From c73fb1e27492f9d4784b057a677ef59b2a5d1be2 Mon Sep 17 00:00:00 2001 From: IllusionMan1212 Date: Sun, 30 Sep 2018 16:39:00 +0200 Subject: [PATCH] Final touches before music and sound effects --- lib/game/entities/finalboss.js | 86 +++++++++++++++++++++ lib/game/entities/mouse.js | 15 ++-- lib/game/levels/level2.js | 137 +++++++++++++++++---------------- lib/game/main.js | 122 ++++++++++++++++++++++++++++- media/finalboss.png | Bin 0 -> 3069 bytes 5 files changed, 285 insertions(+), 75 deletions(-) create mode 100644 lib/game/entities/finalboss.js create mode 100644 media/finalboss.png 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 0000000000000000000000000000000000000000..5992863dfbc105711a266ea887b2d092cdec3a8c GIT binary patch literal 3069 zcmVKLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3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