|
|
@@ -118,7 +118,8 @@ function makeEnt(obj, game, mass) { |
|
|
|
obj.game = game; |
|
|
|
obj.shape = new Shape(obj); |
|
|
|
obj.moves = false; |
|
|
|
this.dead = false; |
|
|
|
obj.dead = false; |
|
|
|
obj.inputListener = false; |
|
|
|
|
|
|
|
obj.mass = mass || 0; |
|
|
|
obj.forceScalar = 1 / obj.mass; |
|
|
@@ -138,9 +139,9 @@ function Game(canvas) { |
|
|
|
this.worldgen = null; |
|
|
|
|
|
|
|
this.entities = []; |
|
|
|
this.inputListeners = []; |
|
|
|
|
|
|
|
this.keys = {}; |
|
|
|
this.presses = {}; |
|
|
|
this.onkey = function onkey(evt) { |
|
|
|
var down = (evt.type === "keydown" || evt.type === "touchstart"); |
|
|
|
var code = evt.keyCode || "touch"; |
|
|
@@ -148,8 +149,18 @@ function Game(canvas) { |
|
|
|
var name = keymap[code]; |
|
|
|
if (name) { |
|
|
|
this.keys[name] = down; |
|
|
|
if (down) |
|
|
|
this.presses[name] = true; |
|
|
|
|
|
|
|
for (var i = 0; i < this.inputListeners.length; ++i) { |
|
|
|
var ent = this.inputListeners[i]; |
|
|
|
if (ent === null) { |
|
|
|
continue; |
|
|
|
} else if (ent.dead) { |
|
|
|
delete this.inputListeners[i]; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
this.inputListeners[i].onInput(name, down); |
|
|
|
} |
|
|
|
} |
|
|
|
}.bind(this); |
|
|
|
} |
|
|
@@ -165,6 +176,11 @@ Game.prototype.start = function(worldgen) { |
|
|
|
|
|
|
|
this.update(); |
|
|
|
} |
|
|
|
Game.prototype.spawn = function(ent) { |
|
|
|
this.entities.push(ent); |
|
|
|
if (ent.inputListener) |
|
|
|
this.inputListeners.push(ent); |
|
|
|
} |
|
|
|
Game.prototype.update = function() { |
|
|
|
var time = new Date().getTime(); |
|
|
|
var dt = time - this.prevTime; |