aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--index.html1
-rw-r--r--src/engine.js11
-rw-r--r--src/objecttypes.js3
3 files changed, 9 insertions, 6 deletions
diff --git a/index.html b/index.html
index c72896f..26142ee 100644
--- a/index.html
+++ b/index.html
@@ -28,6 +28,5 @@
<body>
<script type="text/javascript" src="src/platformer.js"></script>
- <center>Huom! 16.11. asianomistajan pyynnöstä grafiikkaa parannettu.<center>
</body>
</html>
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;