/****
* Classes
****/
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -15 - Math.floor(LK.getScore() / 10);
self.update = function () {
self.y += self.speed;
if (self.y < 0) {
self.destroy();
}
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5 + Math.floor(LK.getScore() / 10);
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Hero update logic
};
});
// Character class
var Karakter = Container.expand(function () {
var self = Container.call(this);
var karakterGraphics = self.attachAsset('karakter', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Character update logic
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var karakter = game.addChild(new Karakter());
karakter.x = 2048 / 2;
karakter.y = 2500;
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2500;
var enemies = [];
var bullets = [];
var score = 0;
function spawnEnemy() {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = 0;
enemies.push(enemy);
game.addChild(enemy);
}
function shootBullet() {
var bullet = new Bullet();
bullet.x = hero.x;
bullet.y = hero.y;
bullets.push(bullet);
game.addChild(bullet);
}
game.down = function (x, y, obj) {
hero.x = x;
hero.y = y;
karakter.x = x;
karakter.y = y;
};
game.update = function () {
if (LK.ticks % Math.max(5, 30 - Math.floor(LK.getScore() / 10)) === 0) {
spawnEnemy();
}
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
if (enemies[i].intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
for (var k = enemies.length - 1; k >= 0; k--) {
if (bullets[j].intersects(enemies[k])) {
score += 1;
bullets[j].destroy();
enemies[k].destroy();
bullets.splice(j, 1);
enemies.splice(k, 1);
break;
}
}
}
if (LK.ticks % 30 === 0) {
shootBullet();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -97,9 +97,9 @@
karakter.x = x;
karakter.y = y;
};
game.update = function () {
- if (LK.ticks % Math.max(10, 60 - Math.floor(LK.getScore() / 10)) === 0) {
+ if (LK.ticks % Math.max(5, 30 - Math.floor(LK.getScore() / 10)) === 0) {
spawnEnemy();
}
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();