From 7d9cd2f0acfaca42c3c48d9ebb4b1c31dc552b53 Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Fri, 2 Aug 2013 22:41:18 -0400 Subject: [PATCH] Working on entities... --- example/public/javascripts/game.js | 3 --- example/shared/core.js | 23 +++++++++-------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/example/public/javascripts/game.js b/example/public/javascripts/game.js index 9aa754a..bc37728 100644 --- a/example/public/javascripts/game.js +++ b/example/public/javascripts/game.js @@ -45,9 +45,6 @@ $(function () { if (keyboard.pressed('right')) { GarageServerIO.addInput('right'); } - if (keyboard.pressed('down')) { - GarageServerIO.addInput('down'); - } if (keyboard.pressed('up')) { GarageServerIO.addInput('up'); } diff --git a/example/shared/core.js b/example/shared/core.js index 0196c05..aa4f592 100644 --- a/example/shared/core.js +++ b/example/shared/core.js @@ -1,8 +1,7 @@ (function(exports){ exports.getNewPlayerState = function (state, inputs, deltaTime, garageServer) { - var i = 0, - distance = 0; + var i = 0, distance = 0, notLaunched = false; if (!state.ang && state.ang !== 0) { state.ang = 0; @@ -19,10 +18,11 @@ } else if (inputs[i].input === 'up') { distance += (125 * deltaTime); } else if (inputs[i].input === 'space') { - if (garageServer) { + if (garageServer && !notLaunched) { var newId = guid(); garageServer.addEntity(newId); - garageServer.updateEntityState(newId, { x: state.x + 5, y: state.y + 5, direction: state.direction } ); + garageServer.updateEntityState(newId, { x: state.x, y: state.y, ang: state.ang } ); + notLaunched = true; } } } @@ -32,7 +32,7 @@ return state; }; - + function getPoint(angle, distance, oldX, oldY) { var radians = angle * (Math.PI / 180); return { @@ -42,15 +42,10 @@ } exports.getNewEntityState = function (state, deltaTime) { - if (state.direction === 'left') { - state.x -= (300 * deltaTime); - } else if (state.direction === 'right') { - state.x += (300 * deltaTime); - } else if (state.direction === 'down') { - state.y += (300 * deltaTime); - } else if (state.direction === 'up') { - state.y -= (300 * deltaTime); - } + var distance = 300 * deltaTime; + var newPoint = getPoint(state.ang, distance, state.x, state.y); + state.x = newPoint.x; + state.y = newPoint.y; return state; };