Skip to content

Commit b106b6d

Browse files
committed
Add enemy kill on block hit
When Mario hits a block from below, it now kills enemies standing on top.
1 parent 6990b6f commit b106b6d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

bricks.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class Brick { // type 0 = invis, 1 = brick, 2 = question, 3 = block
7070
this.bounce = false;
7171
this.velocity = - 80;
7272

73+
this.killEnemiesAbove();
74+
7375
switch (this.prize) {
7476
case 'Coins':
7577
if (this.startTime === 0) this.startTime = Date.now();
@@ -107,6 +109,20 @@ class Brick { // type 0 = invis, 1 = brick, 2 = question, 3 = block
107109

108110
};
109111

112+
killEnemiesAbove() {
113+
const that = this;
114+
this.game.entities.forEach(entity => {
115+
if (entity.BB && entity.BB.bottom <= this.BB.top && entity.BB.right > this.BB.left && entity.BB.left < this.BB.right) {
116+
// Check if the entity is an enemy and kill it
117+
if (entity instanceof Goomba || entity instanceof Koopa || entity instanceof PirahnaPlant || entity instanceof KoopaParatroopaGreen || entity instanceof KoopaParatroopaRed) {
118+
entity.dead = true;
119+
that.game.addEntity(new Score(that.game, entity.x, entity.y, 100));
120+
ASSET_MANAGER.playAsset("./audio/stomp.mp3");
121+
}
122+
}
123+
});
124+
}
125+
110126
drawMinimap(ctx, mmX, mmY) {
111127
ctx.fillStyle = this.type === 2 ? "Gold" : "Brown";
112128
if (this.type) ctx.fillRect(mmX + this.x / PARAMS.BITWIDTH, mmY + this.y / PARAMS.BITWIDTH, PARAMS.SCALE, PARAMS.SCALE);

0 commit comments

Comments
 (0)