User prompt
Give the larger asteroid a thirty percent spawn rate
User prompt
Make large asteroids take ten hits to destroy
User prompt
Make it so that rarely, large asteroids, which give out a hundred points and an extra life, will spawn, but if they hit you, you lose all of your lives.
User prompt
Make laser fire every .3 seconds
User prompt
Give the player 5 lives
User prompt
Make the Laser fire every 2 seconds
User prompt
Make the asteroids slower and give out 10 points each when destroyed
User prompt
Make the background more space-like
User prompt
Add the ability to go left and right
Code edit (1 edits merged)
Please save this source code
User prompt
Space Dog: Asteroid Blaster
Initial prompt
Make a game where you're a dog in space. Shooting asteroids.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Asteroid var Asteroid = Container.expand(function () { var self = Container.call(this); var asteroid = self.attachAsset('asteroid', { anchorX: 0.5, anchorY: 0.5 }); // Randomize rotation asteroid.rotation = Math.random() * Math.PI * 2; // Speed and direction self.speedY = 7 + Math.random() * 4; // 7-11 px/frame self.speedX = (Math.random() - 0.5) * 4; // -2 to 2 px/frame // For collision self.radius = asteroid.width * 0.5; // For rotation animation self.rotSpeed = (Math.random() - 0.5) * 0.04; // Update method self.update = function () { self.y += self.speedY; self.x += self.speedX; asteroid.rotation += self.rotSpeed; }; return self; }); // Dog Ship (Player) var DogShip = Container.expand(function () { var self = Container.call(this); var ship = self.attachAsset('dogShip', { anchorX: 0.5, anchorY: 0.5 }); // For collision, use the container itself self.radius = ship.width * 0.5; // For drag effect self.isDragging = false; return self; }); // Laser var Laser = Container.expand(function () { var self = Container.call(this); var laser = self.attachAsset('laser', { anchorX: 0.5, anchorY: 0.5 }); self.speedY = -22; // Fast upward // For collision self.radius = laser.width * 0.5; self.update = function () { self.y += self.speedY; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x0a0a1a }); /**** * Game Code ****/ // Play background music // Spaceship (dog ship) // Asteroid // Laser // Sound for shooting // Sound for asteroid destroyed // Music (background) LK.playMusic('spaceMusic'); // Score display var scoreTxt = new Text2('0', { size: 120, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Game variables var dogShip; var asteroids = []; var lasers = []; var dragNode = null; var lastGameOver = false; var asteroidSpawnTick = 0; // Place dog ship at bottom center, above bottom edge dogShip = new DogShip(); game.addChild(dogShip); dogShip.x = 2048 / 2; dogShip.y = 2732 - 320; // Prevent dogShip from going off screen function clampShipPosition() { var margin = dogShip.radius + 30; if (dogShip.x < margin) dogShip.x = margin; if (dogShip.x > 2048 - margin) dogShip.x = 2048 - margin; if (dogShip.y < margin + 120) dogShip.y = margin + 120; // Don't go under score if (dogShip.y > 2732 - margin) dogShip.y = 2732 - margin; } // Touch/mouse drag to move dog ship function handleMove(x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; clampShipPosition(); } } game.move = handleMove; game.down = function (x, y, obj) { // Only start drag if touch is on the ship var dx = x - dogShip.x; var dy = y - dogShip.y; if (dx * dx + dy * dy < dogShip.radius * dogShip.radius) { dragNode = dogShip; handleMove(x, y, obj); } }; game.up = function (x, y, obj) { dragNode = null; }; // Tap anywhere to shoot game.tap = function (x, y, obj) { // Only allow shooting if not game over if (lastGameOver) return; var laser = new Laser(); laser.x = dogShip.x; laser.y = dogShip.y - dogShip.radius - 30; lasers.push(laser); game.addChild(laser); LK.getSound('laserShoot').play(); }; // For mobile, treat down as tap if not dragging game.down = function (x, y, obj) { var dx = x - dogShip.x; var dy = y - dogShip.y; if (dx * dx + dy * dy < dogShip.radius * dogShip.radius) { dragNode = dogShip; handleMove(x, y, obj); } else { // Not on ship: tap left/right to move, tap center to shoot // Define left/right/center regions var leftEdge = 0; var rightEdge = 2048; var centerWidth = 400; var leftRegion = (rightEdge - centerWidth) / 2; var rightRegion = (rightEdge + centerWidth) / 2; if (x < leftRegion) { // Move ship left by a fixed amount dogShip.x -= 220; clampShipPosition(); } else if (x > rightRegion) { // Move ship right by a fixed amount dogShip.x += 220; clampShipPosition(); } else { // Center: shoot game.tap(x, y, obj); } } }; // Asteroid spawn logic function spawnAsteroid() { var asteroid = new Asteroid(); // Spawn at random X, just above top var margin = asteroid.radius + 40; asteroid.x = margin + Math.random() * (2048 - margin * 2); asteroid.y = -asteroid.radius - 40; asteroids.push(asteroid); game.addChild(asteroid); } // Collision detection (circle vs circle) function circlesIntersect(a, b) { var dx = a.x - b.x; var dy = a.y - b.y; var r = a.radius + b.radius - 10; // -10 for some forgiveness return dx * dx + dy * dy < r * r; } // Main game update game.update = function () { // Asteroid spawn rate: every 40-70 ticks, randomize for tension asteroidSpawnTick--; if (asteroidSpawnTick <= 0) { spawnAsteroid(); asteroidSpawnTick = 40 + Math.floor(Math.random() * 30); } // Update asteroids for (var i = asteroids.length - 1; i >= 0; i--) { var a = asteroids[i]; a.update(); // Remove if off screen if (a.y - a.radius > 2732 + 60) { a.destroy(); asteroids.splice(i, 1); continue; } // Check collision with dogShip if (!lastGameOver && circlesIntersect(a, dogShip)) { // Game over lastGameOver = true; LK.effects.flashScreen(0xff0000, 900); tween(dogShip, { alpha: 0.2 }, { duration: 400, easing: tween.easeOut }); LK.showGameOver(); return; } } // Update lasers for (var j = lasers.length - 1; j >= 0; j--) { var l = lasers[j]; l.update(); // Remove if off screen if (l.y + l.radius < -60) { l.destroy(); lasers.splice(j, 1); continue; } // Check collision with asteroids for (var k = asteroids.length - 1; k >= 0; k--) { var a2 = asteroids[k]; if (circlesIntersect(l, a2)) { // Destroy both LK.getSound('asteroidHit').play(); a2.destroy(); asteroids.splice(k, 1); l.destroy(); lasers.splice(j, 1); // Score up LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); // Small asteroid explosion effect LK.effects.flashObject(dogShip, 0x00e0ff, 200); break; } } } }; // Reset state on new game LK.on('gameStart', function () { // Remove all asteroids and lasers for (var i = 0; i < asteroids.length; i++) asteroids[i].destroy(); for (var j = 0; j < lasers.length; j++) lasers[j].destroy(); asteroids = []; lasers = []; // Reset dogShip dogShip.x = 2048 / 2; dogShip.y = 2732 - 320; dogShip.alpha = 1; lastGameOver = false; scoreTxt.setText('0'); LK.setScore(0); asteroidSpawnTick = 30; clampShipPosition(); // Restart music LK.playMusic('spaceMusic'); });
===================================================================
--- original.js
+++ change.js
@@ -68,15 +68,15 @@
/****
* Game Code
****/
-// Music (background)
-// Sound for asteroid destroyed
-// Sound for shooting
-// Laser
-// Asteroid
-// Spaceship (dog ship)
// Play background music
+// Spaceship (dog ship)
+// Asteroid
+// Laser
+// Sound for shooting
+// Sound for asteroid destroyed
+// Music (background)
LK.playMusic('spaceMusic');
// Score display
var scoreTxt = new Text2('0', {
size: 120,
@@ -143,10 +143,27 @@
if (dx * dx + dy * dy < dogShip.radius * dogShip.radius) {
dragNode = dogShip;
handleMove(x, y, obj);
} else {
- // Not on ship, treat as tap to shoot
- game.tap(x, y, obj);
+ // Not on ship: tap left/right to move, tap center to shoot
+ // Define left/right/center regions
+ var leftEdge = 0;
+ var rightEdge = 2048;
+ var centerWidth = 400;
+ var leftRegion = (rightEdge - centerWidth) / 2;
+ var rightRegion = (rightEdge + centerWidth) / 2;
+ if (x < leftRegion) {
+ // Move ship left by a fixed amount
+ dogShip.x -= 220;
+ clampShipPosition();
+ } else if (x > rightRegion) {
+ // Move ship right by a fixed amount
+ dogShip.x += 220;
+ clampShipPosition();
+ } else {
+ // Center: shoot
+ game.tap(x, y, obj);
+ }
}
};
// Asteroid spawn logic
function spawnAsteroid() {
Modern App Store icon, high definition, square with rounded corners, for a game titled "Space Dog: Asteroid Blaster" and with the description "Control a spacefaring dog, shoot asteroids, and avoid collisions to survive and score points.". No text on icon!
A BIG GRAY ASTEROID. In-Game asset. 2d. High contrast. No shadows. Retro 8bt
16 bit super nintendo