Final touches before music and sound effects

This commit is contained in:
IllusionMan1212
2018-09-30 16:39:00 +02:00
parent 13e35a0a7b
commit c73fb1e274
5 changed files with 285 additions and 75 deletions
+86
View File
@@ -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);
}
})
})
+7 -6
View File
@@ -11,7 +11,7 @@ ig.module(
collides: ig.Entity.COLLIDES.PASSIVE, collides: ig.Entity.COLLIDES.PASSIVE,
size: {x: 26, y: 9}, size: {x: 26, y: 9},
gravityFactor: 4, gravityFactor: 10,
speed: 100, speed: 100,
maxVel: {x: 300, y: 100}, maxVel: {x: 300, y: 100},
flip: true, flip: true,
@@ -36,10 +36,9 @@ ig.module(
this.currentAnim = this.anims.dead; this.currentAnim = this.anims.dead;
this.currentAnim.flip.y = true; this.currentAnim.flip.y = true;
} }
this.currentAnim.flip.x = this.flip;
var xdir = this.flip ? -1:1; this.currentAnim.flip.x = this.flip;
this.vel.x = this.speed * this.turnAround();; this.vel.x = this.speed * this.turnAround();
}, },
handleMovementTrace: function(res) { handleMovementTrace: function(res) {
@@ -53,10 +52,12 @@ ig.module(
collideWith: function(other, axis) { collideWith: function(other, axis) {
this.player = ig.game.getEntitiesByType(EntityKuroneko)[0]; this.player = ig.game.getEntitiesByType(EntityKuroneko)[0];
if (other instanceof EntityKuroneko) { if (other instanceof EntityKuroneko) {
if (axis === 'y') { if (axis === 'y' && this.player.pos.y < this.pos.y) {
this.kill(); this.kill();
this.player.vel.y = -200; this.player.vel.y = -300;
ig.game.score += 100; ig.game.score += 100;
} else if (axis === 'y' && this.player.pos.y > this.pos.y) {
this.player.receiveDamage(1, this);
} else if (axis === 'x') { } else if (axis === 'x') {
this.player.receiveDamage(1, this); this.player.receiveDamage(1, this);
if (this.player.pos.x < this.pos.x) { if (this.player.pos.x < this.pos.x) {
+71 -66
View File
@@ -1,17 +1,17 @@
ig.module( 'game.levels.level2' ) 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(){ .defines(function(){
LevelLevel2=/*JSON[*/{ LevelLevel2=/*JSON[*/{
"entities": [ "entities": [
{ {
"type": "EntityMouse", "type": "EntityMouse",
"x": 1188, "x": 2700,
"y": 484 "y": 300
}, },
{ {
"type": "EntityMouse", "type": "EntityMouse",
"x": 1248, "x": 2328,
"y": 484 "y": 300
}, },
{ {
"type": "EntityCheese", "type": "EntityCheese",
@@ -28,11 +28,71 @@ LevelLevel2=/*JSON[*/{
"x": 2540, "x": 2540,
"y": 396 "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", "type": "EntityMouse",
"x": 2420, "x": 2420,
"y": 588 "y": 588
}, },
{
"type": "EntityMouse",
"x": 1188,
"y": 484
},
{ {
"type": "EntityCheese", "type": "EntityCheese",
"x": 2532, "x": 2532,
@@ -48,71 +108,11 @@ LevelLevel2=/*JSON[*/{
"x": 2160, "x": 2160,
"y": 592 "y": 592
}, },
{
"type": "EntityMouse",
"x": 2700,
"y": 300
},
{
"type": "EntityMouse",
"x": 2328,
"y": 300
},
{
"type": "EntityMouse",
"x": 2812,
"y": 460
},
{ {
"type": "EntityMouse", "type": "EntityMouse",
"x": 2044, "x": 2044,
"y": 588 "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", "type": "EntityCheese",
"x": 4384, "x": 4384,
@@ -200,8 +200,13 @@ LevelLevel2=/*JSON[*/{
}, },
{ {
"type": "EntityKuroneko", "type": "EntityKuroneko",
"x": 132, "x": 152,
"y": 580 "y": 580
},
{
"type": "EntityFinalboss",
"x": 5388,
"y": 552
} }
], ],
"layer": [ "layer": [
+119 -1
View File
@@ -27,6 +27,7 @@ MyGame = ig.Game.extend({
gravity: 200, gravity: 200,
player: null, player: null,
boss: null,
score: 0, score: 0,
checkpoint: null, checkpoint: null,
@@ -39,6 +40,9 @@ MyGame = ig.Game.extend({
ig.input.bind(ig.KEY.UP_ARROW, 'up'); ig.input.bind(ig.KEY.UP_ARROW, 'up');
ig.input.bind(ig.KEY.SPACE, 'space'); ig.input.bind(ig.KEY.SPACE, 'space');
this.timer = new ig.Timer(5);
this.cheesetimer = new ig.Timer(15);
}, },
update: function() { update: function() {
@@ -46,11 +50,11 @@ MyGame = ig.Game.extend({
this.parent(); this.parent();
this.player = this.getEntitiesByType(EntityKuroneko)[0]; this.player = this.getEntitiesByType(EntityKuroneko)[0];
this.boss = this.getEntitiesByType(EntityFinalboss)[0];
if (this.player) { if (this.player) {
this.scrollScreen(); this.scrollScreen();
} }
if (this.currentLevel == LevelTitle) { if (this.currentLevel == LevelTitle) {
//play title music //play title music
if (ig.input.pressed('space')) { if (ig.input.pressed('space')) {
@@ -81,6 +85,19 @@ MyGame = ig.Game.extend({
this.loadLevel( LevelTitle ); 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) { loadLevel: function(data) {
@@ -123,6 +140,7 @@ MyGame = ig.Game.extend({
this.parent(); this.parent();
this.player = this.getEntitiesByType(EntityKuroneko)[0]; this.player = this.getEntitiesByType(EntityKuroneko)[0];
this.boss = this.getEntitiesByType(EntityFinalboss)[0];
var canvas = document.getElementById('canvas'); var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d'); var ctx = canvas.getContext('2d');
@@ -177,6 +195,106 @@ MyGame = ig.Game.extend({
ctx.stroke(); ctx.stroke();
ctx.fillStyle = '#ac3232'; ctx.fillStyle = '#ac3232';
ctx.fillRect(63, 33, 0, 10); 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();
}
}
} }
} }
}); });
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB