User prompt
add boss boss and improve game
User prompt
improve game
User prompt
add
Code edit (1 edits merged)
Please save this source code
User prompt
the enemyies are vibrating some time pls solve
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'for (var i = 0; i < enemyShips.length; i++) {' Line Number: 446 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'if (enemyGraphics.height && self.y > 2732 + enemyGraphics.height / 2) {' Line Number: 157 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'if (self.y > 2732 + enemyGraphics.height / 2) {' Line Number: 157 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'tween(enemyGraphics.scale, {' Line Number: 44 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'if (self.y > 2732 + enemyGraphics.height / 2) {' Line Number: 157
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'for (var i = 0; i < enemyShips.length; i++) {' Line Number: 446
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'for (var i = 0; i < enemyShips.length; i++) {' Line Number: 446
User prompt
Please fix the bug: 'Unable to load plugin: @upit/tween.v1 - Cannot read properties of undefined (reading '@upit/tween.v1')' in or related to this line: 'var tween = LK.import("@upit/tween.v1").tween;' Line Number: 466 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'for (var i = 0; i < enemyShips.length; i++) {' Line Number: 446
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'self.targetY = y;' Line Number: 424
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'self.targetY = y;' Line Number: 424
User prompt
Please fix the bug: 'Uncaught TypeError: flashGraphics.beginFill is not a function' in or related to this line: 'flashGraphics.beginFill(0x00FFFF, 0.8);' Line Number: 320
User prompt
Please fix the bug: 'Uncaught TypeError: Graphics is not a constructor' in or related to this line: 'var flash = new Graphics();' Line Number: 310
User prompt
Please fix the bug: 'tween.to is not a function' in or related to this line: 'tween.to(shipGraphics, {' Line Number: 295 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: easing is not a function' in or related to this line: 'for (var i = 0; i < enemyShips.length; i++) {' Line Number: 441
Code edit (1 edits merged)
Please save this source code
User prompt
remove explosion
User prompt
Please fix the bug: 'Uncaught Error: getChildAt: Supplied index 0 does not exist in the child list, or the supplied DisplayObject must be a child of the caller' in or related to this line: 'var halfWidth = player.getChildAt(0).width / 2;' Line Number: 368
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: LK.restartGame is not a function' in or related to this line: 'LK.restartGame();' Line Number: 916
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Class for enemy bullets
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFF0000,
scaleX: 0.2,
scaleY: 0.2
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
// Destroy if off-screen
if (self.y > SCREEN_HEIGHT + 20) {
self.destroy();
var index = enemyBullets.indexOf(self);
if (index !== -1) {
enemyBullets.splice(index, 1);
}
}
};
return self;
});
// Class for enemy ships with wave-based spawning and better animation
var EnemyShip = Container.expand(function (type) {
var self = Container.call(this);
self.type = type || ENEMY_TYPES.BASIC;
var enemyGraphics = self.attachAsset('enemyShip', {
anchorX: 0.5,
anchorY: 0.5
});
// Set properties based on enemy type
switch (self.type) {
case ENEMY_TYPES.FAST:
enemyGraphics.tint = 0x00FF00;
self.speed = 5 + Math.random() * 2;
self.health = 1;
self.scoreValue = 2;
self.driftAmount = 6;
break;
case ENEMY_TYPES.TANK:
enemyGraphics.tint = 0xFF0000;
self.speed = 2 + Math.random() * 1;
self.health = 3;
self.scoreValue = 3;
self.driftAmount = 2;
break;
case ENEMY_TYPES.BOSS:
enemyGraphics.tint = 0xFF00FF;
enemyGraphics.scale.set(1.5);
self.speed = 1.5;
self.health = 15;
self.scoreValue = 10;
self.driftAmount = 3;
break;
default:
// BASIC
self.speed = 3 + Math.random() * 2;
self.health = 1;
self.scoreValue = 1;
self.driftAmount = 3;
}
// Spawn animation: Fade in & Scale up
enemyGraphics.scale.set(0);
enemyGraphics.alpha = 0;
tween(enemyGraphics.scale, {
x: self.type === ENEMY_TYPES.BOSS ? 1.5 : 1,
y: self.type === ENEMY_TYPES.BOSS ? 1.5 : 1
}, {
duration: 500
});
tween(enemyGraphics, {
alpha: 1
}, {
duration: 500
});
self.driftSpeed = 50 + Math.random() * 20; // Slight variation in drift speed
self.shootCooldown = self.type === ENEMY_TYPES.BOSS ? 1500 : 3000; // Boss shoots more frequently
self.canShoot = true;
self.hit = function () {
self.health -= 1;
if (self.health <= 0) {
self.explode();
return true; // Enemy destroyed
}
// Flash effect when hit but not destroyed
tween(enemyGraphics, {
alpha: 0.2
}, {
duration: 100,
onFinish: function onFinish() {
tween(enemyGraphics, {
alpha: 1
}, {
duration: 100
});
}
});
// Emit particles when hit
particleSystem.emit(self.x, self.y, 5);
return false; // Enemy still alive
};
self.explode = function () {
// Play explosion sound
LK.getSound('explosion').play({
volume: 0.5
});
// Emit particles for explosion
particleSystem.emit(self.x, self.y, 20);
// Chance to drop powerup (higher chance for bosses)
var dropChance = self.type === ENEMY_TYPES.BOSS ? 0.8 : 0.1;
if (Math.random() < dropChance) {
spawnPowerup(self.x, self.y);
}
tween(enemyGraphics, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
enemyShips.splice(enemyShips.indexOf(self), 1);
// Add score
increaseScore(self.scoreValue || 1);
}
});
tween(enemyGraphics.scale, {
x: 1.5,
y: 1.5
}, {
duration: 300
});
};
self.shoot = function () {
if (!self.canShoot) {
return;
}
var bullet = new EnemyBullet();
bullet.x = self.x;
bullet.y = self.y + enemyGraphics.height / 2;
game.addChild(bullet);
enemyBullets.push(bullet);
self.canShoot = false;
LK.setTimeout(function () {
self.canShoot = true;
}, self.shootCooldown);
};
self.update = function () {
self.y += self.speed;
self.x += Math.sin(LK.ticks / self.driftSpeed) * self.driftAmount;
// Bosses and some enemies shoot at the player
if ((self.type === ENEMY_TYPES.BOSS || Math.random() < 0.005) && self.y > 0) {
self.shoot();
}
// Destroy if off-screen with fade-out effect
if (self.y > SCREEN_HEIGHT + enemyGraphics.height / 2) {
tween(enemyGraphics, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
self.destroy();
var index = enemyShips.indexOf(self);
if (index !== -1) {
enemyShips.splice(index, 1);
}
}
});
}
};
return self;
});
/****
* Particle System
****/
var ParticleSystem = Container.expand(function (config) {
var self = Container.call(this);
self.particles = [];
self.maxParticles = config.maxParticles || 20;
self.minLifetime = config.minLifetime || 300;
self.maxLifetime = config.maxLifetime || 600;
self.minSpeed = config.minSpeed || 1;
self.maxSpeed = config.maxSpeed || 3;
self.colors = config.colors || [0xFFFFFF];
self.size = config.size || 5;
self.emit = function (x, y, count) {
count = count || 10;
for (var i = 0; i < count && self.particles.length < self.maxParticles; i++) {
var angle = Math.random() * Math.PI * 2;
var speed = self.minSpeed + Math.random() * (self.maxSpeed - self.minSpeed);
var lifetime = self.minLifetime + Math.random() * (self.maxLifetime - self.minLifetime);
var particle = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
tint: self.colors[Math.floor(Math.random() * self.colors.length)],
scaleX: self.size / 10,
scaleY: self.size / 10
});
particle.x = x;
particle.y = y;
particle.vx = Math.cos(angle) * speed;
particle.vy = Math.sin(angle) * speed;
particle.alpha = 1;
particle.lifetime = lifetime;
self.addChild(particle);
self.particles.push(particle);
}
};
self.update = function () {
for (var i = self.particles.length - 1; i >= 0; i--) {
var p = self.particles[i];
p.x += p.vx;
p.y += p.vy;
p.lifetime -= LK.deltaTime;
p.alpha = p.lifetime / self.maxLifetime;
if (p.lifetime <= 0) {
p.destroy();
self.particles.splice(i, 1);
}
}
};
return self;
});
// Class for player bullets with proper destruction
var PlayerBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('playerBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -15;
self.update = function () {
self.y += self.speed;
// Add trail effect
if (LK.ticks % 3 === 0) {
particleSystem.emit(self.x, self.y + bulletGraphics.height / 2, 1);
}
if (self.y < -bulletGraphics.height) {
self.destroy();
var index = playerBullets.indexOf(self);
if (index !== -1) {
playerBullets.splice(index, 1);
}
}
};
return self;
});
// Class for the player's ship with shooting cooldown
var PlayerShip = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('playerShip', {
anchorX: 0.5,
anchorY: 0.5
});
// Shield graphics
var shieldGraphics = self.attachAsset('shield', {
anchorX: 0.5,
anchorY: 0.5
});
shieldGraphics.visible = false;
self.defaultSpeed = 10;
self.speed = self.defaultSpeed;
self.canShoot = true; // Prevents spam shooting
self.shootCooldown = 300; // 300ms cooldown
self.lives = 3; // Player starts with 3 lives
self.invulnerable = false; // Invulnerability after being hit
self.hasTripleShot = false;
self.hasShield = false;
self.tripleShotTimer = null;
self.shieldTimer = null;
self.speedBoostTimer = null;
// Thruster particles
self.thrusterParticles = function () {
if (LK.ticks % 3 === 0) {
particleSystem.emit(self.x, self.y + shipGraphics.height / 2, 2);
}
};
self.shoot = function () {
if (self.canShoot) {
// Play shoot sound
LK.getSound('shoot').play({
volume: 0.3
});
if (self.hasTripleShot) {
// Triple shot pattern
for (var i = -1; i <= 1; i++) {
var bullet = new PlayerBullet();
bullet.x = self.x + i * 30;
bullet.y = self.y - shipGraphics.height / 2;
game.addChild(bullet);
playerBullets.push(bullet);
}
} else {
// Single shot
var bullet = new PlayerBullet();
bullet.x = self.x;
bullet.y = self.y - shipGraphics.height / 2;
game.addChild(bullet);
playerBullets.push(bullet);
}
self.canShoot = false;
LK.setTimeout(function () {
self.canShoot = true;
}, self.shootCooldown);
}
};
self.hit = function () {
if (self.invulnerable) {
return;
}
// If player has shield, remove it instead of taking damage
if (self.hasShield) {
self.setShield(false);
// Special shield break effect
particleSystem.emit(self.x, self.y, 30);
// Brief invulnerability after shield breaks
self.invulnerable = true;
LK.setTimeout(function () {
self.invulnerable = false;
}, 1000);
return;
}
self.lives--;
updateLivesDisplay();
if (self.lives <= 0) {
// Final explosion effect
particleSystem.emit(self.x, self.y, 50);
LK.showGameOver();
return;
}
// Make player invulnerable temporarily
self.invulnerable = true;
// Flash effect
var flashCount = 0;
var flashInterval = LK.setInterval(function () {
shipGraphics.alpha = shipGraphics.alpha === 1 ? 0.3 : 1;
flashCount++;
if (flashCount >= 10) {
LK.clearInterval(flashInterval);
shipGraphics.alpha = 1;
self.invulnerable = false;
}
}, 150);
};
// Powerup methods
self.setTripleShot = function (active) {
self.hasTripleShot = active;
// Show triple shot status
showStatusMessage(active ? "TRIPLE SHOT!" : "Triple shot expired", 0x00FFFF);
// Clear existing timer if any
if (self.tripleShotTimer) {
LK.clearTimeout(self.tripleShotTimer);
}
// Set timer to remove triple shot
if (active) {
self.tripleShotTimer = LK.setTimeout(function () {
self.setTripleShot(false);
}, 10000); // 10 seconds
}
};
self.setShield = function (active) {
self.hasShield = active;
shieldGraphics.visible = active;
if (active) {
// Show shield animation
shieldGraphics.scale.set(0);
tween(shieldGraphics.scale, {
x: 1,
y: 1
}, {
duration: 300
});
showStatusMessage("SHIELD ACTIVATED!", 0x0088FF);
}
// Clear existing timer if any
if (self.shieldTimer) {
LK.clearTimeout(self.shieldTimer);
}
// Set timer to remove shield
if (active) {
self.shieldTimer = LK.setTimeout(function () {
if (self.hasShield) {
self.setShield(false);
showStatusMessage("Shield expired", 0x0088FF);
}
}, 15000); // 15 seconds
}
};
self.setSpeedBoost = function (active) {
self.speed = active ? self.defaultSpeed * 1.5 : self.defaultSpeed;
showStatusMessage(active ? "SPEED BOOST!" : "Speed boost expired", 0xFFFF00);
// Clear existing timer if any
if (self.speedBoostTimer) {
LK.clearTimeout(self.speedBoostTimer);
}
// Set timer to remove speed boost
if (active) {
self.speedBoostTimer = LK.setTimeout(function () {
self.setSpeedBoost(false);
}, 8000); // 8 seconds
}
};
self.addLife = function () {
self.lives++;
updateLivesDisplay();
showStatusMessage("EXTRA LIFE!", 0xFF0000);
};
self.update = function () {
// Thruster effect
self.thrusterParticles();
// Shield rotation effect
if (self.hasShield) {
shieldGraphics.rotation += 0.01;
}
if (self.invulnerable) {
return;
}
// Check collision with enemy ships
for (var i = 0; i < enemyShips.length; i++) {
if (self.intersects(enemyShips[i])) {
self.hit();
enemyShips[i].explode();
break;
}
}
// Check collision with enemy bullets
for (var j = 0; j < enemyBullets.length; j++) {
if (self.intersects(enemyBullets[j])) {
self.hit();
enemyBullets[j].destroy();
enemyBullets.splice(j, 1);
break;
}
}
// Check collision with powerups
for (var k = 0; k < powerups.length; k++) {
if (self.intersects(powerups[k])) {
powerups[k].collect();
break;
}
}
};
return self;
});
// Class for powerups
var Powerup = Container.expand(function (type) {
var self = Container.call(this);
self.type = type || POWERUP_TYPES.TRIPLE_SHOT;
var powerupGraphics = self.attachAsset('powerup', {
anchorX: 0.5,
anchorY: 0.5
});
// Set color based on powerup type
switch (self.type) {
case POWERUP_TYPES.TRIPLE_SHOT:
powerupGraphics.tint = 0x00FFFF;
break;
case POWERUP_TYPES.SHIELD:
powerupGraphics.tint = 0x0000FF;
break;
case POWERUP_TYPES.SPEED:
powerupGraphics.tint = 0xFFFF00;
break;
case POWERUP_TYPES.LIFE:
powerupGraphics.tint = 0xFF0000;
break;
}
// Floating animation
self.floatOffset = Math.random() * Math.PI * 2;
self.speed = 2 + Math.random();
self.update = function () {
self.y += self.speed;
self.x += Math.sin((LK.ticks + self.floatOffset) / 20) * 1.5;
// Add sparkle effect
if (LK.ticks % 10 === 0) {
particleSystem.emit(self.x, self.y, 1);
}
// Destroy if off-screen
if (self.y > SCREEN_HEIGHT + powerupGraphics.height) {
self.destroy();
var index = powerups.indexOf(self);
if (index !== -1) {
powerups.splice(index, 1);
}
}
};
self.collect = function () {
// Play powerup sound
LK.sound.play('powerup', {
volume: 0.7
});
// Apply powerup effect
switch (self.type) {
case POWERUP_TYPES.TRIPLE_SHOT:
player.setTripleShot(true);
break;
case POWERUP_TYPES.SHIELD:
player.setShield(true);
break;
case POWERUP_TYPES.SPEED:
player.setSpeedBoost(true);
break;
case POWERUP_TYPES.LIFE:
player.addLife();
break;
}
// Remove powerup with effect
tween(powerupGraphics.scale, {
x: 2,
y: 2
}, {
duration: 200
});
tween(powerupGraphics, {
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
self.destroy();
powerups.splice(powerups.indexOf(self), 1);
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
/****
* Game Constants
****/
// Replace with actual sound ID
// Replace with actual sound ID
// Replace with actual sound ID
// Replace with actual powerup image ID
// Replace with actual background image ID
// Additional assets
// Add scrolling background
var SCREEN_WIDTH = 2048;
var SCREEN_HEIGHT = 2732;
var ENEMY_TYPES = {
BASIC: 'basic',
FAST: 'fast',
TANK: 'tank',
BOSS: 'boss'
};
var POWERUP_TYPES = {
TRIPLE_SHOT: 'tripleShot',
SHIELD: 'shield',
SPEED: 'speed',
LIFE: 'life'
};
function createScrollingBackground() {
var bg1 = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
}));
var bg2 = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
}));
bg1.y = 0;
bg2.y = -SCREEN_HEIGHT;
game.updateBackground = function () {
bg1.y += 1;
bg2.y += 1;
if (bg1.y >= SCREEN_HEIGHT) {
bg1.y = bg2.y - SCREEN_HEIGHT;
}
if (bg2.y >= SCREEN_HEIGHT) {
bg2.y = bg1.y - SCREEN_HEIGHT;
}
};
}
/****
* Game Variables
****/
var playerBullets = [];
var enemyBullets = [];
var enemyShips = [];
var powerups = [];
var player = game.addChild(new PlayerShip());
player.x = SCREEN_WIDTH / 2;
player.y = SCREEN_HEIGHT - 200;
// Create particle system
var particleSystem = game.addChild(new ParticleSystem({
maxParticles: 200,
minLifetime: 300,
maxLifetime: 800,
minSpeed: 1,
maxSpeed: 4,
colors: [0x00FFFF, 0x0088FF, 0xFFFFFF],
size: 4
}));
// Score Display
var scoreText = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
scoreText.x = SCREEN_WIDTH / 2;
scoreText.y = 50;
LK.gui.top.addChild(scoreText);
// Lives Display
var livesText = new Text2('Lives: 3', {
size: 100,
fill: 0xFFFFFF
});
livesText.anchor.set(0, 0);
livesText.x = 50;
livesText.y = 50;
LK.gui.top.addChild(livesText);
// Wave Display
var waveText = new Text2('Wave: 1', {
size: 100,
fill: 0xFFFFFF
});
waveText.anchor.set(1, 0);
waveText.x = SCREEN_WIDTH - 50;
waveText.y = 50;
LK.gui.top.addChild(waveText);
// Status message display
var statusMessage = new Text2('', {
size: 100,
fill: 0xFFFFFF
});
statusMessage.anchor.set(0.5, 0);
statusMessage.x = SCREEN_WIDTH / 2;
statusMessage.y = 200;
statusMessage.alpha = 0;
LK.gui.top.addChild(statusMessage);
// Wave Variables
var waveNumber = 1;
var enemiesPerWave = 5;
var enemiesSpawned = 0;
var waveInProgress = true;
var waveCooldown = false;
/****
* Helper Functions
****/
function updateLivesDisplay() {
livesText.setText('Lives: ' + player.lives);
}
function increaseScore(amount) {
LK.setScore(LK.getScore() + amount);
scoreText.setText(LK.getScore());
}
function updateWaveDisplay() {
waveText.setText('Wave: ' + waveNumber);
}
function showStatusMessage(message, color) {
statusMessage.setText(message);
statusMessage.setStyle({
fill: color || 0xFFFFFF
});
statusMessage.alpha = 1;
// Animation
statusMessage.scale.set(0.8);
tween(statusMessage.scale, {
x: 1,
y: 1
}, {
duration: 300
});
// Fade out
tween(statusMessage, {
alpha: 0
}, {
duration: 1500,
delay: 1000
});
}
function spawnPowerup(x, y) {
var types = Object.values(POWERUP_TYPES);
var type = types[Math.floor(Math.random() * types.length)];
var powerup = new Powerup(type);
powerup.x = x;
powerup.y = y;
game.addChild(powerup);
powerups.push(powerup);
}
// Function to spawn enemies in waves
function spawnEnemy() {
if (!waveInProgress || waveCooldown) {
return;
}
if (enemiesSpawned < enemiesPerWave) {
var enemy;
var enemyType;
// Every 3 waves, add a boss as the last enemy
if (waveNumber > 0 && waveNumber % 3 === 0 && enemiesSpawned === enemiesPerWave - 1) {
enemyType = ENEMY_TYPES.BOSS;
} else {
// Determine enemy type based on wave number and random chance
var random = Math.random();
if (waveNumber >= 5 && random < 0.2) {
enemyType = ENEMY_TYPES.TANK;
} else if (waveNumber >= 3 && random < 0.4) {
enemyType = ENEMY_TYPES.FAST;
} else {
enemyType = ENEMY_TYPES.BASIC;
}
}
enemy = new EnemyShip(enemyType);
enemy.x = Math.random() * SCREEN_WIDTH;
enemy.y = -100;
game.addChild(enemy);
enemyShips.push(enemy);
enemiesSpawned++;
if (enemiesSpawned >= enemiesPerWave) {
waveInProgress = false;
}
}
}
function startNextWave() {
waveNumber++;
updateWaveDisplay();
enemiesPerWave += 2; // Increase difficulty each wave
enemiesSpawned = 0;
waveInProgress = true;
// Display wave number
var newWaveText = new Text2('WAVE ' + waveNumber, {
size: 250,
fill: 0xFFFFFF
});
newWaveText.anchor.set(0.5, 0.5);
newWaveText.x = SCREEN_WIDTH / 2;
newWaveText.y = SCREEN_HEIGHT / 2;
game.addChild(newWaveText);
// Animate and remove wave text
tween(newWaveText.scale, {
x: 1.5,
y: 1.5
}, {
duration: 800,
onFinish: function onFinish() {
tween(newWaveText, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
newWaveText.destroy();
}
});
}
});
}
// Initialize game elements
function initGame() {
createScrollingBackground();
showStatusMessage("GET READY!", 0xFFFFFF);
}
// Call initialization
initGame();
/****
* Game update loop
****/
game.update = function () {
// Update scrolling background
if (game.updateBackground) {
game.updateBackground();
}
// Update particle system
particleSystem.update();
// Update player
player.update();
// Update player bullets
for (var i = playerBullets.length - 1; i >= 0; i--) {
if (playerBullets[i]) {
playerBullets[i].update();
}
}
// Update enemy bullets
for (var j = enemyBullets.length - 1; j >= 0; j--) {
if (enemyBullets[j]) {
enemyBullets[j].update();
}
}
// Update powerups
for (var l = powerups.length - 1; l >= 0; l--) {
if (powerups[l]) {
powerups[l].update();
}
}
// Check for collisions between player bullets and enemy ships
for (var m = playerBullets.length - 1; m >= 0; m--) {
if (!playerBullets[m]) {
continue;
}
for (var n = enemyShips.length - 1; n >= 0; n--) {
if (!enemyShips[n]) {
continue;
}
if (playerBullets[m] && enemyShips[n] && playerBullets[m].intersects(enemyShips[n])) {
// Enemy hit by bullet
var destroyed = enemyShips[n].hit();
// Remove bullet
playerBullets[m].destroy();
playerBullets.splice(m, 1);
break;
}
}
}
// Spawn enemies periodically
if (LK.ticks % 60 === 0) {
spawnEnemy();
}
// Check if wave is complete and start next wave
if (!waveInProgress && enemyShips.length === 0 && !waveCooldown) {
waveCooldown = true;
LK.setTimeout(function () {
startNextWave();
waveCooldown = false;
}, 2000);
}
};
// Handle player movement
game.move = function (x, y, obj) {
// Calculate movement based on speed
var targetX = x;
var currentX = player.x;
var dx = targetX - currentX;
// Apply player speed
if (Math.abs(dx) > player.speed) {
dx = Math.sign(dx) * player.speed;
}
// Constrain player to screen boundaries
var halfWidth = player.getChildAt(0).width / 2;
player.x = Math.min(Math.max(currentX + dx, halfWidth), SCREEN_WIDTH - halfWidth);
};
// Handle shooting
game.down = function (x, y, obj) {
player.shoot();
};
// Add pause/resume functionality
LK.gui.pauseButton = function () {
var pauseBtn = new Container();
var pauseBg = new Graphics();
pauseBg.beginFill(0x000000, 0.5);
pauseBg.drawCircle(0, 0, 40);
pauseBg.endFill();
pauseBtn.addChild(pauseBg);
var pauseIcon = new Graphics();
pauseIcon.beginFill(0xFFFFFF);
pauseIcon.drawRect(-15, -15, 10, 30);
pauseIcon.drawRect(5, -15, 10, 30);
pauseIcon.endFill();
pauseBtn.addChild(pauseIcon);
pauseBtn.x = SCREEN_WIDTH - 60;
pauseBtn.y = 60;
pauseBtn.interactive = true;
pauseBtn.down = function () {
showPauseMenu();
showPauseMenu();
};
return pauseBtn;
};
// Custom pause menu
function showPauseMenu() {
var pauseMenu = new Container();
var overlay = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x000000,
alpha: 0.7,
scaleX: SCREEN_WIDTH / 100,
scaleY: SCREEN_HEIGHT / 100
});
pauseMenu.addChild(overlay);
var title = new Text2("PAUSED", {
size: 200,
fill: 0xFFFFFF
});
title.anchor.set(0.5, 0.5);
title.x = SCREEN_WIDTH / 2;
title.y = SCREEN_HEIGHT / 3;
pauseMenu.addChild(title);
var resumeBtn = createButton("RESUME", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, function () {
pauseMenu.destroy();
LK.resumeGame();
});
pauseMenu.addChild(resumeBtn);
var restartBtn = createButton("RESTART", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 150, function () {
pauseMenu.destroy();
LK.showGameOver();
});
pauseMenu.addChild(restartBtn);
LK.gui.addChild(pauseMenu);
}
// Helper function to create buttons
function createButton(text, x, y, callback) {
var button = new Container();
var bg = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x333333,
scaleX: 3,
scaleY: 0.8
});
button.addChild(bg);
var label = new Text2(text, {
size: 60,
fill: 0xFFFFFF
});
label.anchor.set(0.5, 0.5);
button.addChild(label);
button.x = x;
button.y = y;
button.interactive = true;
button.down = function () {
// Button press effect
button.scale.set(0.95);
LK.setTimeout(function () {
button.scale.set(1);
if (callback) {
callback();
}
}, 100);
};
return button;
}
// Custom game over screen
LK.showGameOver = function () {
var gameOver = new Container();
var overlay = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x000000,
alpha: 0.8,
scaleX: SCREEN_WIDTH / 100,
scaleY: SCREEN_HEIGHT / 100
});
gameOver.addChild(overlay);
var title = new Text2("GAME OVER", {
size: 200,
fill: 0xFF0000
});
title.anchor.set(0.5, 0.5);
title.x = SCREEN_WIDTH / 2;
title.y = SCREEN_HEIGHT / 3;
gameOver.addChild(title);
var scoreDisplay = new Text2("SCORE: " + LK.getScore(), {
size: 120,
fill: 0xFFFFFF
});
scoreDisplay.anchor.set(0.5, 0.5);
scoreDisplay.x = SCREEN_WIDTH / 2;
scoreDisplay.y = SCREEN_HEIGHT / 2;
gameOver.addChild(scoreDisplay);
var waveDisplay = new Text2("WAVES COMPLETED: " + (waveNumber - 1), {
size: 80,
fill: 0xFFFFFF
});
waveDisplay.anchor.set(0.5, 0.5);
waveDisplay.x = SCREEN_WIDTH / 2;
waveDisplay.y = SCREEN_HEIGHT / 2 + 100;
gameOver.addChild(waveDisplay);
var restartBtn = createButton("PLAY AGAIN", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 250, function () {
gameOver.destroy();
LK.showGameOver();
});
gameOver.addChild(restartBtn);
// Add final explosion particles
for (var i = 0; i < 10; i++) {
LK.setTimeout(function () {
particleSystem.emit(SCREEN_WIDTH / 2 + (Math.random() * 500 - 250), SCREEN_HEIGHT / 2 + (Math.random() * 500 - 250), 30);
}, i * 200);
}
LK.gui.addChild(gameOver);
showPauseMenu();
};
// Add a start menu
function showStartMenu() {
var startMenu = new Container();
var overlay = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x000033,
alpha: 0.9,
scaleX: SCREEN_WIDTH / 100,
scaleY: SCREEN_HEIGHT / 100
});
startMenu.addChild(overlay);
var title = new Text2("SPACE SHOOTER", {
size: 200,
fill: 0x00FFFF
});
title.anchor.set(0.5, 0.5);
title.x = SCREEN_WIDTH / 2;
title.y = SCREEN_HEIGHT / 3;
startMenu.addChild(title);
var startBtn = createButton("START GAME", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 100, function () {
startMenu.destroy();
// Show tutorial message
showStatusMessage("TAP TO SHOOT, DRAG TO MOVE", 0xFFFFFF);
});
startMenu.addChild(startBtn);
// Add stars effect
for (var i = 0; i < 50; i++) {
var star = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFFFFFF,
scaleX: (1 + Math.random() * 3) / 10,
scaleY: (1 + Math.random() * 3) / 10,
alpha: 0.3 + Math.random() * 0.7
});
star.x = Math.random() * SCREEN_WIDTH;
star.y = Math.random() * SCREEN_HEIGHT;
// Twinkle animation
(function (s) {
var duration = 1000 + Math.random() * 2000;
var _animate = function animate() {
tween(s, {
alpha: 0.2 + Math.random() * 0.8
}, {
duration: duration,
onFinish: _animate
});
};
_animate();
})(star);
startMenu.addChild(star);
}
LK.gui.addChild(startMenu);
showPauseMenu();
}
// Show start menu on game load
LK.setTimeout(function () {
showStartMenu();
}, 100);
// Add cheats for debugging
var cheats = {
invincible: false,
toggleInvincible: function toggleInvincible() {
this.invincible = !this.invincible;
player.invulnerable = this.invincible;
showStatusMessage("Invincibility: " + (this.invincible ? "ON" : "OFF"), 0xFFFF00);
},
addLife: function addLife() {
player.addLife();
},
skipWave: function skipWave() {
enemyShips.forEach(function (ship) {
ship.explode();
});
enemyShips = [];
waveInProgress = false;
},
activateAllPowerups: function activateAllPowerups() {
player.setTripleShot(true);
player.setShield(true);
player.setSpeedBoost(true);
}
};
// Uncomment to enable console cheats
/*
LK.console = function(command) {
switch (command) {
case "god":
cheats.toggleInvincible();
break;
case "life":
cheats.addLife();
break;
case "skip":
cheats.skipWave();
break;
case "power":
cheats.activateAllPowerups();
break;
default:
return "Unknown command";
}
return "Command executed: " + command;
};
*/
A 2D top-down view of a futuristic player spaceship with a streamlined silver and blue body, glowing thrusters, and dual laser cannons. The design is sleek and modern for a space shooter game. Single Game Texture. 2d. Blank background. High contrast. No shadows
A 2D top-down view of an alien spaceship with a dark metallic body, glowing red energy cores, and sharp angular wings. The design is sleek and futuristic, suitable for a space shooter game.. Single Game Texture. 2d. Blank background. High contrast. No shadows
A 2D top-down view of a futuristic energy bullet for a space shooter game. The bullet is a glowing blue plasma projectile with a sleek, elongated shape and a slight energy trail behind it. The design is simple, bright, and high-speed-looking, suitable for fast-paced shooting gameplay. Single Game Texture. In-Game asset. Blank background. High contrast. No shadows
A 2D top-down view of a futuristic energy bullet for a space shooter game. The bullet is a glowing red plasma projectile elongated shape and a slight energy trail behind it. The design is simple, bright, and high-speed-looking, suitable for fast-paced shooting gameplay. Single Game Texture. In-Game asset. Blank background. High contrast. No shadows
A vibrant and dynamic 2D space background for a top-down space shooter game. The scene features a deep, dark space filled with glowing nebulae in shades of blue and purple, scattered distant stars, and swirling cosmic dust. A subtle parallax effect is suggested with faintly glowing planets and asteroids in the background. The atmosphere is slightly mysterious and futuristic, with soft light gradients to create depth. The overall tone is immersive but does not distract from gameplay, ensuring clear visibility of player and enemy ships.. Single Game Texture. Blank background. High contrast. No shadows
A vibrant and dynamic 2D space background for a top-down space shooter game. The scene features a deep, dark space filled with glowing nebulae in shades of blue and purple, scattered distant stars, and swirling cosmic dust. A subtle parallax effect is suggested with faintly glowing planets and asteroids in the background. The atmosphere is slightly mysterious and futuristic, with soft light gradients to create depth. The overall tone is immersive but does not distract from gameplay, ensuring clear visibility of player and enemy ships.. Single Game Texture. Blank background. High contrast. No shadows
powerup boll. Single Game Texture. Blank background. High contrast. No shadows