diff --git a/lib/game/entities/finalboss.js b/lib/game/entities/finalboss.js new file mode 100644 index 0000000..9d5a5e6 --- /dev/null +++ b/lib/game/entities/finalboss.js @@ -0,0 +1,86 @@ +ig.module( + 'game.entities.finalboss' +) +.requires( + 'impact.entity', + 'game.entities.kuroneko', +) +.defines(function() { + EntityFinalboss = ig.Entity.extend({ + collides: ig.Entity.COLLIDES.PASSIVE, + + size: {x: 78, y: 27}, + gravityFactor: 4, + speed: 400, + health: 10, + maxVel: {x: 300, y: 100}, + flip: false, + player: null, + is_dead: false, + + animSheet: new ig.AnimationSheet('media/finalboss.png', 78, 27), + + init: function(x, y, settings) { + this.parent(x, y, settings); + + this.addAnim('normal', 1, [0]); + this.addAnim('dead', 1, [1]); + }, + + update: function() { + this.parent(); + + if (!this.is_dead) { + this.currentAnim = this.anims.normal; + } else { + this.currentAnim = this.anims.dead; + this.currentAnim.flip.y = true; + } + + this.currentAnim.flip.x = this.flip; + this.vel.x = this.speed * this.turnAround(); + }, + + handleMovementTrace: function(res) { + this.parent(res); + + if (res.collision.x) { + this.flip = !this.flip; + } + }, + + collideWith: function(other, axis) { + this.player = ig.game.getEntitiesByType(EntityKuroneko)[0]; + if (other instanceof EntityKuroneko) { + if (axis === 'y') { + this.receiveDamage(1, this.player); + this.player.vel.y = -400; + } else if (axis === 'x') { + this.player.receiveDamage(2, this); + if (this.player.pos.x < this.pos.x) { + this.player.vel.x = -500; + } else { + this.player.vel.x = 500; + } + } + } + }, + + turnAround: function() { + var x = this.pos.x + (this.flip ? + 5 : this.size.x - 5); + var y = this.pos.y + this.size.y + 5; + if(!ig.game.collisionMap.getTile(x, y)){ + this.flip = !this.flip; + } + return this.flip ? -1 : 1; + }, + + kill: function() { + this.is_dead = true; + this.speed = 0; + ig.game.score += 1000; + this.collides = ig.Entity.COLLIDES.NEVER; + setTimeout(function(){ig.game.removeEntity(this);}.bind(this), 500); + } + }) +}) \ No newline at end of file diff --git a/lib/game/entities/mouse.js b/lib/game/entities/mouse.js index 86a82bb..878495a 100644 --- a/lib/game/entities/mouse.js +++ b/lib/game/entities/mouse.js @@ -11,7 +11,7 @@ ig.module( collides: ig.Entity.COLLIDES.PASSIVE, size: {x: 26, y: 9}, - gravityFactor: 4, + gravityFactor: 10, speed: 100, maxVel: {x: 300, y: 100}, flip: true, @@ -36,10 +36,9 @@ ig.module( this.currentAnim = this.anims.dead; this.currentAnim.flip.y = true; } - this.currentAnim.flip.x = this.flip; - var xdir = this.flip ? -1:1; - this.vel.x = this.speed * this.turnAround();; + this.currentAnim.flip.x = this.flip; + this.vel.x = this.speed * this.turnAround(); }, handleMovementTrace: function(res) { @@ -53,10 +52,12 @@ ig.module( collideWith: function(other, axis) { this.player = ig.game.getEntitiesByType(EntityKuroneko)[0]; if (other instanceof EntityKuroneko) { - if (axis === 'y') { + if (axis === 'y' && this.player.pos.y < this.pos.y) { this.kill(); - this.player.vel.y = -200; + this.player.vel.y = -300; ig.game.score += 100; + } else if (axis === 'y' && this.player.pos.y > this.pos.y) { + this.player.receiveDamage(1, this); } else if (axis === 'x') { this.player.receiveDamage(1, this); if (this.player.pos.x < this.pos.x) { @@ -75,7 +76,7 @@ ig.module( if(!ig.game.collisionMap.getTile(x, y)){ this.flip = !this.flip; } - return this.flip ? -1 : 1; + return this.flip ? -1 : 1; }, kill: function() { diff --git a/lib/game/levels/level2.js b/lib/game/levels/level2.js index e265d99..7ac1fe5 100644 --- a/lib/game/levels/level2.js +++ b/lib/game/levels/level2.js @@ -1,17 +1,17 @@ ig.module( 'game.levels.level2' ) -.requires( 'impact.image','game.entities.mouse','game.entities.cheese','game.entities.endgame','game.entities.kuroneko' ) +.requires( 'impact.image','game.entities.mouse','game.entities.cheese','game.entities.endgame','game.entities.kuroneko','game.entities.finalboss' ) .defines(function(){ LevelLevel2=/*JSON[*/{ "entities": [ { "type": "EntityMouse", - "x": 1188, - "y": 484 + "x": 2700, + "y": 300 }, { "type": "EntityMouse", - "x": 1248, - "y": 484 + "x": 2328, + "y": 300 }, { "type": "EntityCheese", @@ -28,11 +28,71 @@ LevelLevel2=/*JSON[*/{ "x": 2540, "y": 396 }, + { + "type": "EntityMouse", + "x": 2812, + "y": 460 + }, + { + "type": "EntityCheese", + "x": 3480, + "y": 588 + }, + { + "type": "EntityMouse", + "x": 2352, + "y": 468 + }, + { + "type": "EntityCheese", + "x": 3536, + "y": 588 + }, + { + "type": "EntityCheese", + "x": 4352, + "y": 428 + }, + { + "type": "EntityMouse", + "x": 1680, + "y": 488 + }, + { + "type": "EntityMouse", + "x": 544, + "y": 440 + }, + { + "type": "EntityCheese", + "x": 1404, + "y": 492 + }, + { + "type": "EntityMouse", + "x": 3480, + "y": 404 + }, + { + "type": "EntityMouse", + "x": 1248, + "y": 484 + }, + { + "type": "EntityMouse", + "x": 1880, + "y": 488 + }, { "type": "EntityMouse", "x": 2420, "y": 588 }, + { + "type": "EntityMouse", + "x": 1188, + "y": 484 + }, { "type": "EntityCheese", "x": 2532, @@ -48,71 +108,11 @@ LevelLevel2=/*JSON[*/{ "x": 2160, "y": 592 }, - { - "type": "EntityMouse", - "x": 2700, - "y": 300 - }, - { - "type": "EntityMouse", - "x": 2328, - "y": 300 - }, - { - "type": "EntityMouse", - "x": 2812, - "y": 460 - }, { "type": "EntityMouse", "x": 2044, "y": 588 }, - { - "type": "EntityCheese", - "x": 3480, - "y": 588 - }, - { - "type": "EntityMouse", - "x": 2352, - "y": 468 - }, - { - "type": "EntityMouse", - "x": 544, - "y": 440 - }, - { - "type": "EntityCheese", - "x": 3536, - "y": 588 - }, - { - "type": "EntityMouse", - "x": 3480, - "y": 404 - }, - { - "type": "EntityMouse", - "x": 1680, - "y": 488 - }, - { - "type": "EntityMouse", - "x": 1880, - "y": 488 - }, - { - "type": "EntityCheese", - "x": 1404, - "y": 492 - }, - { - "type": "EntityCheese", - "x": 4352, - "y": 428 - }, { "type": "EntityCheese", "x": 4384, @@ -200,8 +200,13 @@ LevelLevel2=/*JSON[*/{ }, { "type": "EntityKuroneko", - "x": 132, + "x": 152, "y": 580 + }, + { + "type": "EntityFinalboss", + "x": 5388, + "y": 552 } ], "layer": [ diff --git a/lib/game/main.js b/lib/game/main.js index 524957d..948d35d 100644 --- a/lib/game/main.js +++ b/lib/game/main.js @@ -27,6 +27,7 @@ MyGame = ig.Game.extend({ gravity: 200, player: null, + boss: null, score: 0, checkpoint: null, @@ -38,6 +39,9 @@ MyGame = ig.Game.extend({ ig.input.bind(ig.KEY.LEFT_ARROW, 'left'); ig.input.bind(ig.KEY.UP_ARROW, 'up'); ig.input.bind(ig.KEY.SPACE, 'space'); + + this.timer = new ig.Timer(5); + this.cheesetimer = new ig.Timer(15); }, @@ -46,10 +50,10 @@ MyGame = ig.Game.extend({ this.parent(); this.player = this.getEntitiesByType(EntityKuroneko)[0]; + this.boss = this.getEntitiesByType(EntityFinalboss)[0]; if (this.player) { this.scrollScreen(); - } - + } if (this.currentLevel == LevelTitle) { //play title music @@ -81,6 +85,19 @@ MyGame = ig.Game.extend({ this.loadLevel( LevelTitle ); } } + + var randomX = Math.floor(Math.random() * (5824 - 5184 + 1) ) + 5184; + + if (this.timer.delta() > 5 && this.boss && this.player.pos.x > 5056) { + this.spawnEntity(EntityMouse, randomX, 448); + this.timer.reset(); + } + + if (this.cheesetimer.delta() > 15 && this.boss && this.player.pos.x > 5056) { + this.spawnEntity(EntityCheese, randomX, 586); + console.log(this.cheesetimer.delta()); + this.cheesetimer.reset(); + } }, loadLevel: function(data) { @@ -123,6 +140,7 @@ MyGame = ig.Game.extend({ this.parent(); this.player = this.getEntitiesByType(EntityKuroneko)[0]; + this.boss = this.getEntitiesByType(EntityFinalboss)[0]; var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); @@ -177,6 +195,106 @@ MyGame = ig.Game.extend({ ctx.stroke(); ctx.fillStyle = '#ac3232'; ctx.fillRect(63, 33, 0, 10); + + if (this.player.pos.x > 5056 && this.boss) { + if (this.boss.health == 10) { + ctx.beginPath(); + ctx.lineWidth = '10'; + ctx.strokeStyle = '#808080'; + ctx.rect(230, 100, 500, 30); + ctx.stroke(); + ctx.fillStyle = "#3c813f"; + ctx.fillRect(235, 105, 490, 20); + } + if (this.boss.health == 9) { + ctx.beginPath(); + ctx.lineWidth = '10'; + ctx.strokeStyle = '#808080'; + ctx.rect(230, 100, 500, 30); + ctx.stroke(); + ctx.fillStyle = "#3c813f"; + ctx.fillRect(235, 105, 441, 20); + } + if (this.boss.health == 8) { + ctx.beginPath(); + ctx.lineWidth = '10'; + ctx.strokeStyle = '#808080'; + ctx.rect(230, 100, 500, 30); + ctx.stroke(); + ctx.fillStyle = "#3c813f"; + ctx.fillRect(235, 105, 392, 20); + } + if (this.boss.health == 7) { + ctx.beginPath(); + ctx.lineWidth = '10'; + ctx.strokeStyle = '#808080'; + ctx.rect(230, 100, 500, 30); + ctx.stroke(); + ctx.fillStyle = "#3c813f"; + ctx.fillRect(235, 105, 343, 20); + } + if (this.boss.health == 6) { + ctx.beginPath(); + ctx.lineWidth = '10'; + ctx.strokeStyle = '#808080'; + ctx.rect(230, 100, 500, 30); + ctx.stroke(); + ctx.fillStyle = "#3c813f"; + ctx.fillRect(235, 105, 294, 20); + } + if (this.boss.health == 5) { + ctx.beginPath(); + ctx.lineWidth = '10'; + ctx.strokeStyle = '#808080'; + ctx.rect(230, 100, 500, 30); + ctx.stroke(); + ctx.fillStyle = "#3c813f"; + ctx.fillRect(235, 105, 245, 20); + } + if (this.boss.health == 4) { + ctx.beginPath(); + ctx.lineWidth = '10'; + ctx.strokeStyle = '#808080'; + ctx.rect(230, 100, 500, 30); + ctx.stroke(); + ctx.fillStyle = "#3c813f"; + ctx.fillRect(235, 105, 196, 20); + } + if (this.boss.health == 3) { + ctx.beginPath(); + ctx.lineWidth = '10'; + ctx.strokeStyle = '#808080'; + ctx.rect(230, 100, 500, 30); + ctx.stroke(); + ctx.fillStyle = "#3c813f"; + ctx.fillRect(235, 105, 147, 20); + } + if (this.boss.health == 2) { + ctx.beginPath(); + ctx.lineWidth = '10'; + ctx.strokeStyle = '#808080'; + ctx.rect(230, 100, 500, 30); + ctx.stroke(); + ctx.fillStyle = "#3c813f"; + ctx.fillRect(235, 105, 98, 20); + } + if (this.boss.health == 1) { + ctx.beginPath(); + ctx.lineWidth = '10'; + ctx.strokeStyle = '#808080'; + ctx.rect(230, 100, 500, 30); + ctx.stroke(); + ctx.fillStyle = "#3c813f"; + ctx.fillRect(235, 105, 49, 20); + } + if (this.boss.health == 0) { + ctx.beginPath(); + ctx.lineWidth = '10'; + ctx.strokeStyle = '#808080'; + ctx.rect(230, 100, 500, 30); + ctx.stroke(); + } + } } } }); diff --git a/media/finalboss.png b/media/finalboss.png new file mode 100644 index 0000000..5992863 Binary files /dev/null and b/media/finalboss.png differ