Skip to content

Commit

Permalink
Bat
Browse files Browse the repository at this point in the history
  • Loading branch information
kdrzazga committed Dec 19, 2024
1 parent 0bea5a4 commit c6766c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Binary file added other/electrician/files/bat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 22 additions & 2 deletions other/electrician/files/classdef.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,26 @@ class Enemy {
}
}

class Rat extends Enemy{
class Bat extends Enemy{
constructor(id){
super(id);
}

init(physics, y){
this.sprite = physics.add.sprite(180 + (this.id + 1)*44, y, 'bat');
this.sprite.velocity = { y: this.speed };
}

move(){
this.sprite.y += this.sprite.velocity.y;
if (this.sprite.y >= this.maxX || this.sprite.y <= this.minX){
this.sprite.velocity.y *= -1;
}
}
}

class Rat extends Enemy{

init(physics, y){
this.sprite = physics.add.sprite(180 + (this.id + 1)*44, y, 'rat' + this.id);
this.sprite.velocity = { x: this.speed };
Expand Down Expand Up @@ -313,7 +328,12 @@ class Creator {

const rats = ratsData.map(createRat);

building.enemies.push(...rats); // Spread operator to add the array of rats
const bat = new Bat(0);
bat.init(physics, 555);
bat.sprite.x = Constants.SCREEN_WIDTH - 50;

building.enemies.push(...rats);
building.enemies.push(bat);

return building;
}
Expand Down
1 change: 1 addition & 0 deletions other/electrician/files/electrician.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class MainScene extends Phaser.Scene {
for (let i = 1; i <= 8; i++) {
this.load.image(`rat${i}`, 'files/rat.png');
}
this.load.image('bat', 'files/bat.png');

this.load.image('ladder', 'files/ladder.png');

Expand Down

0 comments on commit c6766c2

Please sign in to comment.