mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-06-27 16:10:34 +08:00
Added laser beams for entity
This commit is contained in:
+1
-3
@@ -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 |
@@ -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 () {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user