Skip to content

Commit

Permalink
dust off the bitrot
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpvar committed Mar 5, 2016
1 parent 6dfb97f commit 2a37393
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 30 deletions.
12 changes: 6 additions & 6 deletions client/js/index.js
Expand Up @@ -2,7 +2,7 @@
/*
Bootstrap the browser
*/

valid_keys = {
32 : true,
37 : true,
Expand All @@ -20,8 +20,8 @@
scene.addPlanet(new Planet());
scene.update(gameState);

if (scene.hasPlayer(socket.socket.sessionid)) {
var ship = window.ship = scene.getPlayer(socket.socket.sessionid);
if (scene.hasPlayer(socket.id)) {
var ship = window.ship = scene.getPlayer(socket.id);

/*
Keybinds
Expand All @@ -45,8 +45,8 @@
setInterval(function() {
socket.emit('keys', ship.heldKeys);
}, 33);


socket.on('tick', function(gameState) {
scale = ship.planet_distance();
$("#vel").html(scale)
Expand Down Expand Up @@ -86,4 +86,4 @@
}, fps);
});
};
})(window);
})(window);
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -10,8 +10,8 @@
"node": "*"
},
"dependencies": {
"socket.io" : "0.7.0",
"connect" : "*"
"connect": "1.0.x",
"socket.io": "^1.4.5"
},
"devDependencies": {}
}
4 changes: 2 additions & 2 deletions server/run.js
Expand Up @@ -21,7 +21,7 @@ io.sockets.on('connection', function (socket) {
var ship = new Ship({
x: Math.random()*100,
y: Math.random()*100,
id : socket.id
id : socket.id.split('#').pop()
});

scene.addPlayer(ship);
Expand All @@ -45,4 +45,4 @@ setInterval(function() {
} catch (e) {
process.exit();
}
}, 33)
}, 33)
11 changes: 6 additions & 5 deletions shared/scene.js
Expand Up @@ -52,7 +52,7 @@

tick : function() {
var that = this;
Object.keys(this.players).forEach(function(player_key) {
Object.keys(this.players).forEach(function(player_key) {
var player = that.players[player_key];
player.tick(that);
});
Expand All @@ -65,14 +65,15 @@
this.planets[planet].render(context, timeDiff);
};


var keys = Object.keys(this.players);
var player = keys.length;
var player = keys.length;

while(player--) {
this.players[keys[player]].render(context, timeDiff, window.ship._.id === this.players[keys[player]]._.id);
var currentPlayer = window.ship && window.ship._ && window.ship._.id === this.players[keys[player]]._.id;
this.players[keys[player]].render(context, timeDiff, currentPlayer);
};

}
};
})(typeof window === 'undefined' ? exports : window);
})(typeof window === 'undefined' ? exports : window);
30 changes: 15 additions & 15 deletions shared/ship.js
Expand Up @@ -36,7 +36,7 @@
landing: 0,
crashing: []
}

this._.animation = {
crashing: []
}
Expand Down Expand Up @@ -101,7 +101,7 @@
if (imageIndex < 5) {
imageIndex = 4 - imageIndex;
if (imageIndex > 4) imageIndex = 4;
ctx.drawImage(imageCache.ship.default.landing[imageIndex], this._.x, this._.y)
ctx.drawImage(imageCache.ship.default.landing[imageIndex], this._.x, this._.y)
} else {
ctx.drawImage(this.image, this._.x, this._.y)
}
Expand All @@ -115,7 +115,7 @@
ctx.translate(this._.x + 22, this._.y + 50);
var imageIndex = (this.animation.trails.big % 50) % 4;
if (this.trails.large[imageIndex]) {
ctx.scale(2.0);
ctx.scale(2.0, 2.0);
ctx.drawImage(this.trails.large[imageIndex], -7, 2);
}
ctx.restore();
Expand All @@ -129,7 +129,7 @@
ctx.translate(this._.x + 34, this._.y + 35);
var imageIndex = (this.animation.trails.big % 50) % 4;
if (this.trails.small[imageIndex]) {
ctx.scale(2.0);
ctx.scale(2.0, 2.0);
ctx.drawImage(this.trails.small[imageIndex], -6, 2);
}
ctx.restore();
Expand All @@ -141,7 +141,7 @@
ctx.translate(this._.x + 10, this._.y + 35);
var imageIndex = (this.animation.trails.big % 50) % 4;
if (this.trails.small[imageIndex]) {
ctx.scale(2.0);
ctx.scale(2.0, 2.0);
ctx.drawImage(this.trails.small[imageIndex], -5, 2);
}
ctx.restore();
Expand All @@ -150,7 +150,7 @@
if (this.heldKeys['40']) {
this.animation.trails.big += timeDiff;
ctx.save();

var imageIndex = (this.animation.trails.big % 50) % 4;
if (this.trails.small[imageIndex]) {
ctx.translate(this._.x + 33, this._.y-0.5);
Expand All @@ -164,11 +164,11 @@
}

ctx.restore();

this.projectiles.forEach(function(projectile) {
projectile.render(ctx, timeDiff);
});

};
}

Expand Down Expand Up @@ -205,11 +205,11 @@
y += Math.sin(planet_angle) * ((CONST.GRAVITY / Math.pow(planet_distance, 2)));

// update the ship position due to speed

if (planet_distance < 100) { // contact planet
planet_angle = (planet_angle - Math.PI) % (Math.PI * 2)
var rotation = this._.rotation % (Math.PI * 2)

if (this._.velocity <= 2 && (rotation > planet_angle - 0.4) && (rotation < planet_angle + 0.4)) { // land
this._.landed = true;
this._.rotation = planet_angle;
Expand All @@ -232,17 +232,17 @@
}

} else { // flying

this._.landed = false;

this._.rotation += this._.rotation_delta;
this._.velocity = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));

if (this._.velocity > CONST.MAX_SPEED) this._.velocity = CONST.MAX_SPEED;
if (this._.velocity < 0) this._.velocity = 0;

this._.velocity_angle = calc_angle(x, y)

this._.x += x;
this._.y += y;

Expand Down Expand Up @@ -292,11 +292,11 @@
// Forward
if (heldKeys['38']) {
if (this._.landed) {

this._.landed = false;
this.addVelocity(CONST.THRUST*40);
}

// Thrust forward!
this.addVelocity(CONST.THRUST);
}
Expand Down

0 comments on commit 2a37393

Please sign in to comment.