From ed2ca44bd951df39dc3be16822764601f10c69e1 Mon Sep 17 00:00:00 2001 From: neingeist Date: Mon, 25 Nov 2013 12:51:20 +0100 Subject: [PATCH] don't copy code for enemies --- platformer.js | 51 ++++++++++++--------------------------------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/platformer.js b/platformer.js index f965b3f..ed129f8 100644 --- a/platformer.js +++ b/platformer.js @@ -46,9 +46,9 @@ Q.Sprite.extend("Rocket", { } }); -Q.Sprite.extend("Neingeist",{ - init: function(p) { - this._super(p, { sheet: 'neingeist', vx: 100 }); +Q.Sprite.extend("Enemy", { + init: function(p, q) { + this._super(p, q); this.add('2d, aiBounce'); this.on("bump.left,bump.right,bump.bottom",function(collision) { @@ -67,48 +67,21 @@ Q.Sprite.extend("Neingeist",{ } }); -// FIXME do not copy -Q.Sprite.extend("Starbug",{ +Q.Enemy.extend("Neingeist",{ init: function(p) { - this._super(p, { sheet: 'starbug', vx: 100 }); - this.add('2d, aiBounce'); - - this.on("bump.left,bump.right,bump.bottom",function(collision) { - if(collision.obj.isA("Player")) { - Q.stageScene("endGame", 1); - collision.obj.destroy(); - } - }); - - this.on("bump.top",function(collision) { - if(collision.obj.isA("Player")) { - this.destroy(); - collision.obj.p.vy = -300; - } - }); + this._super(p, { sheet: 'neingeist', vx: 100 }); } }); -// FIXME do not copy -Q.Sprite.extend("Martin",{ +Q.Enemy.extend("Starbug",{ init: function(p) { - this._super(p, { sheet: 'martin', vx: 100 }); - - this.add('2d, aiBounce'); - - this.on("bump.left,bump.right,bump.bottom",function(collision) { - if(collision.obj.isA("Player")) { - Q.stageScene("endGame", 1); - collision.obj.destroy(); - } - }); + this._super(p, { sheet: 'starbug', vx: 90 }); + } +}); - this.on("bump.top",function(collision) { - if(collision.obj.isA("Player")) { - this.destroy(); - collision.obj.p.vy = -300; - } - }); +Q.Enemy.extend("Martin",{ + init: function(p) { + this._super(p, { sheet: 'martin', vx: 80 }); } });