Skip to content

Commit bee5d87

Browse files
Merge pull request #1 from NinjaPanda351/faustjoe/minor-bug-fixes
Faustjoe/minor bug fixes
2 parents e43de00 + b106b6d commit bee5d87

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
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);

items.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ class Mushroom {
122122
that.y = entity.BB.top - PARAMS.BLOCKWIDTH;
123123
that.velocity.y = 0;
124124
that.updateBB();
125-
} else if (entity !== that && !(entity instanceof Flower)) {
125+
} else if (entity !== that && !(entity instanceof Flower || entity instanceof Goomba
126+
|| entity instanceof KoopaParatroopaRed || entity instanceof KoopaParatroopaGreen
127+
|| entity instanceof Koopa || entity instanceof KoopaShell
128+
|| entity instanceof PirahnaPlant || entity instanceof HammerBro
129+
|| entity instanceof Hammer || entity instanceof FireBar
130+
|| entity instanceof FireBar_Fire)) {
126131
that.velocity.x = -that.velocity.x;
127132
}
128133
};

mario.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class Mario {
127127
else {
128128
if (this.game.down) // big mario is crouching
129129
this.BB = new BoundingBox(this.x, this.y + PARAMS.BLOCKWIDTH, PARAMS.BLOCKWIDTH, PARAMS.BLOCKWIDTH);
130-
else
130+
else
131131
this.BB = new BoundingBox(this.x, this.y, PARAMS.BLOCKWIDTH, PARAMS.BLOCKWIDTH * 2);
132132
}
133133
};
@@ -324,11 +324,11 @@ class Mario {
324324

325325
if (this.game.A) { // jump
326326
if (Math.abs(this.velocity.x) < 16) {
327-
this.velocity.y = -240;
327+
this.velocity.y = -280;
328328
this.fallAcc = STOP_FALL;
329329
}
330330
else if (Math.abs(this.velocity.x) < 40) {
331-
this.velocity.y = -240;
331+
this.velocity.y = -280;
332332
this.fallAcc = WALK_FALL;
333333
}
334334
else {
@@ -424,6 +424,13 @@ class Mario {
424424
// update position
425425
this.x += this.velocity.x * TICK * PARAMS.SCALE;
426426
this.y += this.velocity.y * TICK * PARAMS.SCALE;
427+
428+
// Apply left boundary constraint
429+
if (this.x < this.game.camera.x) {
430+
this.x = this.game.camera.x;
431+
this.velocity.x = Math.max(0, this.velocity.x);
432+
}
433+
427434
this.updateLastBB();
428435
this.updateBB();
429436

@@ -519,7 +526,7 @@ class Mario {
519526
that.x = entity.BB.left - PARAMS.BLOCKWIDTH;
520527
if (that.velocity.x > 0) that.velocity.x = 0;
521528
if (entity instanceof SideTube && that.game.right) {
522-
that.game.camera.loadLevel(levelOne, 162.5 * PARAMS.BLOCKWIDTH, 11 * PARAMS.BLOCKWIDTH)
529+
that.game.camera.loadLevel(levelOne, 162.5 * PARAMS.BLOCKWIDTH, 11 * PARAMS.BLOCKWIDTH)
523530
}
524531
} else if (that.lastBB.left >= entity.BB.right) { // Collided with the right
525532
that.x = entity.BB.right;

0 commit comments

Comments
 (0)