diff --git a/Cat.js b/Cat.js index 87e44e9..3a34f51 100644 --- a/Cat.js +++ b/Cat.js @@ -112,8 +112,7 @@ export class ChefCat extends Cat { } action() { - // Produces 50 cheese every 10 seconds, cheese.png pop in front of the chefCat - // TODO: change it to 25 secs + // Produces 25 cheese every 10 seconds, cheese.png pop in front of the chefCat if (millis() - this.lastProduced > 10000) { console.log(`produces Cheese!`) const cheese = createSprite(this.x + this.width / 5, this.y + this.width / 5); @@ -143,7 +142,11 @@ export class SingleYarnCat extends Cat { yarn.scale = gameFrame.tileWidth / 1024; yarn.vel.x = 1; yarn.life = 600; - movingObjects.push(yarn); + const newMovingObject = { + sprite: yarn, + point: 15 + } + movingObjects.push(newMovingObject); this.lastShot = millis(); } } @@ -168,7 +171,11 @@ export class DoubleYarnCat extends Cat { yarn.scale = gameFrame.tileWidth / 1024; yarn.vel.x = 1; yarn.life = 600; - movingObjects.push(yarn); + const newMovingObject = { + sprite: yarn, + point: 15 + } + movingObjects.push(newMovingObject); } this.lastShot = millis(); } @@ -199,17 +206,6 @@ export class SleepyCat extends Cat { if (millis() - this.wakeStart > 1480) this.remove(); } } - - // action(mouse) { - // if (this.awake) { - // this.changeAni('action'); - // this.wakeStart = millis(); - // } - // if (this.wakeStart && millis() - this.wakeStart > 1000) { - // this.remove(); - // // Still needs to remove it from the activeCats or grid[row][col] - // } - // } } export class IceCat extends Cat { @@ -230,7 +226,11 @@ export class IceCat extends Cat { snowball.scale = gameFrame.tileWidth / 1024; snowball.vel.x = 1; snowball.life = 600; - movingObjects.push(snowball); + const newMovingObject = { + sprite: snowball, + point: 20 + } + movingObjects.push(newMovingObject); this.lastShot = millis(); } } diff --git a/GameScene.js b/GameScene.js index 03d7345..626e939 100644 --- a/GameScene.js +++ b/GameScene.js @@ -3,6 +3,7 @@ import { imageAssets, catImages, catAnimation, selectedCatType, resetCatType } f import { Cat, ChefCat, SingleYarnCat, DoubleYarnCat, SleepyCat, IceCat } from './Cat.js'; import { Mice, BasicMouse, HelmetMouse } from './Mouse.js'; import { level1Mice } from './level/level1.js'; +import { RobotVacuum } from './RobotVacuum.js'; const gameParent = document.getElementById('gameFrame'); const upperContainer = document.getElementById('upperContainer'); @@ -83,10 +84,7 @@ export function GameScene() { let x = gameFrame.paddingRobot + gameFrame.robotSize / 2; let y = gameFrame.padding_up + row * gameFrame.tileHeight + gameFrame.tileHeight / 2; - let vacuum = createSprite(x, y, gameFrame.robotSize, gameFrame.robotSize); - vacuum.image = imageAssets.robotVacuum; - vacuum.image.scale = gameFrame.tileWidth / 1000; - // vacuum.vel.x = 1; + let vacuum = new RobotVacuum(x, y, row); gameSprites.push(vacuum); robotVacuums.push(vacuum); @@ -138,6 +136,12 @@ export function GameScene() { activeMice[row].splice(i, 1); } }) + + robotVacuums.forEach((vacuum) => { + if (vacuum.sprite.overlaps(currMouse.sprite)) { + vacuum.action(); + } + }) } } } diff --git a/Mouse.js b/Mouse.js index b638d78..9bb95df 100644 --- a/Mouse.js +++ b/Mouse.js @@ -5,7 +5,7 @@ export class Mice { constructor(x, y, speed, HP, AP, img, width) { this.sprite = createSprite(x, y, width, width); this.sprite.image = img; - this.sprite.layer = 2; + this.sprite.layer = 3; this.sprite.velocity.x = speed; this.HP = HP; this.AP = AP; diff --git a/RobotVacuum.js b/RobotVacuum.js new file mode 100644 index 0000000..0adc310 --- /dev/null +++ b/RobotVacuum.js @@ -0,0 +1,30 @@ +import { gameFrame } from './prototype.js'; +import { imageAssets } from './sketch.js'; +import { activeMice } from './GameScene.js'; + +export class RobotVacuum { + constructor(x, y, row) { + this.sprite = createSprite(x, y, gameFrame.robotSize, gameFrame.robotSize) + this.sprite.image = imageAssets.robotVacuum; + this.sprite.scale = gameFrame.tileWidth / 1000; + this.sprite.layer = 2; + this.activated = false; + this.row = row; + } + + action() { + if (!this.activated) { + this.activated = true; + this.sprite.vel.x = 1; + } + + for (let i = 0; i < activeMice[this.row].length; i++) { + let currMouse = activeMice[this.row][i]; + if (this.sprite.overlaps(currMouse.sprite)) { + activeMice[this.row].splice(i, 1); + currMouse.remove(); + } + } + } + +} \ No newline at end of file diff --git a/level/Level1.js b/level/Level1.js index bdd42b7..ca947d6 100644 --- a/level/Level1.js +++ b/level/Level1.js @@ -5,4 +5,6 @@ export const level1Mice = [ { time: 23, type: 'basicMouse', row: 0 }, { time: 30, type: 'basicMouse', row: 4 }, { time: 36, type: 'helmetMouse', row: 1 }, + { time: 45, type: 'basicMouse', row: 0}, + { time: 55, type: 'basicMouse', row: 0} ] \ No newline at end of file