aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2019-01-03 12:07:47 -0500
committerJan Tuomi <jans.tuomi@gmail.com>2019-01-03 12:07:47 -0500
commit014874367d7800aafbcf3ce624380b19a5cfe781 (patch)
tree74be243966f5144ddcedbbd9216fad0dd8519c3b /src
parentdbdfaafc447a4d09377619a7c824b87539453007 (diff)
Commit changes
Diffstat (limited to 'src')
-rw-r--r--src/engine.js11
-rw-r--r--src/objecttypes.js3
2 files changed, 9 insertions, 5 deletions
diff --git a/src/engine.js b/src/engine.js
index b75886a..4ae653a 100644
--- a/src/engine.js
+++ b/src/engine.js
@@ -133,7 +133,7 @@ Engine.prototype.testForGameover = function() {
var xdist = obj.position.x - p.position.x;
- if (xdist > -0.3 * obj.width && xdist < 0.2 * obj.width) {
+ if (xdist > -obj.width * 0.8 && xdist < obj.width * 0.1) {
var ydist = obj.position.y - p.position.y;
if (ydist > -obj.height / 2 && ydist < obj.height / 2) {
@@ -166,16 +166,21 @@ Engine.prototype.update = function() {
if (this.state == GAME || this.state == MENU) {
this.testForGameover();
+ var toBeRemoved = -1;
for (var i = 0; i < this.gameObjectList.length; i++) {
var obj = this.gameObjectList[i];
obj.update();
// check if integral object has left the screen
if (obj.objectType == "integral") {
- if (obj.sprite.x < -obj.sprite.width)
- this.removeIntegral(obj);
+ if (obj.sprite.x < -obj.sprite.width) {
+ toBeRemoved = i;
+ }
}
}
+ if (toBeRemoved != -1) {
+ this.removeIntegral(this.gameObjectList[toBeRemoved]);
+ }
}
if (this.state == GAMEOVER) {
diff --git a/src/objecttypes.js b/src/objecttypes.js
index e9f69f0..4dab85c 100644
--- a/src/objecttypes.js
+++ b/src/objecttypes.js
@@ -6,8 +6,7 @@ function Background(x_offset) {
this.x_speed = 10
this.objectType = "background";
-}
-
+}
Background.prototype = Object.create(GameObject.prototype);
Background.prototype.constructor = Background;