User prompt
Do not dim selected defensive ships as much āŖš” Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the red collision flash much dimmer āŖš” Consider importing and using the following plugins: @upit/tween.v1
User prompt
Spawn ALL DEFENSIVE SHIPS in THE TOP RIGHT CORNER in ONE SPOT STACKED ON TOP OF EACH OTHER and ENSURE that they spawn EVERY 50 POINTS. āŖš” Consider importing and using the following plugins: @upit/tween.v1
User prompt
Spawn available defensive ships in only one spot. Place multiple on top of each other if necessary. āŖš” Consider importing and using the following plugins: @upit/tween.v1
User prompt
Spawn available asteroids in only one spot. Place multiple on top of each other if necessary.
User prompt
Ensure that available defensive ships do not go off-screen. If they do, move over so they are fully visible in the top right corner. āŖš” Consider importing and using the following plugins: @upit/tween.v1
User prompt
When an available defensive ship is moved, shift over other defensive ships so the next one is where the first previously was āŖš” Consider importing and using the following plugins: @upit/tween.v1
User prompt
Allow defensive ships to stay selected and fire an infinite number of times āŖš” Consider importing and using the following plugins: @upit/tween.v1
User prompt
Rotate ships along their centers, not at the top point āŖš” Consider importing and using the following plugins: @upit/tween.v1
User prompt
When one ship is selected to fire lasers, all ships are selected. All present ships fire lasers at the selected point. āŖš” Consider importing and using the following plugins: @upit/tween.v1
User prompt
When a point in the solar system is selected for lasers to fire at, rotate the defensive ships so the top faces that point āŖš” Consider importing and using the following plugins: @upit/tween.v1
User prompt
Increase size of defensive ships
User prompt
Add another ship every time score increases by 50 instead of 100
User prompt
Do not shrink defensive ship assets when moveing
User prompt
Remove explosion sound
User prompt
Give defensive ships a cooldown of half a second between lasers āŖš” Consider importing and using the following plugins: @upit/tween.v1
User prompt
Only have to select the defensive ships once to move it
User prompt
Do not move the defensive ships automatically when selected to be moved
User prompt
Put the available defensive ships in the top right corner
User prompt
Each asteroid counts as 5 points
User prompt
Start with one ship, but every time the score goes up by 100 add another available ship
User prompt
Center the score and lives displays so each end of the text is equidistant from the center of the screen
User prompt
Move the four available defensive ships so that they are centered below the score and lives displays
User prompt
Correction: center the four available defensive ships right below the score and lives display
User prompt
Center the four available ships.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Asteroid = Container.expand(function () { var self = Container.call(this); var asteroidGraphics = self.attachAsset('asteroid', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.targetPlanet = null; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; asteroidGraphics.rotation += 0.05; }; return self; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; }; return self; }); var Laser = Container.expand(function () { var self = Container.call(this); var laserGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); laserGraphics.tint = 0x00ff00; // Green laser color laserGraphics.scaleX = 0.5; // Make laser thinner laserGraphics.scaleY = 2; // Make laser longer self.velocityX = 0; self.velocityY = 0; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; }; return self; }); var Planet = Container.expand(function (size, color, orbitRadius, orbitSpeed) { var self = Container.call(this); self.orbitRadius = orbitRadius; self.orbitSpeed = orbitSpeed; self.angle = Math.random() * Math.PI * 2; var assetName = 'mercury'; if (color === 0x4169e1) assetName = 'earth';else if (color === 0xff4500) assetName = 'mars';else if (color === 0xffc649) assetName = 'venus';else if (color === 0xd2691e) assetName = 'jupiter';else if (color === 0xffd700) assetName = 'saturn';else if (color === 0x40e0d0) assetName = 'uranus';else if (color === 0x4169e1 && size === 85) assetName = 'neptune'; var planetGraphics = self.attachAsset(assetName, { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.angle += self.orbitSpeed; self.x = sunX + Math.cos(self.angle) * self.orbitRadius; self.y = sunY + Math.sin(self.angle) * self.orbitRadius; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000011 }); /**** * Game Code ****/ var sunX = 2048 / 2; var sunY = 2732 / 2; var sun = game.addChild(LK.getAsset('sun', { anchorX: 0.5, anchorY: 0.5, x: sunX, y: sunY })); var planets = []; var mercury = new Planet(50, 0x8c7853, 150, 0.015); var venus = new Planet(70, 0xffc649, 200, 0.012); var earth = new Planet(80, 0x4169e1, 300, 0.008); var mars = new Planet(60, 0xff4500, 450, 0.005); var jupiter = new Planet(120, 0xd2691e, 600, 0.003); var saturn = new Planet(100, 0xffd700, 750, 0.002); var uranus = new Planet(90, 0x40e0d0, 900, 0.0015); var neptune = new Planet(85, 0x4169e1, 1050, 0.001); planets.push(mercury); planets.push(venus); planets.push(earth); planets.push(mars); planets.push(jupiter); planets.push(saturn); planets.push(uranus); planets.push(neptune); for (var i = 0; i < planets.length; i++) { game.addChild(planets[i]); } var bullets = []; var lasers = []; var asteroids = []; var asteroidSpawnTimer = 0; var lives = 4; var scoreTxt = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); scoreTxt.x = 0; LK.gui.top.addChild(scoreTxt); var livesTxt = new Text2('Lives: 4', { size: 60, fill: 0xFFFFFF }); livesTxt.anchor.set(0.5, 0); livesTxt.x = 0; livesTxt.y = 70; LK.gui.top.addChild(livesTxt); var defensiveShips = []; var selectedShipIndex = -1; var isDragging = false; var totalShips = 4; // Maximum number of ships var availableShips = 1; // Start with 1 ship available var lastScoreCheck = 0; // Track score for adding new ships // Create 4 defensive ships but only show the available ones for (var i = 0; i < totalShips; i++) { var defensiveShip = LK.getAsset('defensiveShip', { anchorX: 0.5, anchorY: 0.5, x: -80, // Position all ships in the same spot in top right corner y: 80 }); defensiveShip.shipIndex = i; defensiveShip.placed = false; defensiveShip.selected = false; // Only show ships that are available defensiveShip.visible = i < availableShips; defensiveShips.push(defensiveShip); LK.gui.topRight.addChild(defensiveShip); } // Add down handler to each defensive ship for (var i = 0; i < defensiveShips.length; i++) { defensiveShips[i].down = function (x, y, obj) { var ship = this; var shipIndex = ship.shipIndex; // Only allow interaction with visible/available ships if (!ship.visible) { return; } if (ship.placed) { // Ship has been placed, allow selection for shooting // Deselect all other ships for (var j = 0; j < defensiveShips.length; j++) { if (j !== shipIndex && defensiveShips[j].selected) { defensiveShips[j].selected = false; tween(defensiveShips[j], { alpha: 1.0 }, { duration: 200 }); } } if (!ship.selected) { ship.selected = true; selectedShipIndex = shipIndex; tween(ship, { alpha: 0.7 }, { duration: 200 }); } else { ship.selected = false; selectedShipIndex = -1; tween(ship, { alpha: 1.0 }, { duration: 200 }); } return; } // Ship not placed yet - immediately start dragging // Deselect all other ships for (var j = 0; j < defensiveShips.length; j++) { if (j !== shipIndex && defensiveShips[j].selected) { defensiveShips[j].selected = false; tween(defensiveShips[j], { alpha: 1.0 }, { duration: 200 }); } } // Start dragging immediately isDragging = true; selectedShipIndex = shipIndex; ship.selected = true; // Store original scale before moving var originalScaleX = ship.scaleX; var originalScaleY = ship.scaleY; // No need to shift ships since they're all in the same position // Move defensive ship to game area for dragging var gamePos = game.toLocal(LK.gui.topRight.toGlobal({ x: ship.x, y: ship.y })); LK.gui.topRight.removeChild(ship); game.addChild(ship); ship.x = gamePos.x; ship.y = gamePos.y; // Restore original scale after moving to game area ship.scaleX = originalScaleX; ship.scaleY = originalScaleY; }; } game.move = function (x, y, obj) { // Move ship to cursor position during dragging if (isDragging && selectedShipIndex >= 0) { var ship = defensiveShips[selectedShipIndex]; ship.x = x; ship.y = y; } }; game.down = function (x, y, obj) { // If a defensive ship is selected and placed, shoot laser at clicked position if (selectedShipIndex >= 0 && defensiveShips[selectedShipIndex].placed && defensiveShips[selectedShipIndex].selected) { // Make all placed ships fire lasers at the selected point for (var k = 0; k < defensiveShips.length; k++) { var ship = defensiveShips[k]; // Only fire from ships that are placed if (!ship.placed) { continue; } var laser = new Laser(); laser.x = ship.x; laser.y = ship.y; // Calculate direction from this ship to clicked position var dx = x - laser.x; var dy = y - laser.y; var distance = Math.sqrt(dx * dx + dy * dy); // Calculate rotation angle to face the target point var targetRotation = Math.atan2(dy, dx) + Math.PI / 2; // Add PI/2 since ship top should face target // Rotate the ship to face the target tween(ship, { rotation: targetRotation }, { duration: 200, easing: tween.easeOut }); var speed = 8; if (distance > 0) { laser.velocityX = dx / distance * speed; laser.velocityY = dy / distance * speed; } lasers.push(laser); game.addChild(laser); } } }; game.up = function (x, y, obj) { if (isDragging && selectedShipIndex >= 0) { isDragging = false; // Defensive ship is now placed in the solar system var placedShip = defensiveShips[selectedShipIndex]; // Check if ship is off-screen and needs to be moved back to available ships area var shipHalfWidth = 40; // Half width of defensive ship (80/2) var shipHalfHeight = 55; // Half height of defensive ship (110/2) var isOffScreen = placedShip.x - shipHalfWidth < 0 || placedShip.x + shipHalfWidth > 2048 || placedShip.y - shipHalfHeight < 0 || placedShip.y + shipHalfHeight > 2732; if (isOffScreen) { // Move ship back to available ships area game.removeChild(placedShip); LK.gui.topRight.addChild(placedShip); // Place ship back at the single spawn position in top right corner placedShip.x = -80; placedShip.y = 80; placedShip.placed = false; } else { placedShip.placed = true; } placedShip.selected = false; selectedShipIndex = -1; tween(placedShip, { alpha: 1.0 }, { duration: 200 }); } }; game.update = function () { // Check if we should add a new ship (every 50 points) var currentScore = LK.getScore(); var newAvailableShips = Math.min(totalShips, 1 + Math.floor(currentScore / 50)); if (newAvailableShips > availableShips) { availableShips = newAvailableShips; // Make the newly available ship visible for (var k = 0; k < availableShips; k++) { if (!defensiveShips[k].visible) { defensiveShips[k].visible = true; } } } for (var i = 0; i < planets.length; i++) { planets[i].update(); } asteroidSpawnTimer++; // Calculate spawn frequency based on score - starts at 120 ticks, decreases to minimum of 30 ticks var baseSpawnDelay = 120; var minSpawnDelay = 30; var scoreSpeedUp = Math.floor(LK.getScore() / 100); // Every 100 points reduces delay var currentSpawnDelay = Math.max(minSpawnDelay, baseSpawnDelay - scoreSpeedUp * 10); if (asteroidSpawnTimer > currentSpawnDelay) { var asteroid = new Asteroid(); var spawnAngle = Math.random() * Math.PI * 2; var spawnDistance = 1500; asteroid.x = sunX + Math.cos(spawnAngle) * spawnDistance; asteroid.y = sunY + Math.sin(spawnAngle) * spawnDistance; // Set initial velocity toward Earth's current position var dx = earth.x - asteroid.x; var dy = earth.y - asteroid.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { asteroid.velocityX = dx / distance * 2; asteroid.velocityY = dy / distance * 2; } asteroids.push(asteroid); game.addChild(asteroid); asteroidSpawnTimer = 0; } for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; if (bullet.x < -50 || bullet.x > 2098 || bullet.y < -50 || bullet.y > 2782) { bullet.destroy(); bullets.splice(i, 1); continue; } for (var j = asteroids.length - 1; j >= 0; j--) { if (bullet.intersects(asteroids[j])) { LK.setScore(LK.getScore() + 5); scoreTxt.setText('Score: ' + LK.getScore()); bullet.destroy(); bullets.splice(i, 1); asteroids[j].destroy(); asteroids.splice(j, 1); break; } } } // Update lasers for (var i = lasers.length - 1; i >= 0; i--) { var laser = lasers[i]; laser.update(); if (laser.x < -50 || laser.x > 2098 || laser.y < -50 || laser.y > 2782) { laser.destroy(); lasers.splice(i, 1); continue; } // Check laser collision with asteroids for (var j = asteroids.length - 1; j >= 0; j--) { if (laser.intersects(asteroids[j])) { LK.setScore(LK.getScore() + 5); scoreTxt.setText('Score: ' + LK.getScore()); laser.destroy(); lasers.splice(i, 1); asteroids[j].destroy(); asteroids.splice(j, 1); break; } } } for (var i = asteroids.length - 1; i >= 0; i--) { var asteroid = asteroids[i]; for (var j = 0; j < planets.length; j++) { if (asteroid.intersects(planets[j])) { if (planets[j] === earth) { LK.effects.flashScreen(0x440000, 1000); lives--; livesTxt.setText('Lives: ' + lives); if (lives <= 0) { LK.showGameOver(); return; } } asteroid.destroy(); asteroids.splice(i, 1); break; } } var distanceFromSun = Math.sqrt(Math.pow(asteroid.x - sunX, 2) + Math.pow(asteroid.y - sunY, 2)); if (distanceFromSun < 120) { asteroid.destroy(); asteroids.splice(i, 1); } } };
===================================================================
--- original.js
+++ change.js
@@ -178,9 +178,9 @@
if (!ship.selected) {
ship.selected = true;
selectedShipIndex = shipIndex;
tween(ship, {
- alpha: 0.5
+ alpha: 0.7
}, {
duration: 200
});
} else {