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:
@@ -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,
|
||||
|
||||
@@ -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
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user