RobotVacuum working

This commit is contained in:
adeliptr 2025-05-06 22:06:59 +09:00
parent ea6e321c2f
commit 1569132f8d
5 changed files with 57 additions and 21 deletions

32
Cat.js
View File

@ -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();
}
}

View File

@ -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();
}
})
}
}
}

View File

@ -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;

30
RobotVacuum.js Normal file
View File

@ -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();
}
}
}
}

View File

@ -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}
]