User prompt
bullet moving verticaly
User prompt
fix
User prompt
player auto moving horizontaly
User prompt
player auto move horizontal left and right. shooting when taping
User prompt
make 100 waves level
User prompt
make waves level until 100 wave
User prompt
make perfect
Code edit (1 edits merged)
Please save this source code
User prompt
Retro Commando: 8-Bit Assault
Initial prompt
make top down 8 bit look a like contra game with edit code import pygame import random import sys # Initialize pygame pygame.init() # Screen dimensions SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) pygame.display.set_caption("8-Bit Contra-like") # Colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0, 0, 255) # Player class class Player(pygame.sprite.Sprite): def __init__(self): super().__init__() self.image = pygame.Surface((30, 50)) self.image.fill(GREEN) self.rect = self.image.get_rect() self.rect.x = 100 self.rect.y = SCREEN_HEIGHT - 150 self.speed_x = 0 self.speed_y = 0 self.jumping = False self.health = 100 self.shoot_delay = 250 # milliseconds self.last_shot = pygame.time.get_ticks() def update(self): # Gravity if self.jumping: self.speed_y += 0.8 if self.speed_y > 10: self.speed_y = 10 # Update position self.rect.x += self.speed_x self.rect.y += self.speed_y # Keep player on screen if self.rect.left < 0: self.rect.left = 0 if self.rect.right > SCREEN_WIDTH: self.rect.right = SCREEN_WIDTH if self.rect.bottom > SCREEN_HEIGHT - 100: self.rect.bottom = SCREEN_HEIGHT - 100 self.jumping = False self.speed_y = 0 def jump(self): if not self.jumping: self.jumping = True self.speed_y = -15 def shoot(self): now = pygame.time.get_ticks() if now - self.last_shot > self.shoot_delay: self.last_shot = now bullet = Bullet(self.rect.right, self.rect.centery) all_sprites.add(bullet) bullets.add(bullet) # Bullet class class Bullet(pygame.sprite.Sprite): def __init__(self, x, y): super().__init__() self.image = pygame.Surface((10, 5)) self.image.fill(RED) self.rect = self.image.get_rect() self.rect.left = x self.rect.centery = y self.speed = 10 def update(self): self.rect.x += self.speed # Remove if it goes off screen if self.rect.left > SCREEN_WIDTH: self.kill() # Enemy class class Enemy(pygame.sprite.Sprite): def __init__(self): super().__init__() self.image = pygame.Surface((30, 40)) self.image.fill(RED) self.rect = self.image.get_rect() self.rect.x = random.randrange(SCREEN_WIDTH, SCREEN_WIDTH + 100) self.rect.y = SCREEN_HEIGHT - 140 self.speed = random.randrange(1, 4) def update(self): self.rect.x -= self.speed if self.rect.right < 0: self.rect.x = random.randrange(SCREEN_WIDTH, SCREEN_WIDTH + 100) self.rect.y = SCREEN_HEIGHT - 140 self.speed = random.randrange(1, 4) # Platform class class Platform(pygame.sprite.Sprite): def __init__(self, x, y, width, height): super().__init__() self.image = pygame.Surface((width, height)) self.image.fill(BLUE) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y # Create sprite groups all_sprites = pygame.sprite.Group() enemies = pygame.sprite.Group() bullets = pygame.sprite.Group() platforms = pygame.sprite.Group() # Create player player = Player() all_sprites.add(player) # Create platforms ground = Platform(0, SCREEN_HEIGHT - 100, SCREEN_WIDTH, 100) platforms.add(ground) all_sprites.add(ground) # Create some floating platforms for i in range(3): p = Platform(random.randrange(0, SCREEN_WIDTH - 100), random.randrange(200, SCREEN_HEIGHT - 200), 100, 20) platforms.add(p) all_sprites.add(p) # Create enemies for i in range(8): enemy = Enemy() all_sprites.add(enemy) enemies.add(enemy) # Game loop clock = pygame.time.Clock() score = 0 running = True font = pygame.font.SysFont('Arial', 24) while running: # Keep loop running at the right speed clock.tick(60) # Process input (events) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: player.jump() if event.key == pygame.K_f: player.shoot() # Get pressed keys keys = pygame.key.get_pressed() player.speed_x = 0 if keys[pygame.K_LEFT]: player.speed_x = -5 if keys[pygame.K_RIGHT]: player.speed_x = 5 # Update all_sprites.update() # Check if bullets hit enemies hits = pygame.sprite.groupcollide(bullets, enemies, True, True) for hit in hits: score += 10 enemy = Enemy() all_sprites.add(enemy) enemies.add(enemy) # Check if player hits enemies hits = pygame.sprite.spritecollide(player, enemies, False) if hits: player.health -= 1 if player.health <= 0: running = False # Draw / render screen.fill(BLACK) all_sprites.draw(screen) # Draw HUD score_text = font.render(f"Score: {score}", True, WHITE) health_text = font.render(f"Health: {player.health}", True, WHITE) screen.blit(score_text, (10, 10)) screen.blit(health_text, (10, 40)) # Flip the display pygame.display.flip() pygame.quit() sys.exit()
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 140; // Double the speed again for faster gameplay self.damage = 1; self.update = function () { // Auto-move player left and right self.y -= self.speed; // Auto-destroy bullets that go off screen if (self.y < -50) { self.destroy(); } }; return self; }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.health = 1; // Ensure enemy dies in one hit self.speed = 2 + Math.random() * 0.5; // Decrease enemy movement speed for slower gameplay self.value = 100; // score value self.canShoot = Math.random() < 0.3; // 30% of enemies can shoot self.lastShot = 0; self.fireRate = 2000 + Math.random() * 2000; // Random fire rate between 2-4 seconds // Create health bar self.healthBarBg = self.attachAsset('healthBarBg', { anchorX: 0.5, anchorY: 0.5, y: -70 }); self.healthBar = self.attachAsset('healthBar', { anchorX: 0.5, anchorY: 0.5, y: -70 }); self.updateHealthBar = function () { var healthPercentage = self.health / 2; // 2 is max health self.healthBar.scaleX = healthPercentage; }; self.damage = function (amount) { self.health -= amount; self.updateHealthBar(); // Flash enemy when hit LK.effects.flashObject(self, 0xffffff, 200); if (self.health <= 0) { // Create explosion var explosion = new Explosion(); explosion.x = self.x; explosion.y = self.y; game.addChild(explosion); // Add score LK.setScore(LK.getScore() + self.value); // Remove from array and destroy self.destroy(); } }; self.shoot = function () { // Create a single bullet var enemyBullet = new EnemyBullet(); enemyBullet.x = self.x; enemyBullet.y = self.y + 50; // Start below the enemy enemyBullet.speed = 4; // Set speed for the bullet game.addChild(enemyBullet); enemyBullets.push(enemyBullet); LK.getSound('enemyShoot').play(); }; self.update = function () { self.y += self.speed; // Remove evade behavior from enemies // Shooting logic if (self.canShoot) { var now = Date.now(); if (now - self.lastShot > self.fireRate) { self.lastShot = now; self.shoot(); } } // Destroy if off screen if (self.y > 2732 + 100) { self.destroy(); gameActive = false; updateHighScore(); LK.showGameOver(); } }; return self; }); var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; // Lower enemy bullet speed for less challenging gameplay self.damage = 5; // Increase enemy bullet damage self.update = function () { self.y += self.speed; // Auto-destroy bullets that go off screen if (self.y > 2732 + 50) { self.destroy(); } }; return self; }); var Explosion = Container.expand(function () { var self = Container.call(this); var explosionGraphics = self.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.5, scaleY: 0.5 }); // Play explosion sound LK.getSound('explosion').play(); // Animate explosion tween(explosionGraphics, { scaleX: 2, scaleY: 2, alpha: 0 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.maxHealth = 3; self.health = self.maxHealth; self.fireRate = 500; // Fire rate set to 0.5 seconds per shot self.lastShot = 0; self.speed = 20; self.invulnerable = false; // Create health bar self.healthBarBg = self.attachAsset('healthBarBg', { anchorX: 0.5, anchorY: 0.5, y: -80 }); self.healthBar = self.attachAsset('healthBar', { anchorX: 0.5, anchorY: 0.5, y: -80 }); self.updateHealthBar = function () { var healthPercentage = self.health / self.maxHealth; self.healthBar.scaleX = healthPercentage; }; self.damage = function (amount) { if (self.invulnerable) { return; } self.health -= amount; self.updateHealthBar(); LK.getSound('playerHit').play(); // Flash player when hit self.invulnerable = true; LK.effects.flashObject(self, 0xff0000, 1000); LK.setTimeout(function () { self.invulnerable = false; }, 1000); if (self.health <= 0) { // Create explosion var explosion = new Explosion(); explosion.x = self.x; explosion.y = self.y; game.addChild(explosion); // Game over LK.setTimeout(function () { LK.showGameOver(); }, 1000); self.visible = false; } }; self.shoot = function () { var now = Date.now(); if (now - self.lastShot < self.fireRate) { return; } self.lastShot = now; // Create twin bullets var bulletLeft = new Bullet(); var bulletRight = new Bullet(); // Position bullets slightly apart bulletLeft.x = self.x - 20; bulletRight.x = self.x + 20; bulletLeft.y = self.y - 50; bulletRight.y = self.y - 50; // Add bullets to the game game.addChild(bulletLeft); game.addChild(bulletRight); // Add to game's bullets array bullets.push(bulletLeft); bullets.push(bulletRight); LK.getSound('playerShoot').play(); }; self.down = function (x, y, obj) { self.shoot(); // Trigger shooting when player is touched }; self.update = function () { // Manual player movement control if (gameActive) { // Movement logic will be handled in game.move // Automatically fire bullets every 60 ticks (1 second at 60 FPS) if (LK.ticks % 60 === 0) { self.shoot(); } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var background = LK.getAsset('nightSky', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(background); // Game variables var player; var bullets = []; var enemyBullets = []; var enemies = []; var powerUps = []; var waveNumber = 1; var enemiesInWave = 5 + waveNumber * 2; var lastEnemySpawn = 0; var enemySpawnRate = 2000; // Increase to 2 seconds between spawns for stability var waveDelay = 5000; // 5 seconds between waves var gameActive = true; var dragActive = false; // Setup GUI var waveTxt = new Text2('WAVE 1', { size: 80, fill: 0xFFFFFF }); waveTxt.anchor.set(0.5, 0); LK.gui.top.addChild(waveTxt); waveTxt.y = 50; // Initialize player player = new Player(); player.x = 2048 / 2; player.y = 2732 - 300; player.updateHealthBar(); game.addChild(player); // Start background music LK.playMusic('bgMusic', { fade: { start: 0, end: 0.6, duration: 1000 } }); // Touch/mouse handling var lastTapTime = 0; game.down = function (x, y, obj) { if (!gameActive) { return; } var currentTime = Date.now(); if (currentTime - lastTapTime < 300) { // Double-tap detected within 300ms player.speed = 20; // Resume player movement } lastTapTime = currentTime; if (gameActive) { player.shoot(); // Shoot when tapping } }; game.move = function (x, y, obj) { if (!gameActive || !player.visible) { return; } // Constrain player to game area if (x > 100 && x < 2048 - 100) { player.x = x; } if (y > 100 && y < 2732 - 100) { player.y = y; } }; game.up = function (x, y, obj) { dragActive = false; }; // Spawn enemies for current wave function spawnWave() { if (waveNumber > 100) { gameActive = false; updateHighScore(); LK.showYouWin(); return; } enemiesInWave = 3 + waveNumber; // Further reduce the number of enemies per wave for less frequent enemy appearances waveTxt.setText('WAVE ' + waveNumber); // Show wave notification waveTxt.alpha = 1; tween(waveTxt, { alpha: 0 }, { duration: 2000, easing: tween.easeOut }); // Slightly increase enemy spawn rate with each wave enemySpawnRate = Math.max(1000, 1500 - waveNumber * 50); } // Spawn a single enemy function spawnEnemy() { var enemy = new Enemy(); enemy.x = Math.random() * (2048 - 200) + 100; // Random position between 100 and (2048-100) enemy.y = -100; // Start above the screen enemy.updateHealthBar(); // Increase enemy health every few waves if (waveNumber > 3) { enemy.health += Math.floor(waveNumber / 3); enemy.updateHealthBar(); } // Increase enemy speed slightly with each wave enemy.speed += waveNumber * 0.1; game.addChild(enemy); enemies.push(enemy); enemiesInWave--; // Decrease the count of enemies to spawn in the current wave // Trigger automatic bullet release when an enemy appears player.shoot(); } // Save the high score if needed function updateHighScore() { var currentScore = LK.getScore(); if (currentScore > storage.highScore) { storage.highScore = currentScore; } } // Main game update loop game.update = function () { if (!gameActive) { return; } // Enemy spawning logic var now = Date.now(); if (enemies.length < enemiesInWave && now - lastEnemySpawn > enemySpawnRate) { lastEnemySpawn = now; spawnEnemy(); } // Wave transition logic if (enemies.length === 0 && enemiesInWave <= 0) { waveNumber++; if (waveNumber <= 100) { // Start next wave after delay LK.setTimeout(function () { spawnWave(); }, waveDelay); enemiesInWave = 5 + waveNumber * 2; // Reset for next wave } else { gameActive = false; updateHighScore(); LK.showYouWin(); } } // Bullet collision detection for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; // Check collision with each enemy for (var j = enemies.length - 1; j >= 0; j--) { var enemy = enemies[j]; if (bullet.intersects(enemy)) { // Damage enemy enemy.damage(bullet.damage); // Remove bullet bullet.destroy(); bullets.splice(i, 1); // If enemy is destroyed, remove from array if (enemy.health <= 0) { enemies.splice(j, 1); enemiesInWave--; } break; // This bullet hit something, stop checking } } } // Enemy bullet collision with player if (player.visible) { for (var i = enemyBullets.length - 1; i >= 0; i--) { var bullet = enemyBullets[i]; if (bullet.intersects(player)) { // Damage player player.damage(bullet.damage); // Remove bullet bullet.destroy(); enemyBullets.splice(i, 1); // Check if game over if (player.health <= 0) { gameActive = false; updateHighScore(); } } // Check collision with player bullets for (var j = bullets.length - 1; j >= 0; j--) { var playerBullet = bullets[j]; if (bullet.intersects(playerBullet)) { // Create explosion at the collision point var explosion = new Explosion(); explosion.x = bullet.x; explosion.y = bullet.y; game.addChild(explosion); // Destroy both bullets bullet.destroy(); enemyBullets.splice(i, 1); playerBullet.destroy(); bullets.splice(j, 1); // Display score bar var scoreBar = new Text2('Score: ' + LK.getScore(), { size: 50, fill: 0xFFFFFF }); scoreBar.anchor.set(0.5, 0); scoreBar.x = 2048 / 2; scoreBar.y = 100; game.addChild(scoreBar); LK.setTimeout(function () { scoreBar.destroy(); }, 2000); // Display for 2 seconds break; // Stop checking this bullet } } } // Enemy collision with player for (var i = enemies.length - 1; i >= 0; i--) { var enemy = enemies[i]; if (enemy.intersects(player)) { // Damage player player.damage(1); // Damage enemy enemy.damage(1); // If enemy is destroyed, remove from array if (enemy.health <= 0) { enemies.splice(i, 1); enemiesInWave--; } // Check if game over if (player.health <= 0) { gameActive = false; updateHighScore(); } } } } // Clean up arrays (remove destroyed objects) bullets = bullets.filter(function (bullet) { return bullet.parent !== null; }); enemyBullets = enemyBullets.filter(function (bullet) { return bullet.parent !== null; }); enemies = enemies.filter(function (enemy) { return enemy.parent !== null; }); powerUps = powerUps.filter(function (powerUp) { return powerUp.parent !== null; }); }; // Start the first wave spawnWave();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0
});
/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 140; // Double the speed again for faster gameplay
self.damage = 1;
self.update = function () {
// Auto-move player left and right
self.y -= self.speed;
// Auto-destroy bullets that go off screen
if (self.y < -50) {
self.destroy();
}
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 1; // Ensure enemy dies in one hit
self.speed = 2 + Math.random() * 0.5; // Decrease enemy movement speed for slower gameplay
self.value = 100; // score value
self.canShoot = Math.random() < 0.3; // 30% of enemies can shoot
self.lastShot = 0;
self.fireRate = 2000 + Math.random() * 2000; // Random fire rate between 2-4 seconds
// Create health bar
self.healthBarBg = self.attachAsset('healthBarBg', {
anchorX: 0.5,
anchorY: 0.5,
y: -70
});
self.healthBar = self.attachAsset('healthBar', {
anchorX: 0.5,
anchorY: 0.5,
y: -70
});
self.updateHealthBar = function () {
var healthPercentage = self.health / 2; // 2 is max health
self.healthBar.scaleX = healthPercentage;
};
self.damage = function (amount) {
self.health -= amount;
self.updateHealthBar();
// Flash enemy when hit
LK.effects.flashObject(self, 0xffffff, 200);
if (self.health <= 0) {
// Create explosion
var explosion = new Explosion();
explosion.x = self.x;
explosion.y = self.y;
game.addChild(explosion);
// Add score
LK.setScore(LK.getScore() + self.value);
// Remove from array and destroy
self.destroy();
}
};
self.shoot = function () {
// Create a single bullet
var enemyBullet = new EnemyBullet();
enemyBullet.x = self.x;
enemyBullet.y = self.y + 50; // Start below the enemy
enemyBullet.speed = 4; // Set speed for the bullet
game.addChild(enemyBullet);
enemyBullets.push(enemyBullet);
LK.getSound('enemyShoot').play();
};
self.update = function () {
self.y += self.speed;
// Remove evade behavior from enemies
// Shooting logic
if (self.canShoot) {
var now = Date.now();
if (now - self.lastShot > self.fireRate) {
self.lastShot = now;
self.shoot();
}
}
// Destroy if off screen
if (self.y > 2732 + 100) {
self.destroy();
gameActive = false;
updateHighScore();
LK.showGameOver();
}
};
return self;
});
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('enemyBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4; // Lower enemy bullet speed for less challenging gameplay
self.damage = 5; // Increase enemy bullet damage
self.update = function () {
self.y += self.speed;
// Auto-destroy bullets that go off screen
if (self.y > 2732 + 50) {
self.destroy();
}
};
return self;
});
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.5,
scaleY: 0.5
});
// Play explosion sound
LK.getSound('explosion').play();
// Animate explosion
tween(explosionGraphics, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.maxHealth = 3;
self.health = self.maxHealth;
self.fireRate = 500; // Fire rate set to 0.5 seconds per shot
self.lastShot = 0;
self.speed = 20;
self.invulnerable = false;
// Create health bar
self.healthBarBg = self.attachAsset('healthBarBg', {
anchorX: 0.5,
anchorY: 0.5,
y: -80
});
self.healthBar = self.attachAsset('healthBar', {
anchorX: 0.5,
anchorY: 0.5,
y: -80
});
self.updateHealthBar = function () {
var healthPercentage = self.health / self.maxHealth;
self.healthBar.scaleX = healthPercentage;
};
self.damage = function (amount) {
if (self.invulnerable) {
return;
}
self.health -= amount;
self.updateHealthBar();
LK.getSound('playerHit').play();
// Flash player when hit
self.invulnerable = true;
LK.effects.flashObject(self, 0xff0000, 1000);
LK.setTimeout(function () {
self.invulnerable = false;
}, 1000);
if (self.health <= 0) {
// Create explosion
var explosion = new Explosion();
explosion.x = self.x;
explosion.y = self.y;
game.addChild(explosion);
// Game over
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
self.visible = false;
}
};
self.shoot = function () {
var now = Date.now();
if (now - self.lastShot < self.fireRate) {
return;
}
self.lastShot = now;
// Create twin bullets
var bulletLeft = new Bullet();
var bulletRight = new Bullet();
// Position bullets slightly apart
bulletLeft.x = self.x - 20;
bulletRight.x = self.x + 20;
bulletLeft.y = self.y - 50;
bulletRight.y = self.y - 50;
// Add bullets to the game
game.addChild(bulletLeft);
game.addChild(bulletRight);
// Add to game's bullets array
bullets.push(bulletLeft);
bullets.push(bulletRight);
LK.getSound('playerShoot').play();
};
self.down = function (x, y, obj) {
self.shoot(); // Trigger shooting when player is touched
};
self.update = function () {
// Manual player movement control
if (gameActive) {
// Movement logic will be handled in game.move
// Automatically fire bullets every 60 ticks (1 second at 60 FPS)
if (LK.ticks % 60 === 0) {
self.shoot();
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var background = LK.getAsset('nightSky', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
// Game variables
var player;
var bullets = [];
var enemyBullets = [];
var enemies = [];
var powerUps = [];
var waveNumber = 1;
var enemiesInWave = 5 + waveNumber * 2;
var lastEnemySpawn = 0;
var enemySpawnRate = 2000; // Increase to 2 seconds between spawns for stability
var waveDelay = 5000; // 5 seconds between waves
var gameActive = true;
var dragActive = false;
// Setup GUI
var waveTxt = new Text2('WAVE 1', {
size: 80,
fill: 0xFFFFFF
});
waveTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(waveTxt);
waveTxt.y = 50;
// Initialize player
player = new Player();
player.x = 2048 / 2;
player.y = 2732 - 300;
player.updateHealthBar();
game.addChild(player);
// Start background music
LK.playMusic('bgMusic', {
fade: {
start: 0,
end: 0.6,
duration: 1000
}
});
// Touch/mouse handling
var lastTapTime = 0;
game.down = function (x, y, obj) {
if (!gameActive) {
return;
}
var currentTime = Date.now();
if (currentTime - lastTapTime < 300) {
// Double-tap detected within 300ms
player.speed = 20; // Resume player movement
}
lastTapTime = currentTime;
if (gameActive) {
player.shoot(); // Shoot when tapping
}
};
game.move = function (x, y, obj) {
if (!gameActive || !player.visible) {
return;
}
// Constrain player to game area
if (x > 100 && x < 2048 - 100) {
player.x = x;
}
if (y > 100 && y < 2732 - 100) {
player.y = y;
}
};
game.up = function (x, y, obj) {
dragActive = false;
};
// Spawn enemies for current wave
function spawnWave() {
if (waveNumber > 100) {
gameActive = false;
updateHighScore();
LK.showYouWin();
return;
}
enemiesInWave = 3 + waveNumber; // Further reduce the number of enemies per wave for less frequent enemy appearances
waveTxt.setText('WAVE ' + waveNumber);
// Show wave notification
waveTxt.alpha = 1;
tween(waveTxt, {
alpha: 0
}, {
duration: 2000,
easing: tween.easeOut
});
// Slightly increase enemy spawn rate with each wave
enemySpawnRate = Math.max(1000, 1500 - waveNumber * 50);
}
// Spawn a single enemy
function spawnEnemy() {
var enemy = new Enemy();
enemy.x = Math.random() * (2048 - 200) + 100; // Random position between 100 and (2048-100)
enemy.y = -100; // Start above the screen
enemy.updateHealthBar();
// Increase enemy health every few waves
if (waveNumber > 3) {
enemy.health += Math.floor(waveNumber / 3);
enemy.updateHealthBar();
}
// Increase enemy speed slightly with each wave
enemy.speed += waveNumber * 0.1;
game.addChild(enemy);
enemies.push(enemy);
enemiesInWave--; // Decrease the count of enemies to spawn in the current wave
// Trigger automatic bullet release when an enemy appears
player.shoot();
}
// Save the high score if needed
function updateHighScore() {
var currentScore = LK.getScore();
if (currentScore > storage.highScore) {
storage.highScore = currentScore;
}
}
// Main game update loop
game.update = function () {
if (!gameActive) {
return;
}
// Enemy spawning logic
var now = Date.now();
if (enemies.length < enemiesInWave && now - lastEnemySpawn > enemySpawnRate) {
lastEnemySpawn = now;
spawnEnemy();
}
// Wave transition logic
if (enemies.length === 0 && enemiesInWave <= 0) {
waveNumber++;
if (waveNumber <= 100) {
// Start next wave after delay
LK.setTimeout(function () {
spawnWave();
}, waveDelay);
enemiesInWave = 5 + waveNumber * 2; // Reset for next wave
} else {
gameActive = false;
updateHighScore();
LK.showYouWin();
}
}
// Bullet collision detection
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Check collision with each enemy
for (var j = enemies.length - 1; j >= 0; j--) {
var enemy = enemies[j];
if (bullet.intersects(enemy)) {
// Damage enemy
enemy.damage(bullet.damage);
// Remove bullet
bullet.destroy();
bullets.splice(i, 1);
// If enemy is destroyed, remove from array
if (enemy.health <= 0) {
enemies.splice(j, 1);
enemiesInWave--;
}
break; // This bullet hit something, stop checking
}
}
}
// Enemy bullet collision with player
if (player.visible) {
for (var i = enemyBullets.length - 1; i >= 0; i--) {
var bullet = enemyBullets[i];
if (bullet.intersects(player)) {
// Damage player
player.damage(bullet.damage);
// Remove bullet
bullet.destroy();
enemyBullets.splice(i, 1);
// Check if game over
if (player.health <= 0) {
gameActive = false;
updateHighScore();
}
}
// Check collision with player bullets
for (var j = bullets.length - 1; j >= 0; j--) {
var playerBullet = bullets[j];
if (bullet.intersects(playerBullet)) {
// Create explosion at the collision point
var explosion = new Explosion();
explosion.x = bullet.x;
explosion.y = bullet.y;
game.addChild(explosion);
// Destroy both bullets
bullet.destroy();
enemyBullets.splice(i, 1);
playerBullet.destroy();
bullets.splice(j, 1);
// Display score bar
var scoreBar = new Text2('Score: ' + LK.getScore(), {
size: 50,
fill: 0xFFFFFF
});
scoreBar.anchor.set(0.5, 0);
scoreBar.x = 2048 / 2;
scoreBar.y = 100;
game.addChild(scoreBar);
LK.setTimeout(function () {
scoreBar.destroy();
}, 2000); // Display for 2 seconds
break; // Stop checking this bullet
}
}
}
// Enemy collision with player
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
if (enemy.intersects(player)) {
// Damage player
player.damage(1);
// Damage enemy
enemy.damage(1);
// If enemy is destroyed, remove from array
if (enemy.health <= 0) {
enemies.splice(i, 1);
enemiesInWave--;
}
// Check if game over
if (player.health <= 0) {
gameActive = false;
updateHighScore();
}
}
}
}
// Clean up arrays (remove destroyed objects)
bullets = bullets.filter(function (bullet) {
return bullet.parent !== null;
});
enemyBullets = enemyBullets.filter(function (bullet) {
return bullet.parent !== null;
});
enemies = enemies.filter(function (enemy) {
return enemy.parent !== null;
});
powerUps = powerUps.filter(function (powerUp) {
return powerUp.parent !== null;
});
};
// Start the first wave
spawnWave();
8 bit image city of newyork with black sky night. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
8 bit image black rocket with fire tail. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
8 bit front image blue red scifi police drone. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
fire explode with piece of black steel. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
fire ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows