/****
* Classes
****/
// Laser class for the boss
var Laser = Container.expand(function () {
var self = Container.call(this);
var laserGraphics = self.attachAsset('enemy', {
width: 20,
height: 2732,
color: 0xff0000,
shape: 'box',
anchorX: 0.5,
anchorY: 0
});
self.overheated = false;
self.update = function () {
if (!self.overheated && LK.ticks % 300 == 0) {
self.shootLaser();
LK.setTimeout(function () {
self.overheated = true;
}, 5000);
}
if (self.overheated) {
LK.setTimeout(function () {
self.overheated = false;
}, 10000);
}
};
self.shootLaser = function () {
self.overheated = true;
LK.setTimeout(function () {
self.overheated = false;
}, 5000);
};
});
// Turret class for the boss
var Turret = Container.expand(function () {
var self = Container.call(this);
self.hitCount = 0;
var turretGraphics = self.attachAsset('enemyBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.shoot = function () {
if (self.hitCount < 3 && LK.ticks % 120 == 0) {
var bullet = new EnemyBullet();
bullet.x = self.x;
bullet.y = self.y;
enemyBullets.push(bullet);
game.addChild(bullet);
}
};
self.update = function () {
self.shoot();
};
self.registerHit = function () {
self.hitCount++;
if (self.hitCount >= 3) {
self.destroy();
}
};
});
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
this.enableAllySupport = function () {
var ally = new Ally();
ally.x = this.x;
ally.y = this.y - 100;
game.addChild(ally);
LK.setTimeout(function () {
ally.destroy();
}, 5000);
};
this.enableDoubleShot = function () {
this.doubleShotEnabled = true;
LK.setTimeout(function () {
this.doubleShotEnabled = false;
}, 10000);
};
this.enablePiercingShot = function () {
this.piercingShotEnabled = true;
LK.setTimeout(function () {
this.piercingShotEnabled = false;
}, 5000);
};
this.increaseBulletSpeed = function () {
LK.setTimeout(function () {
HeroBullet.prototype.speed = -10;
}, 0);
LK.setTimeout(function () {
HeroBullet.prototype.speed = -5;
}, 10000);
};
};
self.shoot = function () {
if (this.doubleShotEnabled) {
var bulletLeft = new HeroBullet();
bulletLeft.x = this.x - 20;
bulletLeft.y = this.y;
heroBullets.push(bulletLeft);
game.addChild(bulletLeft);
var bulletRight = new HeroBullet();
bulletRight.x = this.x + 20;
bulletRight.y = this.y;
heroBullets.push(bulletRight);
game.addChild(bulletRight);
} else {
var bullet = new HeroBullet();
bullet.x = this.x;
bullet.y = this.y;
heroBullets.push(bullet);
game.addChild(bullet);
}
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Updated logic for enemies to move towards the player's hero
self.y += 3 + Math.floor(LK.getScore() / 10); // Enemies speed up as the score increases
};
self.shoot = function () {
// Removed shooting logic so enemies will ram the player
};
});
// Bullet class for hero
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('heroBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.move = function () {
self.move = function () {
self.y += self.speed;
if (this.piercingShotEnabled) {
for (var i = enemies.length - 1; i >= 0; i--) {
if (this.intersects(enemies[i])) {
enemies[i].destroy();
enemies.splice(i, 1);
LK.setScore(LK.getScore() + 1);
scoreText.setText(LK.getScore().toString());
}
}
}
};
self.enablePiercingShot = function () {
this.piercingShotEnabled = true;
};
};
});
// Bullet class for enemies
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('enemyBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.move = function () {
self.y += self.speed;
};
});
var Ally = Container.expand(function () {
var self = Container.call(this);
var allyGraphics = self.attachAsset('hero', {
// Reuse hero asset for ally
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
if (LK.ticks % 60 == 0) {
var bullet = new HeroBullet();
bullet.x = this.x;
bullet.y = this.y;
bullet.enablePiercingShot();
heroBullets.push(bullet);
game.addChild(bullet);
}
};
});
// Boss class with turrets and a central laser
var Boss = Container.expand(function () {
var self = Container.call(this);
self.health = 10;
self.laserHeat = 0;
self.turrets = [];
self.laser = null;
// Initialize turrets and laser
self.initComponents = function () {
// Create turrets
for (var i = 0; i < 2; i++) {
var turret = new Turret();
turret.x = i === 0 ? self.x - 50 : self.x + 50;
turret.y = self.y + 25;
self.turrets.push(turret);
game.addChild(turret);
}
// Create central laser
self.laser = new Laser();
self.laser.x = self.x;
self.laser.y = self.y + 50;
game.addChild(self.laser);
};
self.update = function () {
self.y += 2;
// Update turrets
self.turrets.forEach(function (turret) {
turret.update();
});
// Update laser
self.laser.update();
};
self.initComponents();
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Define assets for the hero, enemies, and bullets
// Initialize hero
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 150;
// Initialize score display
var scoreText = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Initialize enemies and bullets arrays
var enemies = [];
var heroBullets = [];
var enemyBullets = [];
// Game tick event
LK.on('tick', function () {
// Update hero
hero.update();
// Update all enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
// End game when hero collides with an enemy
if (enemies[i].intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
// Check for enemy off-screen
if (enemies[i].y > 2732) {
enemies[i].destroy();
enemies.splice(i, 1);
}
}
// Update all hero bullets
for (var j = heroBullets.length - 1; j >= 0; j--) {
heroBullets[j].move();
// Check for bullet off-screen or collision with enemies
for (var i = enemies.length - 1; i >= 0; i--) {
if (heroBullets[j].intersects(enemies[i])) {
enemies[i].destroy();
enemies.splice(i, 1);
// Increment score and update display
LK.setScore(LK.getScore() + 1);
if (LK.getScore() % 5 === 0) {
var powerUpFunctions = [hero.enableDoubleShot.bind(hero), hero.enablePiercingShot.bind(hero), hero.enableAllySupport.bind(hero), hero.increaseBulletSpeed.bind(hero)];
var randomIndex = Math.floor(Math.random() * powerUpFunctions.length);
powerUpFunctions[randomIndex].call(hero);
}
scoreText.setText(LK.getScore().toString());
heroBullets[j].destroy();
heroBullets.splice(j, 1);
break; // Exit the loop after destroying the bullet to avoid errors
}
}
if (heroBullets[j] && heroBullets[j].y < 0) {
heroBullets[j].destroy();
heroBullets.splice(j, 1);
}
}
// Update all enemy bullets
for (var k = enemyBullets.length - 1; k >= 0; k--) {
enemyBullets[k].move();
// Check for bullet off-screen or collision with hero
if (enemyBullets[k].y > 2732) {
enemyBullets[k].destroy();
enemyBullets.splice(k, 1);
}
if (enemyBullets[k] && enemyBullets[k].intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
// Hero shooting logic
if (LK.ticks % 60 == 0) {
var bullet = new HeroBullet();
bullet.x = hero.x;
bullet.y = hero.y;
heroBullets.push(bullet);
game.addChild(bullet);
}
// Enemy spawning logic with doubling the number after every 10 kills
var enemySpawnMultiplier = Math.pow(2, Math.floor(LK.getScore() / 10));
var enemySpawnRate = 240 - Math.floor(LK.getScore() / 20) * 30;
enemySpawnRate = Math.max(enemySpawnRate, 60); // Ensure there's a minimum spawn rate
if (LK.ticks % enemySpawnRate == 0) {
for (var spawnIndex = 0; spawnIndex < enemySpawnMultiplier; spawnIndex++) {
var enemy = new Enemy();
enemy.x = Math.random() * (2048 - enemy.width) + enemy.width / 2;
enemy.y = -enemy.height;
enemies.push(enemy);
game.addChild(enemy);
}
}
// Enemy shooting logic
});
// Touch event handling for hero movement
game.on('down', function (obj) {
var touchPos = obj.event.getLocalPosition(game);
hero.x = touchPos.x;
hero.y = touchPos.y;
});
game.on('move', function (obj) {
if (obj.event.target === hero) {
var touchPos = obj.event.getLocalPosition(game);
hero.x = touchPos.x;
hero.y = touchPos.y;
}
});
game.on('up', function (obj) {
// Stop moving the hero when touch ends
});
Космолет с оружием и видом с верху. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Космический булыжниклетящий и круживщейся вокруг своей оси С видом с верха. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Космический патрон смотрящий прямо. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.