From 91da305524f7b0e6b3a4fbb731c653d0b96b1000 Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Sun, 14 Jul 2013 15:13:59 -0400 Subject: [PATCH] Progress #3 --- example/game.js | 4 ++-- example/public/javascripts/game.js | 9 ++++++--- example/shared/core.js | 8 ++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/example/game.js b/example/game.js index d137be3..9688451 100644 --- a/example/game.js +++ b/example/game.js @@ -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 { diff --git a/example/public/javascripts/game.js b/example/public/javascripts/game.js index 8f0d5c4..d133780 100644 --- a/example/public/javascripts/game.js +++ b/example/public/javascripts/game.js @@ -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); }); }); }, diff --git a/example/shared/core.js b/example/shared/core.js index 05129b0..4cf8a39 100644 --- a/example/shared/core.js +++ b/example/shared/core.js @@ -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;