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 = 15; self.damage = 1; self.update = function () { 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 = 2; self.speed = 2 + Math.random() * 2; self.value = 100; // score value self.canShoot = Math.random() < 0.5; // 50% 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); // Chance to drop power-up if (Math.random() < 0.15) { // 15% chance var powerUp = new PowerUp(); powerUp.x = self.x; powerUp.y = self.y; game.addChild(powerUp); powerUps.push(powerUp); } // Add score LK.setScore(LK.getScore() + self.value); // Remove from array and destroy self.destroy(); } }; self.shoot = function () { var bullet = new EnemyBullet(); bullet.x = self.x; bullet.y = self.y + 50; game.addChild(bullet); // Add to game's enemyBullets array enemyBullets.push(bullet); LK.getSound('enemyShoot').play(); }; self.update = function () { self.y += self.speed; // Move slightly left or right if (LK.ticks % 60 === 0) { self.x += (Math.random() - 0.5) * 100; // Keep within bounds if (self.x < 100) { self.x = 100; } if (self.x > 2048 - 100) { self.x = 2048 - 100; } } // 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(); } }; 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 = 8; self.damage = 1; 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 = 400; // ms between shots self.lastShot = 0; self.speed = 10; 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; var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y - 50; game.addChild(bullet); // Add to game's bullets array bullets.push(bullet); LK.getSound('playerShoot').play(); }; self.down = function (x, y, obj) { self.shoot(); }; return self; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerUpGraphics = self.attachAsset('powerUp', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.type = Math.floor(Math.random() * 2); // 0: health, 1: faster shooting // Modify appearance based on type if (self.type === 0) { powerUpGraphics.tint = 0x32cd32; // green for health } else { powerUpGraphics.tint = 0x4169e1; // blue for fire rate } self.update = function () { self.y += self.speed; // Remove if off screen if (self.y > 2732 + 50) { self.destroy(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000033 }); /**** * Game Code ****/ // Game variables var player; var bullets = []; var enemyBullets = []; var enemies = []; var powerUps = []; var waveNumber = 1; var enemiesInWave = 5; var lastEnemySpawn = 0; var enemySpawnRate = 1500; // 1.5 seconds between spawns var waveDelay = 5000; // 5 seconds between waves var gameActive = true; var dragActive = false; // Setup GUI var scoreTxt = new Text2('0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(1, 0); // Right-aligned LK.gui.topRight.addChild(scoreTxt); scoreTxt.x = -50; // Add some padding from the right scoreTxt.y = 50; // Add some padding from the top 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 game.down = function (x, y, obj) { if (!gameActive) { return; } dragActive = true; // Move player to touch position if not pressing directly on player if (!player.visible) { return; } if (x < 200 || x > 2048 - 200) { // If touching near the edge, just shoot player.shoot(); } else { // Otherwise move and shoot player.x = x; player.shoot(); } }; game.move = function (x, y, obj) { if (!gameActive || !dragActive || !player.visible) { return; } // Constrain player to game area if (x > 100 && x < 2048 - 100) { player.x = x; } }; game.up = function (x, y, obj) { dragActive = false; }; // Spawn enemies for current wave function spawnWave() { enemiesInWave = 5 + waveNumber * 2; // More enemies per wave 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); } // 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; } // Update score display scoreTxt.setText(LK.getScore()); // 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++; // Start next wave after delay LK.setTimeout(function () { spawnWave(); }, waveDelay); enemiesInWave = 5 + waveNumber * 2; // Reset for next wave } // 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(); } } } // 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(); } } } // Power-up collision with player for (var i = powerUps.length - 1; i >= 0; i--) { var powerUp = powerUps[i]; if (powerUp.intersects(player)) { // Apply power-up effect if (powerUp.type === 0) { // Health power-up player.health = Math.min(player.maxHealth, player.health + 1); player.updateHealthBar(); } else { // Fire rate power-up player.fireRate = Math.max(200, player.fireRate - 50); // Temporarily change player color to show power-up player.tint = 0x4169e1; LK.setTimeout(function () { player.tint = 0xffffff; }, 2000); } // Play power-up sound LK.getSound('powerUp').play(); // Remove power-up powerUp.destroy(); powerUps.splice(i, 1); } } } // 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; }); // Automatic fire if holding if (dragActive && player.visible && LK.ticks % 15 === 0) { player.shoot(); } }; // Start the first wave spawnWave();
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,503 @@
-/****
+/****
+* 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 = 15;
+ self.damage = 1;
+ self.update = function () {
+ 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 = 2;
+ self.speed = 2 + Math.random() * 2;
+ self.value = 100; // score value
+ self.canShoot = Math.random() < 0.5; // 50% 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);
+ // Chance to drop power-up
+ if (Math.random() < 0.15) {
+ // 15% chance
+ var powerUp = new PowerUp();
+ powerUp.x = self.x;
+ powerUp.y = self.y;
+ game.addChild(powerUp);
+ powerUps.push(powerUp);
+ }
+ // Add score
+ LK.setScore(LK.getScore() + self.value);
+ // Remove from array and destroy
+ self.destroy();
+ }
+ };
+ self.shoot = function () {
+ var bullet = new EnemyBullet();
+ bullet.x = self.x;
+ bullet.y = self.y + 50;
+ game.addChild(bullet);
+ // Add to game's enemyBullets array
+ enemyBullets.push(bullet);
+ LK.getSound('enemyShoot').play();
+ };
+ self.update = function () {
+ self.y += self.speed;
+ // Move slightly left or right
+ if (LK.ticks % 60 === 0) {
+ self.x += (Math.random() - 0.5) * 100;
+ // Keep within bounds
+ if (self.x < 100) {
+ self.x = 100;
+ }
+ if (self.x > 2048 - 100) {
+ self.x = 2048 - 100;
+ }
+ }
+ // 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();
+ }
+ };
+ 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 = 8;
+ self.damage = 1;
+ 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 = 400; // ms between shots
+ self.lastShot = 0;
+ self.speed = 10;
+ 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;
+ var bullet = new Bullet();
+ bullet.x = self.x;
+ bullet.y = self.y - 50;
+ game.addChild(bullet);
+ // Add to game's bullets array
+ bullets.push(bullet);
+ LK.getSound('playerShoot').play();
+ };
+ self.down = function (x, y, obj) {
+ self.shoot();
+ };
+ return self;
+});
+var PowerUp = Container.expand(function () {
+ var self = Container.call(this);
+ var powerUpGraphics = self.attachAsset('powerUp', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 3;
+ self.type = Math.floor(Math.random() * 2); // 0: health, 1: faster shooting
+ // Modify appearance based on type
+ if (self.type === 0) {
+ powerUpGraphics.tint = 0x32cd32; // green for health
+ } else {
+ powerUpGraphics.tint = 0x4169e1; // blue for fire rate
+ }
+ self.update = function () {
+ self.y += self.speed;
+ // Remove if off screen
+ if (self.y > 2732 + 50) {
+ self.destroy();
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x000033
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var player;
+var bullets = [];
+var enemyBullets = [];
+var enemies = [];
+var powerUps = [];
+var waveNumber = 1;
+var enemiesInWave = 5;
+var lastEnemySpawn = 0;
+var enemySpawnRate = 1500; // 1.5 seconds between spawns
+var waveDelay = 5000; // 5 seconds between waves
+var gameActive = true;
+var dragActive = false;
+// Setup GUI
+var scoreTxt = new Text2('0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(1, 0); // Right-aligned
+LK.gui.topRight.addChild(scoreTxt);
+scoreTxt.x = -50; // Add some padding from the right
+scoreTxt.y = 50; // Add some padding from the top
+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
+game.down = function (x, y, obj) {
+ if (!gameActive) {
+ return;
+ }
+ dragActive = true;
+ // Move player to touch position if not pressing directly on player
+ if (!player.visible) {
+ return;
+ }
+ if (x < 200 || x > 2048 - 200) {
+ // If touching near the edge, just shoot
+ player.shoot();
+ } else {
+ // Otherwise move and shoot
+ player.x = x;
+ player.shoot();
+ }
+};
+game.move = function (x, y, obj) {
+ if (!gameActive || !dragActive || !player.visible) {
+ return;
+ }
+ // Constrain player to game area
+ if (x > 100 && x < 2048 - 100) {
+ player.x = x;
+ }
+};
+game.up = function (x, y, obj) {
+ dragActive = false;
+};
+// Spawn enemies for current wave
+function spawnWave() {
+ enemiesInWave = 5 + waveNumber * 2; // More enemies per wave
+ 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);
+}
+// 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;
+ }
+ // Update score display
+ scoreTxt.setText(LK.getScore());
+ // 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++;
+ // Start next wave after delay
+ LK.setTimeout(function () {
+ spawnWave();
+ }, waveDelay);
+ enemiesInWave = 5 + waveNumber * 2; // Reset for next wave
+ }
+ // 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();
+ }
+ }
+ }
+ // 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();
+ }
+ }
+ }
+ // Power-up collision with player
+ for (var i = powerUps.length - 1; i >= 0; i--) {
+ var powerUp = powerUps[i];
+ if (powerUp.intersects(player)) {
+ // Apply power-up effect
+ if (powerUp.type === 0) {
+ // Health power-up
+ player.health = Math.min(player.maxHealth, player.health + 1);
+ player.updateHealthBar();
+ } else {
+ // Fire rate power-up
+ player.fireRate = Math.max(200, player.fireRate - 50);
+ // Temporarily change player color to show power-up
+ player.tint = 0x4169e1;
+ LK.setTimeout(function () {
+ player.tint = 0xffffff;
+ }, 2000);
+ }
+ // Play power-up sound
+ LK.getSound('powerUp').play();
+ // Remove power-up
+ powerUp.destroy();
+ powerUps.splice(i, 1);
+ }
+ }
+ }
+ // 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;
+ });
+ // Automatic fire if holding
+ if (dragActive && player.visible && LK.ticks % 15 === 0) {
+ player.shoot();
+ }
+};
+// Start the first wave
+spawnWave();
\ No newline at end of file
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