|
|
@ -11,7 +11,7 @@ class Game {
|
|
|
|
minX: 0,
|
|
|
|
minX: 0,
|
|
|
|
maxX: w,
|
|
|
|
maxX: w,
|
|
|
|
minY: 0,
|
|
|
|
minY: 0,
|
|
|
|
maxY: 100,
|
|
|
|
maxY: 0,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.zombies = [];
|
|
|
|
this.zombies = [];
|
|
|
|
this.store = new Store();
|
|
|
|
this.store = new Store();
|
|
|
@ -19,22 +19,27 @@ class Game {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
add (id, x, y, w, h) {
|
|
|
|
add (id, x, y, w, h) {
|
|
|
|
this.players[id] = createSprite(x, y, w, h);
|
|
|
|
let player = new Player({
|
|
|
|
this.players[id].id = "p"+this.id;
|
|
|
|
id: id,
|
|
|
|
this.players[id].setCollider("rectangle", 0, 0, w, h);
|
|
|
|
x: x,
|
|
|
|
this.players[id].color = color(255, 255, 255);
|
|
|
|
y: y,
|
|
|
|
this.players[id].shapeColor = color(255, 255, 255);
|
|
|
|
width: w,
|
|
|
|
this.players[id].scale = 1;
|
|
|
|
height: h,
|
|
|
|
this.players[id].mass = 1;
|
|
|
|
})
|
|
|
|
this.colliders.add(this.players[id]);
|
|
|
|
this.players[id] = player;
|
|
|
|
print(this.players[id].id + " added.");
|
|
|
|
// this.colliders.add(player.sprite);
|
|
|
|
|
|
|
|
print(player.id + " added.");
|
|
|
|
this.id++;
|
|
|
|
this.id++;
|
|
|
|
this.numPlayers++;
|
|
|
|
this.numPlayers++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
update() {
|
|
|
|
update() {
|
|
|
|
this.checkBounds();
|
|
|
|
// this.checkBounds();
|
|
|
|
this.zombies.forEach(z => z.update());
|
|
|
|
this.zombies.forEach(z => z.update());
|
|
|
|
|
|
|
|
for (let id in this.players) {
|
|
|
|
|
|
|
|
let player = this.players[id];
|
|
|
|
|
|
|
|
player.update();
|
|
|
|
|
|
|
|
}
|
|
|
|
this.zombies = this.zombies.filter(z => !z.isDead());
|
|
|
|
this.zombies = this.zombies.filter(z => !z.isDead());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -42,20 +47,24 @@ class Game {
|
|
|
|
this.update();
|
|
|
|
this.update();
|
|
|
|
this.bank.draw(width*0.25 - 64, height - 128 - 32, 128, 128);
|
|
|
|
this.bank.draw(width*0.25 - 64, height - 128 - 32, 128, 128);
|
|
|
|
this.store.draw(width*0.75 - 64, height - 128 - 32, 128, 128);
|
|
|
|
this.store.draw(width*0.75 - 64, height - 128 - 32, 128, 128);
|
|
|
|
|
|
|
|
for (let id in this.players) {
|
|
|
|
|
|
|
|
let player = this.players[id];
|
|
|
|
|
|
|
|
player.draw();
|
|
|
|
|
|
|
|
}
|
|
|
|
this.zombies.forEach(z => z.draw());
|
|
|
|
this.zombies.forEach(z => z.draw());
|
|
|
|
drawSprites();
|
|
|
|
// drawSprites();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setColor (id, r, g, b) {
|
|
|
|
setColor (id, r, g, b) {
|
|
|
|
this.players[id].color = color(r, g, b);
|
|
|
|
// this.players[id].sprite.color = color(r, g, b);
|
|
|
|
this.players[id].shapeColor = color(r, g, b);
|
|
|
|
// this.players[id].sprite.shapeColor = color(r, g, b);
|
|
|
|
|
|
|
|
|
|
|
|
print(this.players[id].id + " color added.");
|
|
|
|
print(this.players[id].id + " color added.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
remove (id) {
|
|
|
|
remove (id) {
|
|
|
|
this.colliders.remove(this.players[id]);
|
|
|
|
// this.colliders.remove(this.players[id].sprite);
|
|
|
|
this.players[id].remove();
|
|
|
|
// this.players[id].sprite.remove();
|
|
|
|
delete this.players[id];
|
|
|
|
delete this.players[id];
|
|
|
|
this.numPlayers--;
|
|
|
|
this.numPlayers--;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -67,43 +76,45 @@ class Game {
|
|
|
|
|
|
|
|
|
|
|
|
printPlayerIds (x, y) {
|
|
|
|
printPlayerIds (x, y) {
|
|
|
|
push();
|
|
|
|
push();
|
|
|
|
noStroke();
|
|
|
|
noStroke();
|
|
|
|
fill(Colors.Eggplant);
|
|
|
|
fill(Colors.Eggplant);
|
|
|
|
textSize(16);
|
|
|
|
textSize(16);
|
|
|
|
text("# players: " + this.numPlayers, x, y);
|
|
|
|
text("# players: " + this.numPlayers, x, y);
|
|
|
|
|
|
|
|
|
|
|
|
y = y + 16;
|
|
|
|
y = y + 16;
|
|
|
|
fill(Colors.Eggplant);
|
|
|
|
fill(Colors.Eggplant);
|
|
|
|
for (let id in this.players) {
|
|
|
|
for (let id in this.players) {
|
|
|
|
text(this.players[id].id, x, y);
|
|
|
|
text(this.players[id].id, x, y);
|
|
|
|
y += 16;
|
|
|
|
y += 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pop();
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setVelocity(id, velx, vely) {
|
|
|
|
joystickInput(id, x, y) {
|
|
|
|
this.players[id].velocity.x = velx;
|
|
|
|
let player = this.players[id];
|
|
|
|
this.players[id].velocity.y = vely;
|
|
|
|
if (player) {
|
|
|
|
|
|
|
|
player.joystickInput(x, y);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checkBounds() {
|
|
|
|
checkBounds() {
|
|
|
|
for (let id in this.players) {
|
|
|
|
for (let id in this.players) {
|
|
|
|
|
|
|
|
|
|
|
|
if (this.players[id].position.x < 0) {
|
|
|
|
if (this.players[id].sprite.position.x < 0) {
|
|
|
|
this.players[id].position.x = this.w - 1;
|
|
|
|
this.players[id].sprite.position.x = this.w - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (this.players[id].position.x > this.w) {
|
|
|
|
if (this.players[id].sprite.position.x > this.w) {
|
|
|
|
this.players[id].position.x = 1;
|
|
|
|
this.players[id].sprite.position.x = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (this.players[id].position.y < 0) {
|
|
|
|
if (this.players[id].sprite.position.y < 0) {
|
|
|
|
this.players[id].position.y = this.h - 1;
|
|
|
|
this.players[id].sprite.position.y = this.h - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (this.players[id].position.y > this.h) {
|
|
|
|
if (this.players[id].sprite.position.y > this.h) {
|
|
|
|
this.players[id].position.y = 1;
|
|
|
|
this.players[id].sprite.position.y = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|