mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-06-27 16:10:34 +08:00
Progress #3
This commit is contained in:
+2
-2
@@ -7,7 +7,7 @@ function Game (sockets) {
|
||||
this.physicsInterval = 15;
|
||||
this.physicsDelta = this.physicsInterval / 1000;
|
||||
this.physicsIntervalId = 0;
|
||||
this.worldState = { height: 400, width: 800 };
|
||||
this.worldState = { height: 400, width: 800, playerSize: 15, entitySize: 5 };
|
||||
|
||||
this.server = garageServer.createGarageServer(sockets,
|
||||
{
|
||||
@@ -37,7 +37,7 @@ Game.prototype.update = function () {
|
||||
|
||||
entities.forEach(function (entity) {
|
||||
var newState = gamePhysics.getNewEntityState(entity.state, self.physicsDelta);
|
||||
if (newState.x < 0 || newState.y < 0 || newState.x > self.worldState.width || newState.y > self.worldState.height) {
|
||||
if (newState.x < 0 - self.worldState.playerSize || newState.y < 0 - self.worldState.playerSize || newState.x > self.worldState.width || newState.y > self.worldState.height) {
|
||||
self.server.removeEntity(entity.id);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -2,7 +2,8 @@ $(function () {
|
||||
|
||||
"use strict";
|
||||
|
||||
var canvas = document.getElementById('gameCanvas'), ctxCanvas = canvas.getContext('2d'), keyboard = new THREEx.KeyboardState();
|
||||
var canvas = document.getElementById('gameCanvas'), ctxCanvas = canvas.getContext('2d'), keyboard = new THREEx.KeyboardState(),
|
||||
playerSize = 0, entitySize = 0;
|
||||
|
||||
GarageServerIO.initializeGarageServer('http://garageserver_io.jbillmann.c9.io', {
|
||||
logging: true,
|
||||
@@ -11,6 +12,8 @@ $(function () {
|
||||
onWorldState: function (state) {
|
||||
document.getElementById('gameCanvas').style.width = state.width + 'px';
|
||||
document.getElementById('gameCanvas').style.height = state.height + 'px';
|
||||
playerSize = state.playerSize;
|
||||
entitySize = state.entitySize;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -20,11 +23,11 @@ $(function () {
|
||||
ctxCanvas.clearRect(0, 0, canvas.width, canvas.height);
|
||||
GarageServerIO.getStates(function (playerStates, entityStates) {
|
||||
playerStates.forEach(function (player) {
|
||||
ctxCanvas.fillRect(player.state.x, player.state.y, 15, 15);
|
||||
ctxCanvas.fillRect(player.state.x, player.state.y, playerSize, playerSize);
|
||||
});
|
||||
|
||||
entityStates.forEach(function (entity) {
|
||||
ctxCanvas.fillRect(entity.state.x, entity.state.y, 5, 5);
|
||||
ctxCanvas.fillRect(entity.state.x, entity.state.y, entitySize, entitySize);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@@ -34,13 +34,13 @@
|
||||
|
||||
exports.getNewEntityState = function (state, deltaTime) {
|
||||
if (state.direction === 'left') {
|
||||
state.x -= (75 * deltaTime);
|
||||
state.x -= (100 * deltaTime);
|
||||
} else if (state.direction === 'right') {
|
||||
state.x += (75 * deltaTime);
|
||||
state.x += (100 * deltaTime);
|
||||
} else if (state.direction === 'down') {
|
||||
state.y += (75 * deltaTime);
|
||||
state.y += (100 * deltaTime);
|
||||
} else if (state.direction === 'up') {
|
||||
state.y -= (75 * deltaTime);
|
||||
state.y -= (100 * deltaTime);
|
||||
}
|
||||
|
||||
return state;
|
||||
|
||||
Reference in New Issue
Block a user