it's a burger

master
Jordan Orelli 5 years ago
parent ab93bd0fc9
commit bfe683e1ca

@ -0,0 +1,20 @@
class Burger {
constructor(x, y) {
this.sprite = createSprite(x, y, 32, 32);
this.sprite.velocity.y = -5;
this.image = Images.burger;
}
update() {
// this.sprite.velocity.x = this.joyX * 10;
// this.sprite.velocity.y = this.joyY * -10;
}
draw() {
tint(Colors.Purple);
image(this.image, this.sprite.position.x-16, this.sprite.position.y-16, 32, 32);
strokeWeight(4);
stroke('#FF0000');
point(this.sprite.position.x, this.sprite.position.y);
}
}

@ -5,7 +5,6 @@ class Game {
this.players = {}; this.players = {};
this.numPlayers = 0; this.numPlayers = 0;
this.id = 0; this.id = 0;
this.colliders = new Group();
this.spawner = new ZombieSpawner({ this.spawner = new ZombieSpawner({
game: this, game: this,
minX: 0, minX: 0,
@ -14,12 +13,14 @@ class Game {
maxY: 0, maxY: 0,
}); });
this.zombies = []; this.zombies = [];
this.burgers = [];
this.store = new Store(); this.store = new Store();
this.bank = new Bank(); this.bank = new Bank();
} }
add (id, x, y, w, h) { add (id, x, y, w, h) {
let player = new Player({ let player = new Player({
game: this,
id: id, id: id,
x: x, x: x,
y: y, y: y,
@ -27,14 +28,12 @@ class Game {
height: h, height: h,
}) })
this.players[id] = player; this.players[id] = player;
// this.colliders.add(player.sprite);
print(player.id + " added."); print(player.id + " added.");
this.id++; this.id++;
this.numPlayers++; this.numPlayers++;
} }
update() { update() {
// this.checkBounds();
this.zombies.forEach(z => z.update()); this.zombies.forEach(z => z.update());
for (let id in this.players) { for (let id in this.players) {
let player = this.players[id]; let player = this.players[id];
@ -52,19 +51,10 @@ class Game {
player.draw(); player.draw();
} }
this.zombies.forEach(z => z.draw()); this.zombies.forEach(z => z.draw());
// drawSprites(); this.burgers.forEach(b => b.draw());
}
setColor (id, r, g, b) {
// this.players[id].sprite.color = color(r, g, b);
// this.players[id].sprite.shapeColor = color(r, g, b);
print(this.players[id].id + " color added.");
} }
remove (id) { remove (id) {
// this.colliders.remove(this.players[id].sprite);
// this.players[id].sprite.remove();
delete this.players[id]; delete this.players[id];
this.numPlayers--; this.numPlayers--;
} }
@ -91,6 +81,15 @@ class Game {
pop(); pop();
} }
buttonInput(id, val) {
console.log(["game sees button input", [id, val]]);
let player = this.players[id];
if (player) {
console.log(["button input has player", player]);
player.buttonInput(val);
}
}
joystickInput(id, x, y) { joystickInput(id, x, y) {
let player = this.players[id]; let player = this.players[id];
if (player) { if (player) {
@ -120,8 +119,16 @@ class Game {
} }
addZombie(zombie) { addZombie(zombie) {
console.log(["adding zombie", zombie]);
this.zombies.push(zombie); this.zombies.push(zombie);
} }
addBurger(id) {
let player = this.players[id];
if (player) {
let burger = new Burger(player.sprite.position.x, player.sprite.position.y);
console.log(["adding burger", burger]);
this.burgers.push(burger);
}
}
} }

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

@ -93,7 +93,7 @@ function onClientDisconnect (data) {
function onReceiveData (data) { function onReceiveData (data) {
// Input data processing here. ---> // Input data processing here. --->
console.log(data); // console.log(data);
if (data.type === 'joystick') { if (data.type === 'joystick') {
processJoystick(data); processJoystick(data);
@ -102,7 +102,7 @@ function onReceiveData (data) {
processButton(data); processButton(data);
} }
else if (data.type === 'playerColor') { else if (data.type === 'playerColor') {
game.setColor(data.id, data.r*255, data.g*255, data.b*255); // game.setColor(data.id, data.r*255, data.g*255, data.b*255);
} }
// <---- // <----
@ -129,10 +129,6 @@ function processJoystick (data) {
} }
function processButton (data) { function processButton (data) {
game.players[data.id].val = data.button; console.log(data);
game.buttonInput(data.id, data.button);
if (debug) {
console.log(data.id + ': ' +
data.button);
}
} }

@ -1,10 +1,12 @@
class Player { class Player {
constructor(options) { constructor(options) {
options = options || {}; options = options || {};
this.id = "p"+options.id; this.game = options.game;
this.id = options.id;
this.image = random(Images.players); this.image = random(Images.players);
this.width = options.width; this.width = options.width;
this.height = options.height; this.height = options.height;
this.burgers = 5;
let sprite = createSprite(options.x, options.y, options.width, options.height); let sprite = createSprite(options.x, options.y, options.width, options.height);
sprite.addImage(this.image); sprite.addImage(this.image);
@ -24,10 +26,25 @@ class Player {
draw() { draw() {
tint(Colors.Purple); tint(Colors.Purple);
image(this.image, this.sprite.position.x, this.sprite.position.y, 64, 64); image(this.image, this.sprite.position.x, this.sprite.position.y, 64, 64);
strokeWeight(4);
stroke('#FF0000');
point(this.sprite.position.x, this.sprite.position.y);
} }
joystickInput(x, y) { joystickInput(x, y) {
this.joyX = x; this.joyX = x;
this.joyY = y; this.joyY = y;
} }
buttonInput(val) {
console.log(["player sees button input val", val]);
if (val) {
if (this.burgers > 0) {
this.burgers--;
this.game.addBurger(this.id);
} else {
}
}
}
} }

@ -14,6 +14,9 @@ class Zombie {
draw() { draw() {
tint(Colors.DarkGreen); tint(Colors.DarkGreen);
image(this.image, this.x, this.y, 64, 64); image(this.image, this.x, this.y, 64, 64);
strokeWeight(4);
stroke('#FF0000');
point(this.x, this.y);
} }
isDead() { isDead() {
@ -36,7 +39,6 @@ class ZombieSpawner {
planNextSpawn() { planNextSpawn() {
let t = random(this.minT, this.maxT); let t = random(this.minT, this.maxT);
console.log(`will add next zombie in ${t}`);
this.nextSpawn = setTimeout(() => this.spawnZombie(), t); this.nextSpawn = setTimeout(() => this.spawnZombie(), t);
} }

Loading…
Cancel
Save