diff --git a/public/burger.js b/public/burger.js new file mode 100644 index 0000000..4bc05d7 --- /dev/null +++ b/public/burger.js @@ -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); + } +} diff --git a/public/game.js b/public/game.js index 5e1de62..8cf765f 100644 --- a/public/game.js +++ b/public/game.js @@ -5,7 +5,6 @@ class Game { this.players = {}; this.numPlayers = 0; this.id = 0; - this.colliders = new Group(); this.spawner = new ZombieSpawner({ game: this, minX: 0, @@ -14,12 +13,14 @@ class Game { maxY: 0, }); this.zombies = []; + this.burgers = []; this.store = new Store(); this.bank = new Bank(); } add (id, x, y, w, h) { let player = new Player({ + game: this, id: id, x: x, y: y, @@ -27,14 +28,12 @@ class Game { height: h, }) this.players[id] = player; - // this.colliders.add(player.sprite); print(player.id + " added."); this.id++; this.numPlayers++; } update() { - // this.checkBounds(); this.zombies.forEach(z => z.update()); for (let id in this.players) { let player = this.players[id]; @@ -52,19 +51,10 @@ class Game { player.draw(); } this.zombies.forEach(z => z.draw()); - // drawSprites(); - } - - 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."); + this.burgers.forEach(b => b.draw()); } remove (id) { - // this.colliders.remove(this.players[id].sprite); - // this.players[id].sprite.remove(); delete this.players[id]; this.numPlayers--; } @@ -91,6 +81,15 @@ class Game { 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) { let player = this.players[id]; if (player) { @@ -120,8 +119,16 @@ class Game { } addZombie(zombie) { - console.log(["adding zombie", 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); + } + } } diff --git a/public/host.html b/public/host.html index aaba55c..67b9e3e 100644 --- a/public/host.html +++ b/public/host.html @@ -16,6 +16,7 @@ + diff --git a/public/host.js b/public/host.js index ec79964..dfcc113 100644 --- a/public/host.js +++ b/public/host.js @@ -93,7 +93,7 @@ function onClientDisconnect (data) { function onReceiveData (data) { // Input data processing here. ---> - console.log(data); + // console.log(data); if (data.type === 'joystick') { processJoystick(data); @@ -102,7 +102,7 @@ function onReceiveData (data) { processButton(data); } 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) { - game.players[data.id].val = data.button; - - if (debug) { - console.log(data.id + ': ' + - data.button); - } + console.log(data); + game.buttonInput(data.id, data.button); } diff --git a/public/player.js b/public/player.js index 0e0070f..2d829fe 100644 --- a/public/player.js +++ b/public/player.js @@ -1,10 +1,12 @@ class Player { constructor(options) { options = options || {}; - this.id = "p"+options.id; + this.game = options.game; + this.id = options.id; this.image = random(Images.players); this.width = options.width; this.height = options.height; + this.burgers = 5; let sprite = createSprite(options.x, options.y, options.width, options.height); sprite.addImage(this.image); @@ -24,10 +26,25 @@ class Player { draw() { tint(Colors.Purple); 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) { this.joyX = x; 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 { + + } + } + } } diff --git a/public/zombie.js b/public/zombie.js index 3f47c05..3c5e0ce 100644 --- a/public/zombie.js +++ b/public/zombie.js @@ -14,6 +14,9 @@ class Zombie { draw() { tint(Colors.DarkGreen); image(this.image, this.x, this.y, 64, 64); + strokeWeight(4); + stroke('#FF0000'); + point(this.x, this.y); } isDead() { @@ -36,7 +39,6 @@ class ZombieSpawner { planNextSpawn() { let t = random(this.minT, this.maxT); - console.log(`will add next zombie in ${t}`); this.nextSpawn = setTimeout(() => this.spawnZombie(), t); }