diff --git a/bricks.js b/bricks.js index aa039cf..8f17390 100644 --- a/bricks.js +++ b/bricks.js @@ -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(); @@ -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); diff --git a/items.js b/items.js index 391f486..71ba5da 100644 --- a/items.js +++ b/items.js @@ -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; } }; diff --git a/mario.js b/mario.js index dce0efb..4693ce2 100644 --- a/mario.js +++ b/mario.js @@ -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); } }; @@ -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 { @@ -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(); @@ -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;