This commit is contained in:
Jeremiah Billmann
2013-07-14 15:13:59 -04:00
parent 47d0ec5e7d
commit 91da305524
3 changed files with 12 additions and 9 deletions
+2 -2
View File
@@ -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 {
+6 -3
View File
@@ -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);
});
});
},
+4 -4
View File
@@ -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;