This commit is contained in:
Jeremiah Billmann
2013-07-14 14:52:59 -04:00
parent 0883042510
commit 9d364265e9
5 changed files with 37 additions and 15 deletions
+13 -8
View File
@@ -130,15 +130,11 @@ var GarageServerIO = (function (socketio) {
function EntityController() {
this.entities = [];
}
function PlayerController() {
EntityController.call(this);
}
PlayerController.prototype = {
EntityController.prototype = {
add: function (id) {
var player = new Player(id);
this.entities.push(player);
return player;
var entity = new Entity(id);
this.entities.push(entity);
return entity;
},
remove: function (id) {
for (var i = 0; i < this.entities.length; i ++) {
@@ -150,6 +146,15 @@ var GarageServerIO = (function (socketio) {
}
};
function PlayerController() {
EntityController.call(this);
}
PlayerController.prototype.add = function (id) {
var player = new Player(id);
this.entities.push(player);
return player;
};
var _io = socketio,
_socket = null,
_options = null,
+1 -1
View File
@@ -24,7 +24,7 @@ $(function () {
});
entityStates.forEach(function (entity) {
ctxCanvas.fillRect(entity.state.x, entity.state.y, 15, 15);
ctxCanvas.fillRect(entity.state.x, entity.state.y, 5, 5);
});
});
},
+19 -2
View File
@@ -6,19 +6,26 @@
if (!state.x && !state.y) {
state.x = 0;
state.y = 0;
state.direction = 'right';
}
for (i = 0; i < inputs.length; i ++) {
if (inputs[i].input === 'left') {
state.x -= (50 * deltaTime);
state.direction = 'left';
} else if (inputs[i].input === 'right') {
state.x += (50 * deltaTime);
state.direction = 'right';
} else if (inputs[i].input === 'down') {
state.y += (50 * deltaTime);
state.direction = 'down';
} else if (inputs[i].input === 'up') {
state.y -= (50 * deltaTime);
state.direction = 'up';
} else if (inputs[i].input === 'space') {
if (garageServer) {
garageServer.addEntity(new guid(), { x: state.x, y: state.y, direction: '' });
var newId = guid();
garageServer.addEntity(newId);
garageServer.updateEntityState(newId, { x: state.x, y: state.y, direction: state.direction } );
}
}
}
@@ -26,7 +33,17 @@
};
exports.getNewEntityState = function (state, deltaTime) {
if (state.direction === 'left') {
state.x -= (75 * deltaTime);
} else if (state.direction === 'right') {
state.x += (75 * deltaTime);
} else if (state.direction === 'down') {
state.y += (75 * deltaTime);
} else if (state.direction === 'up') {
state.y -= (75 * deltaTime);
}
return state;
};
exports.getInterpolatedState = function (previousState, targetState, amount) {
+2 -2
View File
@@ -117,8 +117,8 @@ GarageServer.prototype.updateEntityState = function (id, state) {
this.game.updateEntityState(id, state);
};
GarageServer.prototype.addEntity = function (id, state) {
this.game.addEntity(id, state);
GarageServer.prototype.addEntity = function (id) {
this.game.addEntity(id);
};
GarageServer.prototype.removeEntity = function (id) {
+2 -2
View File
@@ -90,8 +90,8 @@ GarageServerGame.prototype.removePlayer = function (id) {
this.playerController.remove(id);
};
GarageServerGame.prototype.addEntity = function (id, state) {
this.entityController.add(id, state);
GarageServerGame.prototype.addEntity = function (id) {
this.entityController.add(id);
};
GarageServerGame.prototype.removeEntity = function (id) {