zombies drop money now

master
Jordan Orelli 5 years ago
parent 832601e406
commit 42165639f2

@ -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) {

@ -16,6 +16,7 @@
<script src="lib/p5.multiplayer.js"></script>
<!-- p5 sketch -->
<script src="util.js"></script>
<script src="money.js"></script>
<script src="images.js"></script>
<script src="burger.js"></script>
<script src="player.js"></script>

@ -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;
Loading…
Cancel
Save