User prompt
Move crystal icon and score 100px down
User prompt
Move crystal icon and score 50px down
User prompt
Move crystal icon and score 20px down
User prompt
Keep the crystal icon and score on the left
User prompt
Keep the crystal icon and score in the left corner
User prompt
Crystal score should be in the upper left corner
User prompt
Let it be with the crystal ico in the upper left corner
User prompt
Let's remove the score and let the crystal count be in the upper left corner
User prompt
wave increase after every 30 crystals
User prompt
When you get a bonus box, the shot will be doubled.
User prompt
Every time you get a bonus, the shot is doubled for 5 seconds and the counter is written to the left and center.
User prompt
Increase your firing speed by 1.5 each time a wave increases.
User prompt
Increase your firing speed by 2 each time a wave increases.
User prompt
Change background color every 100 crystals
User prompt
The game should end when the alien passes, fix that
User prompt
fix player taking damage
User prompt
Don't let the aliens follow the boss
User prompt
remove boss from game
User prompt
Don't come with the alien boss
User prompt
Remove the aliens come after the boss code
User prompt
Remove the aliens come after the boss code
User prompt
remove aliens come after the garden code
User prompt
remove aliens come after the garden code
User prompt
remove the aliens do not come to bosun code
User prompt
fix bugs in the game,
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Alien class var Alien = Container.expand(function () { var self = Container.call(this); var sprite = self.attachAsset('alien', { anchorX: 0.5, anchorY: 0.5 }); self.width = sprite.width; self.height = sprite.height; self.speed = 2.5; self.hp = 1; self.isDead = false; self.wave = 1; self.update = function () { // Move downwards if (!self.isDead) { if (typeof self.lastY === "undefined") self.lastY = self.y; self.y += self.speed; self.lastY = self.y; } }; return self; }); // BonusBox class var BonusBox = Container.expand(function () { var self = Container.call(this); var sprite = self.attachAsset('bonus', { anchorX: 0.5, anchorY: 0.5 }); self.width = sprite.width; self.height = sprite.height; self.type = null; // rapid, pierce, shield // No movement logic here; handled in game.update return self; }); // Boss class var Boss = Container.expand(function () { var self = Container.call(this); // Use the alien asset for the boss, but scale up and tint for distinction var sprite = self.attachAsset('alien', { anchorX: 0.5, anchorY: 0.5 }); sprite.scaleX = 2.2; sprite.scaleY = 2.2; sprite.tint = 0xff4444; self.width = sprite.width * sprite.scaleX; self.height = sprite.height * sprite.scaleY; self.speed = 2.2; self.hp = 20; self.isDead = false; self.wave = 1; self.update = function () { if (!self.isDead) { if (typeof self.lastY === "undefined") self.lastY = self.y; self.y += self.speed; self.lastY = self.y; // Boss follower logic removed: no aliens will follow the boss } }; return self; }); // Crystal class var Crystal = Container.expand(function () { var self = Container.call(this); var sprite = self.attachAsset('crystal', { anchorX: 0.5, anchorY: 0.5 }); self.width = sprite.width; self.height = sprite.height; // Crystals are static, but you could add animation or effects here if needed return self; }); // Laser class var Laser = Container.expand(function () { var self = Container.call(this); var sprite = self.attachAsset('laser', { anchorX: 0.5, anchorY: 0.5 }); self.width = sprite.width; self.height = sprite.height; self.speed = -28; self.pierce = false; self.update = function () { if (typeof self.lastY === "undefined") self.lastY = self.y; self.y += self.speed; self.lastY = self.y; }; return self; }); // Player class var Player = Container.expand(function () { var self = Container.call(this); var sprite = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.width = sprite.width; self.height = sprite.height; self.leftLimit = PLAYER_MIN_X; self.rightLimit = PLAYER_MAX_X; self.shootCooldown = 0; self.powered = false; self.powerType = null; self.powerTimer = 0; self.update = function () { // Powerup timer if (self.powered) { self.powerTimer--; if (self.powerTimer <= 0) { self.powered = false; self.powerType = null; } } }; self.setPower = function (type, duration) { self.powered = true; self.powerType = type; self.powerTimer = duration; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ // No title, no description // Always backgroundColor is black backgroundColor: 0x000000 }); /**** * Game Code ****/ // Music // Sound effects // Bonus box // Crystal (collectible) // Player bullet (laser) // Alien (enemy) // Player // Game constants var GAME_WIDTH = 2048; var GAME_HEIGHT = 2732; var GROUND_Y = GAME_HEIGHT - 220; var PLAYER_START_X = GAME_WIDTH / 2; var PLAYER_START_Y = GROUND_Y; var PLAYER_MIN_X = 160 + 40; var PLAYER_MAX_X = GAME_WIDTH - 160 - 40; var ENEMY_START_X_MIN = 160; var ENEMY_START_X_MAX = GAME_WIDTH - 160; // Define Y spawn range for enemies and bonus boxes var ENEMY_START_Y_MIN = -120; var ENEMY_START_Y_MAX = GAME_HEIGHT / 2; // Define 3 fixed road X positions for aliens to spawn and move along (top to bottom) var ROAD_X_POSITIONS = [ENEMY_START_X_MIN + Math.floor((ENEMY_START_X_MAX - ENEMY_START_X_MIN) * 0.2), ENEMY_START_X_MIN + Math.floor((ENEMY_START_X_MAX - ENEMY_START_X_MIN) * 0.5), ENEMY_START_X_MIN + Math.floor((ENEMY_START_X_MAX - ENEMY_START_X_MIN) * 0.8)]; var LASER_COOLDOWN_BASE = 9; // ticks, slowest (0.15 shots/sec at 60fps) var LASER_COOLDOWN_PER_CRYSTAL = 6; // ticks to reduce per crystal (0.1 shots/sec faster per crystal) var LASER_COOLDOWN_MIN = 5; // ticks, fastest var LASER_COOLDOWN_RAPID = 6; var CRYSTAL_COLLECT_DIST = 120; var BONUS_COLLECT_DIST = 120; var CRYSTAL_MOVE_STEP = 180; // How much movement area expands per crystal var MAX_CRYSTALS = 8; var WAVE_ENEMY_BASE = 10; var WAVE_ENEMY_INC = 5; // Increase by 5 each wave var WAVE_SPEED_INC = 0.4; var WAVE_HP_INC = 1; var BONUS_WAVE_INTERVAL = 3; var POWERUP_DURATION = 360; // 6 seconds at 60fps // Game state var firingSpeed = 2; // Initial firing speed (seconds per shot) var player = null; var aliens = []; var lasers = []; var crystals = []; var bonuses = []; var dragNode = null; var dragOffsetX = 0; var dragOffsetY = 0; var lastMoveX = 0; var lastMoveY = 0; var lastAlienSpawnTick = 0; var wave = 1; var enemiesLeft = 0; var enemiesToSpawn = 0; var enemiesKilled = 0; var crystalsCollected = 0; var leftLimit = PLAYER_MIN_X; var rightLimit = PLAYER_MAX_X; var bonusActive = false; var bonusType = null; var waveTxt = null; var powerupTxt = null; var gameOver = false; var youWin = false; // GUI // Crystal icon and count var crystalIcon = LK.getAsset('crystal', { anchorX: 0, anchorY: 0 }); // Place icon at top left, leaving 10px margin for platform menu crystalIcon.x = 110; crystalIcon.y = 10; crystalIcon.width = 80; crystalIcon.height = 80; LK.gui.topLeft.addChild(crystalIcon); var crystalCountTxt = new Text2('0', { size: 70, fill: 0x00eaff }); crystalCountTxt.anchor.set(0, 0.5); crystalCountTxt.x = crystalIcon.x + crystalIcon.width + 24; crystalCountTxt.y = crystalIcon.y + crystalIcon.height / 2; LK.gui.topLeft.addChild(crystalCountTxt); waveTxt = new Text2('Wave 1', { size: 80, fill: 0xAAFFFF }); waveTxt.anchor.set(0.5, 0); LK.gui.top.addChild(waveTxt); waveTxt.y = 120; powerupTxt = new Text2('', { size: 70, fill: 0xFFE100 }); powerupTxt.anchor.set(0.5, 0); LK.gui.top.addChild(powerupTxt); powerupTxt.y = 220; // Start music LK.playMusic('bgmusic'); // Spawn player player = new Player(); player.x = PLAYER_START_X; player.y = PLAYER_START_Y; game.addChild(player); // Set initial movement limits leftLimit = player.leftLimit; rightLimit = player.rightLimit; // Set initial shoot cooldown so player fires at 0.5s (30 ticks at 60fps) when starting player.shootCooldown = Math.max(2, Math.round(1 / firingSpeed * 60)); // Track last firingSpeed and powerType for cooldown logic player._lastFiringSpeed = firingSpeed; player._lastPowerType = player.powerType; // Start first wave // Add: empty wave logic var isEmptyWave = false; function startWave(waveNum) { wave = waveNum; // Increase player's firing speed by 1.5x each wave (except for first wave) if (wave > 1) { firingSpeed *= 1.5; } // Every 20 enemies, insert an empty wave after a normal wave // We use isEmptyWave to track if the current wave is an empty wave if (!isEmptyWave && (wave - 1) % 2 === 0 && Math.floor((WAVE_ENEMY_BASE + (wave - 1) * WAVE_ENEMY_INC) / 20) > 0) { // After every 20 enemies, insert an empty wave isEmptyWave = true; waveTxt.setText('Wave ' + wave + ' (Rest)'); enemiesToSpawn = 0; enemiesLeft = 0; lastAlienSpawnTick = LK.ticks; return; } isEmptyWave = false; waveTxt.setText('Wave ' + wave); // Boss logic: spawn boss before normal enemies, except for first wave if (wave > 1) { // Only one boss at a time: check if a boss already exists in aliens array var bossExists = false; for (var i = 0; i < aliens.length; i++) { if (aliens[i] instanceof Boss) { bossExists = true; break; } } if (!bossExists) { var boss = new Boss(); // Pick a random road for the boss to spawn on (X position) var roadIdx = randInt(0, ROAD_X_POSITIONS.length - 1); boss.x = ROAD_X_POSITIONS[roadIdx]; boss.y = -boss.height / 2; boss.wave = wave; boss.speed = 2.2 + (wave - 2) * 0.25; boss.hp = 12 + (wave - 2) * 6; aliens.push(boss); game.addChild(boss); enemiesToSpawn = 0; // Don't spawn normal enemies until boss is defeated enemiesLeft = 1; lastAlienSpawnTick = LK.ticks; } return; } enemiesToSpawn = WAVE_ENEMY_BASE + (wave - 1) * WAVE_ENEMY_INC; enemiesLeft = enemiesToSpawn; lastAlienSpawnTick = LK.ticks; } startWave(1); // Utility: clamp function clamp(val, min, max) { if (val < min) return min; if (val > max) return max; return val; } // Utility: random int function randInt(min, max) { return min + Math.floor(Math.random() * (max - min + 1)); } // Utility: random powerup function randomPowerup() { var arr = ['rapid', 'pierce', 'shield']; return arr[randInt(0, arr.length - 1)]; } // Handle movement (dragging) function handleMove(x, y, obj) { if (dragNode === player) { // Clamp to current movement limits var newX = clamp(x, leftLimit, rightLimit); player.x = newX; lastMoveX = newX; lastMoveY = player.y; } } game.move = handleMove; game.down = function (x, y, obj) { // Only allow drag if touch/click is on player or below if (y > GROUND_Y - 200) { dragNode = player; handleMove(x, y, obj); } }; game.up = function (x, y, obj) { dragNode = null; }; // Main game update game.update = function () { if (gameOver || youWin) return; // Player update (powerup timer) player.update(); // Aliens update for (var i = aliens.length - 1; i >= 0; i--) { var alien = aliens[i]; alien.update(); // End the game if a non-boss alien passes the bottom of the screen if (alien.y > GAME_HEIGHT + alien.height / 2 && !(alien instanceof Boss)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); gameOver = true; return; } // Remove boss followers if they go off screen or are dead if (alien.y > GAME_HEIGHT + alien.height / 2 || alien.isDead) { // Remove from aliens array and destroy aliens.splice(i, 1); alien.destroy(); continue; } // Only check for alien-boss collision if boss is alive // Check collision with player (if shielded, destroy alien) if (player.powered && player.powerType === 'shield' && alien.intersects(player)) { LK.getSound('alien_die').play(); LK.effects.flashObject(alien, 0x00eaff, 400); alien.isDead = true; aliens.splice(i, 1); alien.destroy(); continue; } // If not shielded, player dies if touched by an alien (but not the boss) // Only trigger on the exact frame of collision (not every frame while overlapping) if (typeof alien.lastWasIntersecting === "undefined") alien.lastWasIntersecting = false; var nowIntersecting = alien.intersects(player); if ((!player.powered || player.powerType !== 'shield') && !alien.lastWasIntersecting && nowIntersecting && !(alien instanceof Boss)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); gameOver = true; return; } alien.lastWasIntersecting = nowIntersecting; } // Lasers update for (var i = lasers.length - 1; i >= 0; i--) { var laser = lasers[i]; laser.update(); // Remove if off screen if (laser.y < -100) { lasers.splice(i, 1); laser.destroy(); continue; } // Check collision with aliens var hit = false; for (var j = aliens.length - 1; j >= 0; j--) { var alien = aliens[j]; if (!alien.isDead && laser.intersects(alien)) { alien.hp -= player.powered && player.powerType === 'pierce' ? 2 : 1; if (alien.hp <= 0) { // Alien dies LK.getSound('alien_die').play(); LK.effects.flashObject(alien, 0xff0000, 400); alien.isDead = true; // Drop crystal var crystal = new Crystal(); crystal.x = alien.x; crystal.y = alien.y; crystals.push(crystal); game.addChild(crystal); // Remove alien aliens.splice(j, 1); alien.destroy(); enemiesLeft--; enemiesKilled++; // New wave? if (enemiesLeft <= 0) { // If a boss was just defeated, start the normal enemies for this wave var bossPresent = false; for (var k = 0; k < aliens.length; k++) { if (aliens[k] instanceof Boss) { bossPresent = true; break; } } if (bossPresent) { // Wait until boss is gone } else if (enemiesToSpawn === 0 && wave > 1) { // Now spawn the normal enemies for this wave enemiesToSpawn = WAVE_ENEMY_BASE + (wave - 1) * WAVE_ENEMY_INC; enemiesLeft = enemiesToSpawn; lastAlienSpawnTick = LK.ticks; // Bonus box every BONUS_WAVE_INTERVAL if (wave % BONUS_WAVE_INTERVAL === 0) { var bonus = new BonusBox(); bonus.x = randInt(leftLimit + 100, rightLimit - 100); bonus.y = randInt(ENEMY_START_Y_MIN + 100, ENEMY_START_Y_MAX - 100); bonus.type = randomPowerup(); bonuses.push(bonus); game.addChild(bonus); } } else { // End of normal enemies, start next wave (boss will spawn in startWave) // Move on to the next wave when 20 aliens are killed if (enemiesKilled > 0 && enemiesKilled % 20 === 0) { startWave(wave + 1); } else { if (wave % BONUS_WAVE_INTERVAL === 0) { var bonus = new BonusBox(); bonus.x = randInt(leftLimit + 100, rightLimit - 100); bonus.y = randInt(ENEMY_START_Y_MIN + 100, ENEMY_START_Y_MAX - 100); bonus.type = randomPowerup(); bonuses.push(bonus); game.addChild(bonus); } startWave(wave + 1); } } } } hit = true; if (!(player.powered && player.powerType === 'pierce')) break; } } if (hit && !(player.powered && player.powerType === 'pierce')) { lasers.splice(i, 1); laser.destroy(); } } // Crystals update for (var i = crystals.length - 1; i >= 0; i--) { var crystal = crystals[i]; // Move crystal toward player var dx = player.x - crystal.x; var dy = player.y - crystal.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 1) { // Move a fraction toward the player (speed: 14px per frame, capped at distance) var moveDist = Math.min(14, dist); crystal.x += dx / dist * moveDist; crystal.y += dy / dist * moveDist; } if (dist < CRYSTAL_COLLECT_DIST) { LK.getSound('crystal_get').play(); LK.effects.flashObject(crystal, 0x00eaff, 400); crystals.splice(i, 1); crystal.destroy(); // Expand movement area if (crystalsCollected < MAX_CRYSTALS) { leftLimit = Math.max(PLAYER_MIN_X - (crystalsCollected + 1) * CRYSTAL_MOVE_STEP, 80 + player.width / 2); rightLimit = Math.min(PLAYER_MAX_X + (crystalsCollected + 1) * CRYSTAL_MOVE_STEP, GAME_WIDTH - 80 - player.width / 2); } // Always increment crystalsCollected when a crystal is collected crystalsCollected++; crystalCountTxt.setText(crystalsCollected + ""); // Change background color every 100 crystals if (crystalsCollected > 0 && crystalsCollected % 100 === 0) { // Cycle through a set of background colors var bgColors = [0x000000, 0x1a237e, 0x004d40, 0x880e4f, 0xff6f00, 0x263238]; var colorIdx = Math.floor(crystalsCollected / 100) % bgColors.length; game.setBackgroundColor(bgColors[colorIdx]); } // Add: When 20 crystals are collected, increment wave and insert a blank wave if (crystalsCollected > 0 && crystalsCollected % 20 === 0) { // Only trigger once per 20 crystals if (!game._crystalWaveTriggered || game._crystalWaveTriggered !== crystalsCollected) { game._crystalWaveTriggered = crystalsCollected; // Start a new wave and set isEmptyWave to true for a blank wave isEmptyWave = true; startWave(wave + 1); } } } } // If this is an empty wave, and there are no enemies to spawn or kill, start the next wave after a short delay if (typeof isEmptyWave !== "undefined" && isEmptyWave && enemiesToSpawn === 0 && enemiesLeft === 0 && aliens.length === 0) { // Use a static property to avoid multiple triggers if (!game._emptyWaveDelay) { game._emptyWaveDelay = 30; // half a second at 60fps } game._emptyWaveDelay--; if (game._emptyWaveDelay <= 0) { game._emptyWaveDelay = null; startWave(wave + 1); } } // Bonus boxes update for (var i = bonuses.length - 1; i >= 0; i--) { var bonus = bonuses[i]; // Move bonus toward player var dx = player.x - bonus.x; var dy = player.y - bonus.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 1) { // Move a fraction toward the player (speed: 18px per frame, capped at distance) var moveDist = Math.min(18, dist); bonus.x += dx / dist * moveDist; bonus.y += dy / dist * moveDist; } if (dist < BONUS_COLLECT_DIST) { LK.getSound('bonus_get').play(); LK.effects.flashObject(bonus, 0xffe100, 400); bonuses.splice(i, 1); bonus.destroy(); // Grant powerup player.setPower(bonus.type, POWERUP_DURATION); if (bonus.type === 'rapid') { powerupTxt.setText('Rapid Fire!'); } else if (bonus.type === 'pierce') { powerupTxt.setText('Piercing Shots!'); } else if (bonus.type === 'shield') { powerupTxt.setText('Shield!'); } } } // Powerup text timer if (player.powered) { powerupTxt.alpha = 1; } else { if (powerupTxt.alpha > 0) { powerupTxt.alpha -= 0.04; if (powerupTxt.alpha < 0) powerupTxt.alpha = 0; } powerupTxt.setText(''); } // Player auto-fire (continuous fire) // Firing speed is always normal unless rapid powerup is active var cooldown; if (player.powered && player.powerType === 'rapid') { // Rapid fire: halve the firingSpeed (double the rate) cooldown = Math.max(2, Math.round(1 / (firingSpeed * 2) * 60)); } else { // Normal: use firingSpeed cooldown = Math.max(2, Math.round(1 / firingSpeed * 60)); } // If firingSpeed or powerup changes, update shootCooldown to not allow instant fire if (typeof player._lastFiringSpeed === "undefined") player._lastFiringSpeed = firingSpeed; if (typeof player._lastPowerType === "undefined") player._lastPowerType = player.powerType; if (player._lastFiringSpeed !== firingSpeed || player._lastPowerType !== player.powerType) { // Only update shootCooldown if cooldown increased (to prevent rapid fire bug) if (player.shootCooldown > cooldown) { player.shootCooldown = cooldown; } player._lastFiringSpeed = firingSpeed; player._lastPowerType = player.powerType; } if (player.shootCooldown > 0) player.shootCooldown--; // Always fire when cooldown is ready (continuous fire) if (player.shootCooldown <= 0) { // Fire one laser (halve the throw) var laser = new Laser(); laser.x = player.x; laser.y = player.y - player.height / 2 + 10; if (player.powered && player.powerType === 'pierce') { laser.pierce = true; } lasers.push(laser); game.addChild(laser); player.shootCooldown = cooldown; LK.getSound('laser_shoot').play(); } // Spawn aliens for current wave if (enemiesToSpawn > 0 && LK.ticks - lastAlienSpawnTick > 24) { var alien = new Alien(); // Pick a random road for the alien to spawn on (X position) var roadIdx = randInt(0, ROAD_X_POSITIONS.length - 1); alien.x = ROAD_X_POSITIONS[roadIdx]; alien.y = -alien.height / 2; alien.wave = wave; alien.speed = 2.5 + (wave - 1) * WAVE_SPEED_INC; alien.hp = 1 + Math.floor((wave - 1) * WAVE_HP_INC / 2); aliens.push(alien); game.addChild(alien); enemiesToSpawn--; lastAlienSpawnTick = LK.ticks; } };
===================================================================
--- original.js
+++ change.js
@@ -259,11 +259,11 @@
// Add: empty wave logic
var isEmptyWave = false;
function startWave(waveNum) {
wave = waveNum;
- // Double player's firing speed each wave (except for first wave)
+ // Increase player's firing speed by 1.5x each wave (except for first wave)
if (wave > 1) {
- firingSpeed *= 2;
+ firingSpeed *= 1.5;
}
// Every 20 enemies, insert an empty wave after a normal wave
// We use isEmptyWave to track if the current wave is an empty wave
if (!isEmptyWave && (wave - 1) % 2 === 0 && Math.floor((WAVE_ENEMY_BASE + (wave - 1) * WAVE_ENEMY_INC) / 20) > 0) {
A triangular spaceship. In-Game asset. 2d. High contrast. No shadows
alien creature drawing. In-Game asset. 2d. High contrast. No shadows
alien creature drawing. In-Game asset. 2d. High contrast. No shadows
alien creature drawing. In-Game asset. 2d. High contrast. No shadows
alien creature drawing. In-Game asset. 2d. High contrast. No shadows
blue crystal. In-Game asset. 2d. High contrast. No shadows
draw thick long laser bullet. In-Game asset. 2d. High contrast. No shadows
remove bonus text
spaceship. In-Game asset. 2d. High contrast. No shadows