Added laser beams for entity

This commit is contained in:
Jeremiah Billmann
2013-08-02 23:45:26 -04:00
parent 7d9cd2f0ac
commit 3b66c2e960
4 changed files with 10 additions and 10 deletions
+1 -3
View File
@@ -7,14 +7,12 @@ function Game (sockets) {
this.physicsInterval = 15;
this.physicsDelta = this.physicsInterval / 1000;
this.physicsIntervalId = 0;
this.worldState = { playerSize: 40, entitySize: 15 };
this.server = garageServer.createGarageServer(sockets,
{
logging: true,
interpolation: true,
clientSidePrediction: true,
worldState: this.worldState,
smoothingFactor: 0.2
});
}
@@ -39,7 +37,7 @@ Game.prototype.update = function () {
var entity = entities[i],
newState = gamePhysics.getNewEntityState(entity.state, self.physicsDelta);
if (newState.x < 0 - self.worldState.playerSize || newState.y < 0 - self.worldState.playerSize || newState.x > self.worldState.width || newState.y > self.worldState.height) {
if (newState.x < -200 || newState.y < -200 || newState.x > 2000 || newState.y > 2000) {
self.server.removeEntity(entity.id);
} else {
self.server.updateEntityState(entity.id, newState);
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

+5 -4
View File
@@ -2,7 +2,8 @@ $(function () {
"use strict";
var canvas = document.getElementById('gameCanvas'), ctxCanvas = canvas.getContext('2d'), keyboard = new THREEx.KeyboardState(), ships = preloadShips();
var canvas = document.getElementById('gameCanvas'), ctxCanvas = canvas.getContext('2d'), keyboard = new THREEx.KeyboardState(), ships = preloadShips(), entityImage = new Image();
entityImage.src = '../images/entity.png';
window.addEventListener('resize', resizeCanvas, false);
@@ -30,12 +31,12 @@ $(function () {
ctxCanvas.fillStyle = 'white';
var playerStates = GarageServerIO.getPlayerStates(),
entityStates = GarageServerIO.getEntityStates();
entityStates.forEach(function (entity) {
drawRotatedImage(entity.state.ang, entity.state.x, entity.state.y, entityImage);
});
playerStates.forEach(function (player) {
drawRotatedImage(player.state.ang, player.state.x, player.state.y, ships[player.state.ship]);
});
entityStates.forEach(function (entity) {
ctxCanvas.fillRect(entity.state.x, entity.state.y, 5, 5);
});
},
//Update Loop
function () {
+4 -3
View File
@@ -1,13 +1,14 @@
(function(exports){
exports.getNewPlayerState = function (state, inputs, deltaTime, garageServer) {
var i = 0, distance = 0, notLaunched = false;
var i = 0, distance = 0;
if (!state.ang && state.ang !== 0) {
state.ang = 0;
state.x = 0;
state.y = 0;
state.ship = Math.floor(Math.random() * 9) + 1;
state.lastFire = new Date().getTime();
}
for (i = 0; i < inputs.length; i ++) {
@@ -18,11 +19,11 @@
} else if (inputs[i].input === 'up') {
distance += (125 * deltaTime);
} else if (inputs[i].input === 'space') {
if (garageServer && !notLaunched) {
if (garageServer && (new Date().getTime() - state.lastFire) > 1000) {
var newId = guid();
garageServer.addEntity(newId);
garageServer.updateEntityState(newId, { x: state.x, y: state.y, ang: state.ang } );
notLaunched = true;
state.lastFire = new Date().getTime();
}
}
}