diff --git a/public/game.js b/public/game.js index 5b4dfce..28cc445 100644 --- a/public/game.js +++ b/public/game.js @@ -1,21 +1,22 @@ class Game { constructor (w, h) { - this.w = w; - this.h = h; - this.players = {}; + this.w = w; + this.h = h; + this.players = {}; this.numPlayers = 0; - this.id = 0; - this.spawner = new ZombieSpawner({ + this.id = 0; + this.spawner = new ZombieSpawner({ game: this, minX: 0, maxX: w, minY: 0, maxY: 0, }); - this.zombies = []; + this.zombies = []; this.burgers = []; - this.store = new Store(); - this.bank = new Bank(); + this.moneys = []; + this.store = new Store(); + this.bank = new Bank(); } add (id, x, y, w, h) { @@ -45,6 +46,9 @@ class Game { for (let zombie of this.zombies) { if (burger.overlaps(zombie)) { burger.kill(); + let money = new Money(zombie.position.x, zombie.position.y); + this.moneys.push(money); + console.log(["adding money", money]); zombie.kill(); break; } @@ -65,6 +69,7 @@ class Game { } this.zombies.forEach(z => z.draw()); this.burgers.forEach(b => b.draw()); + this.moneys.forEach(m => m.draw()); } remove (id) { diff --git a/public/host.html b/public/host.html index d3ff533..8445f13 100644 --- a/public/host.html +++ b/public/host.html @@ -16,6 +16,7 @@ + diff --git a/public/money.js b/public/money.js new file mode 100644 index 0000000..cf36cd4 --- /dev/null +++ b/public/money.js @@ -0,0 +1,32 @@ +class Money { + constructor(x, y) { + this.image = Images.cash; + this.position = {x: x, y: y}; + this.velocity = {x: 0, y: 0}; + this.width = 32; + this.height = 32; + this.alive = true; + } + + draw() { + let half = { + height: this.height * 0.5, + width: this.width * 0.5, + }; + tint(Colors.DarkGreen); + image(this.image, this.position.x - half.width, this.position.y - half.height, this.width, this.height); + + if (debug) { + strokeWeight(4); + stroke('#FF0000'); + point(this.position.x, this.position.y); + strokeWeight(1); + noFill(); + rect(this.position.x - half.width, this.position.y - half.height, this.width, this.height); + } + } +} + +Money.prototype.bounds = bounds; +Money.prototype.outOfBounds = outOfBounds; +Money.prototype.overlaps = overlaps;