Skip to content

Commit

Permalink
spawn points
Browse files Browse the repository at this point in the history
  • Loading branch information
jlongster committed Nov 28, 2012
1 parent 73a1f30 commit 37da697
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
5 changes: 3 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,14 @@ function handlePacket(user, data) {
}

function handleDeath(killerUser, killedUser) {
killedUser.entity.restart();
var spawnPoint = Math.floor(Math.random() * 4);
killedUser.entity.restart(spawnPoint);

var obj = {
type: p.cmdPacket.typeId,
from: 0,
method: 'die',
args: [killerUser.name, killedUser.name]
args: [killerUser.name, killedUser.name, spawnPoint]
};

killedUser.stream.write(p.cmdPacket(obj));
Expand Down
30 changes: 25 additions & 5 deletions static/js/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
var diffRot = vec3.create();
vec3.set(this.rot, diffRot);

this.rotateX(state.mouseY * -.01);
this.rotateY(state.mouseX * -.01);
this.rotateX(state.mouseY * -Math.PI / 6.0 * dt);
this.rotateY(state.mouseX * -Math.PI / 6.0 * dt);

if(state.left) {
if(state.mouseDown) {
Expand Down Expand Up @@ -156,9 +156,29 @@
vec3.set(this.historyRot, this.rot);
},

restart: function() {
this.setPos(0, 0, 0);
this.setRot(0, Math.PI, 0);
restart: function(spawnPoint) {
var sceneX = 256 * 4;
var sceneY = 256 * 4;

switch(spawnPoint) {
case 0:
this.setPos(0, 0, 0);
this.setRot(0, Math.PI, 0);
break;
case 1:
this.setPos(sceneX, 0, 0);
this.setRot(0, Math.PI, 0);
break;
case 2:
this.setPos(0, 0, sceneY);
this.setRot(0, 0, 0);
break;
case 3:
this.setPos(sceneX, 0, sceneY);
this.setRot(0, 0, 0);
break;
}

this.interp = 1.0;
this.packetBuffer = [];
this.startPos = this.targetPos = null;
Expand Down
10 changes: 5 additions & 5 deletions static/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
this.resetState();
var state = this.state;

if(mouse[0] !== 0 && mouse[1] !== 0) {
if(mouse[0] !== 0 || mouse[1] !== 0) {
moved = true;
this.rotateX(mouse[1] * -.01);
this.rotateY(mouse[0] * -.01);
this.rotateX(mouse[1] * -Math.PI / 6.0 * dt);
this.rotateY(mouse[0] * -Math.PI / 6.0 * dt);
}

state.mouseX = mouse[0];
Expand Down Expand Up @@ -138,8 +138,8 @@
}
},

restart: function() {
this.parent();
restart: function(spawnPoint) {
this.parent(spawnPoint);
vec3.set(this.pos, this.goodPos);
vec3.set(this.rot, this.goodRot);
},
Expand Down
2 changes: 1 addition & 1 deletion static/js/server-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}

if(node) {
node.restart();
node.restart(obj.args[2]);
}
}
});
Expand Down

0 comments on commit 37da697

Please sign in to comment.