Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bricks.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Brick { // type 0 = invis, 1 = brick, 2 = question, 3 = block
this.bounce = false;
this.velocity = - 80;

this.killEnemiesAbove();

switch (this.prize) {
case 'Coins':
if (this.startTime === 0) this.startTime = Date.now();
Expand Down Expand Up @@ -107,6 +109,20 @@ class Brick { // type 0 = invis, 1 = brick, 2 = question, 3 = block

};

killEnemiesAbove() {
const that = this;
this.game.entities.forEach(entity => {
if (entity.BB && entity.BB.bottom <= this.BB.top && entity.BB.right > this.BB.left && entity.BB.left < this.BB.right) {
// Check if the entity is an enemy and kill it
if (entity instanceof Goomba || entity instanceof Koopa || entity instanceof PirahnaPlant || entity instanceof KoopaParatroopaGreen || entity instanceof KoopaParatroopaRed) {
entity.dead = true;
that.game.addEntity(new Score(that.game, entity.x, entity.y, 100));
ASSET_MANAGER.playAsset("./audio/stomp.mp3");
}
}
});
}

drawMinimap(ctx, mmX, mmY) {
ctx.fillStyle = this.type === 2 ? "Gold" : "Brown";
if (this.type) ctx.fillRect(mmX + this.x / PARAMS.BITWIDTH, mmY + this.y / PARAMS.BITWIDTH, PARAMS.SCALE, PARAMS.SCALE);
Expand Down
7 changes: 6 additions & 1 deletion items.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ class Mushroom {
that.y = entity.BB.top - PARAMS.BLOCKWIDTH;
that.velocity.y = 0;
that.updateBB();
} else if (entity !== that && !(entity instanceof Flower)) {
} else if (entity !== that && !(entity instanceof Flower || entity instanceof Goomba
|| entity instanceof KoopaParatroopaRed || entity instanceof KoopaParatroopaGreen
|| entity instanceof Koopa || entity instanceof KoopaShell
|| entity instanceof PirahnaPlant || entity instanceof HammerBro
|| entity instanceof Hammer || entity instanceof FireBar
|| entity instanceof FireBar_Fire)) {
that.velocity.x = -that.velocity.x;
}
};
Expand Down
15 changes: 11 additions & 4 deletions mario.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Mario {
else {
if (this.game.down) // big mario is crouching
this.BB = new BoundingBox(this.x, this.y + PARAMS.BLOCKWIDTH, PARAMS.BLOCKWIDTH, PARAMS.BLOCKWIDTH);
else
else
this.BB = new BoundingBox(this.x, this.y, PARAMS.BLOCKWIDTH, PARAMS.BLOCKWIDTH * 2);
}
};
Expand Down Expand Up @@ -324,11 +324,11 @@ class Mario {

if (this.game.A) { // jump
if (Math.abs(this.velocity.x) < 16) {
this.velocity.y = -240;
this.velocity.y = -280;
this.fallAcc = STOP_FALL;
}
else if (Math.abs(this.velocity.x) < 40) {
this.velocity.y = -240;
this.velocity.y = -280;
this.fallAcc = WALK_FALL;
}
else {
Expand Down Expand Up @@ -424,6 +424,13 @@ class Mario {
// update position
this.x += this.velocity.x * TICK * PARAMS.SCALE;
this.y += this.velocity.y * TICK * PARAMS.SCALE;

// Apply left boundary constraint
if (this.x < this.game.camera.x) {
this.x = this.game.camera.x;
this.velocity.x = Math.max(0, this.velocity.x);
}

this.updateLastBB();
this.updateBB();

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