Files

325 lines
7.9 KiB
JavaScript
Raw Permalink Normal View History

2018-09-30 06:17:31 +02:00
ig.module(
'game.main'
)
.requires(
'impact.game',
'impact.font',
'game.entities.kuroneko',
'game.entities.cheese',
'game.entities.mouse',
'game.entities.nextlevel',
'game.entities.endgame',
'game.entities.easteregg',
'game.levels.title',
'game.levels.level1',
'game.levels.level2',
'game.levels.gameover',
'game.levels.goodend',
'game.levels.badend',
'impact.debug.debug',
)
.defines(function(){
MyGame = ig.Game.extend({
gravity: 200,
player: null,
boss: null,
2018-09-30 06:17:31 +02:00
score: 0,
checkpoint: null,
2018-09-30 18:47:05 +02:00
titlemusic: new ig.Sound('media/sounds/titlemusic.ogg'),
gamemusic: new ig.Sound('media/sounds/gamemusic.ogg'),
endmusic: new ig.Sound('media/sounds/gameend.ogg'),
2018-09-30 06:17:31 +02:00
init: function() {
this.loadLevel( LevelTitle );
ig.input.bind(ig.KEY.RIGHT_ARROW, 'right');
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);
2018-09-30 18:47:05 +02:00
if (this.currentLevel == LevelTitle) {
this.titlemusic.play();
}
if (this.currentLevel == LevelLevel1 || this.currentLevel == LevelLevel2) {
this.titlemusic.stop();
this.gamemusic.play();
}
if (this.currentLevel == LevelBadend || this.currentLevel == LevelGoodend) {
this.endmusic.play();
}
2018-09-30 06:17:31 +02:00
},
update: function() {
// Update all entities and backgroundMaps
this.parent();
this.player = this.getEntitiesByType(EntityKuroneko)[0];
this.boss = this.getEntitiesByType(EntityFinalboss)[0];
2018-09-30 06:17:31 +02:00
if (this.player) {
this.scrollScreen();
}
2018-09-30 06:17:31 +02:00
if (this.currentLevel == LevelTitle) {
//play title music
2018-09-30 18:47:05 +02:00
//this.titlemusic.play();
2018-09-30 06:17:31 +02:00
if (ig.input.pressed('space')) {
this.loadLevel( LevelLevel1 );
}
}
if (this.currentLevel == LevelLevel1) {
//play game music
this.checkpoint = LevelLevel1;
}
if (this.currentLevel == LevelLevel2) {
//play game music
this.checkpoint = LevelLevel2;
}
if (this.currentLevel == LevelGameover) {
//play some sad music
if (ig.input.pressed('space')) {
this.loadLevel( this.checkpoint );
}
}
if (this.currentLevel == LevelBadend || this.currentLevel == LevelGoodend) {
//play ending music
if (ig.input.pressed('space')) {
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();
}
2018-09-30 06:17:31 +02:00
},
loadLevel: function(data) {
this.parent(data);
this.currentLevel = data;
},
scrollScreen: function() {
//Camera code
if(this.player.pos.x > (ig.game.collisionMap.width*ig.game.collisionMap.tilesize-ig.system.width/2))
{
this.screen.x = ig.game.collisionMap.width*ig.game.collisionMap.tilesize-ig.system.width;
}
else if (this.player.pos.x < ig.system.width/2)
{
this.screen.x = 0;
}
else
{
this.screen.x = this.player.pos.x - ig.system.width/2;
}
if(this.player.pos.y > (ig.game.collisionMap.height*ig.game.collisionMap.tilesize-ig.system.height/2))
{
this.screen.y = ig.game.collisionMap.height*ig.game.collisionMap.tilesize-ig.system.height;
}
else if (this.player.pos.y < ig.system.height/2)
{
this.screen.y = 0;
}
else
{
this.screen.y = this.player.pos.y - ig.system.height/2;
}
},
draw: function() {
// Draw all entities and backgroundMaps
this.parent();
this.player = this.getEntitiesByType(EntityKuroneko)[0];
this.boss = this.getEntitiesByType(EntityFinalboss)[0];
2018-09-30 06:17:31 +02:00
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.font = '30px Ariel'
if (this.currentLevel == LevelLevel1 || this.currentLevel == LevelLevel2) {
if (this.player) {
if (this.player.health == 4) {
ctx.beginPath();
ctx.lineWidth = "6";
ctx.strokeStyle = "#808080";
ctx.rect(60, 30, 96, 16);
ctx.stroke();
ctx.fillStyle = '#ac3232';
ctx.fillRect(63, 33, 90, 10);
}
else if (this.player.health == 3) {
ctx.beginPath();
ctx.lineWidth = "6";
ctx.strokeStyle = "#808080";
ctx.rect(60, 30, 96, 16);
ctx.stroke();
ctx.fillStyle = '#ac3232';
ctx.fillRect(63, 33, 67.5, 10);
}
else if (this.player.health == 2) {
ctx.beginPath();
ctx.lineWidth = "6";
ctx.strokeStyle = "#808080";
ctx.rect(60, 30, 96, 16);
ctx.stroke();
ctx.fillStyle = '#ac3232';
ctx.fillRect(63, 33, 45, 10);
}
else if (this.player.health == 1) {
ctx.beginPath();
ctx.lineWidth = "6";
ctx.strokeStyle = "#808080";
ctx.rect(60, 30, 96, 16);
ctx.stroke();
ctx.fillStyle = '#ac3232';
ctx.fillRect(63, 33, 22.5, 10);
}
ctx.fillText(`Score: ${this.score}`, 750, 45);
}
ctx.beginPath();
ctx.lineWidth = "6";
ctx.strokeStyle = "#808080";
ctx.rect(60, 30, 96, 16);
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();
}
}
2018-09-30 06:17:31 +02:00
}
}
});
// Start the Game with 60fps, a resolution of 640x480, scaled
// up by a factor of 1.5
ig.main( '#canvas', MyGame, 60, 640, 480, 1.5 );
});