Permalink
Browse files

single player mode working

  • Loading branch information...
1 parent 1d7b070 commit dfb06a0b9845c655af587b4013b9cb1c3ceb8077 @gerad committed Sep 21, 2010
Showing with 24 additions and 28 deletions.
  1. +6 −9 lazeroids.coffee
  2. +15 −17 lazeroids.js
  3. +1 −1 script/server
  4. +2 −1 views/index.jade
View
@@ -21,7 +21,7 @@ class Controller
setupKeys: ->
$(window).keydown (e) =>
- ship: @universe.ship
+ ship = @universe.ship
switch e.which
when 32 # space bar = shoot
ship.shoot()
@@ -199,7 +199,7 @@ class Universe
connect: (ship) ->
return if @ships.find ship
- @status "$ship.name connected"
+ @status "#{ship.name} connected"
@silently =>
@add ship
@send 'connect', ship
@@ -222,7 +222,7 @@ class Universe
@loop()
@injectAsteroids 5
- setInterval __bind(this, @injectAsteroids, 3), 5000
+ setInterval (=> @injectAsteroids 3), 5000
setInterval __bind(@updateLeaderboard, this), 1000
play 'ambient', { loop: true }
@@ -231,7 +231,7 @@ class Universe
@network()
@step 1
@render()
- setTimeout (@loop <- this), 1000/24
+ setTimeout __bind(@loop, this), 1000/24
step: (dt) ->
@tick += dt
@@ -246,8 +246,6 @@ class Universe
@io.flush()
perform: (method, data) ->
- # console.log "Performing #{method} with:"
- # console.dir data
this[method] data
status: (message) ->
@@ -270,8 +268,7 @@ class Universe
injectAsteroids: (howMany) ->
return if @masses.length > 80
-
- for i in [1 .. howMany || 1]
+ for i in [1 .. (howMany || 1)]
b = @bounds
[w, h] = [@bounds.width, @bounds.height]
outside = new Vector w*Math.random()-w/2+b.l, h*Math.random()-h/2+b.t
@@ -582,7 +579,7 @@ class Asteroid extends Mass
@universe.add(new Explosion({ from: this }))
_render: (ctx) ->
- p: @corners
+ p = @corners
ctx.beginPath()
ctx.moveTo p[0].x, p[0].y
ctx.lineTo p[i].x, p[i].y for i in [1 ... p.length]
View
@@ -42,10 +42,8 @@
};
Controller.prototype.setupKeys = function() {
$(window).keydown(__bind(function(e) {
- var _d;
- {
- ship: this.universe.ship
- };
+ var _d, ship;
+ ship = this.universe.ship;
if ((_d = e.which) === 32) {
return ship.shoot();
} else if (_d === 37) {
@@ -290,7 +288,7 @@
if (this.ships.find(ship)) {
return null;
}
- this.status("$ship.name connected");
+ this.status(("" + (ship.name) + " connected"));
this.silently(__bind(function() {
return this.add(ship);
}, this));
@@ -318,7 +316,9 @@
this.requestSync();
this.loop();
this.injectAsteroids(5);
- setInterval(__bind(this, this.injectAsteroids, 3), 5000);
+ setInterval((__bind(function() {
+ return this.injectAsteroids(3);
+ }, this)), 5000);
setInterval(__bind(this.updateLeaderboard, this), 1000);
return play('ambient', {
loop: true
@@ -328,7 +328,7 @@
this.network();
this.step(1);
this.render();
- return setTimeout((this.loop < -this), 1000 / 24);
+ return setTimeout(__bind(this.loop, this), 1000 / 24);
};
Universe.prototype.step = function(dt) {
var _d, _e, id, mass;
@@ -392,17 +392,17 @@
return ctx.restore();
};
Universe.prototype.injectAsteroids = function(howMany) {
- var _d, _e, b, centripetal, h, i, inside, outside, w;
+ var _d, _e, _f, b, centripetal, h, i, inside, outside, w;
if (this.masses.length > 80) {
return null;
}
- _d = [];
- for (i = 1; (1 <= howMany || 1 ? i <= howMany || 1 : i >= howMany || 1); (1 <= howMany || 1 ? i += 1 : i -= 1)) {
+ _d = []; _e = (howMany || 1);
+ for (i = 1; (1 <= _e ? i <= _e : i >= _e); (1 <= _e ? i += 1 : i -= 1)) {
_d.push((function() {
b = this.bounds;
- _e = [this.bounds.width, this.bounds.height];
- w = _e[0];
- h = _e[1];
+ _f = [this.bounds.width, this.bounds.height];
+ w = _f[0];
+ h = _f[1];
outside = new Vector(w * Math.random() - w / 2 + b.l, h * Math.random() - h / 2 + b.t);
if (outside.x > b.l) {
outside.x += w;
@@ -812,10 +812,8 @@
}));
};
Asteroid.prototype._render = function(ctx) {
- var _d, i;
- {
- p: this.corners
- };
+ var _d, i, p;
+ p = this.corners;
ctx.beginPath();
ctx.moveTo(p[0].x, p[0].y);
_d = p.length;
View
@@ -1,2 +1,2 @@
#! /usr/bin/env bash
-restartr node server.js
+restartr node server.js *.js
View
@@ -7,6 +7,7 @@
| \
span.divider |
| \ objects:
+ | \
span.objects
table#score
@@ -64,7 +65,7 @@ canvas
| $('#splash').fadeIn();
| if (localStorage.name)
| $('input[name=name]').val(localStorage.name).select();
- | //c = new Lz.Controller($('canvas').get(0));
+ | c = new Lz.Controller($('canvas').get(0));
| $('form').submit(function() {
| c.setName(localStorage.name = $('input[name=name]', this).val());
| c.setupInput();

0 comments on commit dfb06a0

Please sign in to comment.