User prompt
Can you move the score a little more to the left
User prompt
Sometimes there are two spaceships when the spaceship is close to the bottom right of the screen. Can you make it so there is only ever 1 spaceship?
User prompt
Can you make the stars spawn infinitely, at a rate of 1.3 * minute since game started
User prompt
And now move the score a little bit to the left
User prompt
Can you make the score text right anchored instead of left anchored
User prompt
Can you move the score a little to the left
User prompt
Yeha but can you like do that instead of telling em
User prompt
The lasers are not colliding with the stars :(
User prompt
Make the starship icon not blink
User prompt
When a laser collides with a star, destroy the star and create an explosion. Then destroy the explosion
User prompt
Can you make it to click to fire the laser
User prompt
the icon is blinking
Initial prompt
Astroids
/****
* Classes
****/
// Explosion class
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
explosionGraphics.alpha -= 0.1;
if (explosionGraphics.alpha <= 0) {
self.destroy();
}
};
});
// Laser class
var Laser = Container.expand(function () {
var self = Container.call(this);
var laserGraphics = self.attachAsset('laser', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10;
self.update = function () {
self.y += self.speed;
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Spaceship class
var Spaceship = Container.expand(function () {
var self = Container.call(this);
var spaceshipGraphics = self.attachAsset('spaceship', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Spaceship update logic
// Removed spaceship blinking
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
self.lasers = [];
self.fire = function () {
var laser = new Laser();
laser.x = self.x;
laser.y = self.y;
self.lasers.push(laser);
game.addChild(laser);
};
});
// Star class
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize score
var score = 0;
// Initialize game start time
var gameStartTime = Date.now();
var scoreTxt = new Text2('0', {
size: 50,
fill: 0xFFFFFF,
align: 'right'
});
// Initialize last star spawn time
var lastStarSpawnTime = Date.now();
scoreTxt.x = -50; // Move the score display 50 pixels to the left
LK.gui.topRight.addChild(scoreTxt);
// Initialize spaceship
var spaceship = new Spaceship();
spaceship.x = 2048 / 2;
spaceship.y = 2732 - 200;
game.addChild(spaceship);
// Initialize stars
var stars = [];
for (var i = 0; i < 50; i++) {
var star = new Star();
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
stars.push(star);
game.addChild(star);
}
// Handle spaceship movement
game.down = function (x, y, obj) {
spaceship.move(x, y);
spaceship.fire();
};
// Update game elements
game.update = function () {
for (var i = 0; i < stars.length; i++) {
stars[i].update();
// Check for collision between each star and the spaceship's lasers
for (var j = 0; j < spaceship.lasers.length; j++) {
if (stars[i].intersects(spaceship.lasers[j])) {
// Create an explosion at the star's position
var explosion = new Explosion();
explosion.x = stars[i].x;
explosion.y = stars[i].y;
game.addChild(explosion);
// Destroy the star and the laser
stars[i].destroy();
spaceship.lasers[j].destroy();
// Remove the star and the laser from their respective arrays
stars.splice(i, 1);
spaceship.lasers.splice(j, 1);
// Increase score by 10
score += 10;
// Update score display
scoreTxt.setText(score);
break;
}
}
}
// Calculate the time since the game started in minutes
var timeSinceGameStart = (Date.now() - gameStartTime) / 60000;
// Calculate the time since the last star was spawned in seconds
var timeSinceLastStarSpawn = (Date.now() - lastStarSpawnTime) / 1000;
// Calculate the star spawn rate
var starSpawnRate = 1.3 * timeSinceGameStart;
// If the time since the last star was spawned is greater than or equal to the star spawn rate, spawn a new star
if (timeSinceLastStarSpawn >= starSpawnRate) {
var star = new Star();
star.x = Math.random() * 2048;
star.y = 0;
stars.push(star);
game.addChild(star);
lastStarSpawnTime = Date.now();
}
spaceship.update();
}; ===================================================================
--- original.js
+++ change.js
@@ -82,13 +82,17 @@
* Game Code
****/
// Initialize score
var score = 0;
+// Initialize game start time
+var gameStartTime = Date.now();
var scoreTxt = new Text2('0', {
size: 50,
fill: 0xFFFFFF,
align: 'right'
});
+// Initialize last star spawn time
+var lastStarSpawnTime = Date.now();
scoreTxt.x = -50; // Move the score display 50 pixels to the left
LK.gui.topRight.addChild(scoreTxt);
// Initialize spaceship
var spaceship = new Spaceship();
@@ -134,6 +138,21 @@
break;
}
}
}
+ // Calculate the time since the game started in minutes
+ var timeSinceGameStart = (Date.now() - gameStartTime) / 60000;
+ // Calculate the time since the last star was spawned in seconds
+ var timeSinceLastStarSpawn = (Date.now() - lastStarSpawnTime) / 1000;
+ // Calculate the star spawn rate
+ var starSpawnRate = 1.3 * timeSinceGameStart;
+ // If the time since the last star was spawned is greater than or equal to the star spawn rate, spawn a new star
+ if (timeSinceLastStarSpawn >= starSpawnRate) {
+ var star = new Star();
+ star.x = Math.random() * 2048;
+ star.y = 0;
+ stars.push(star);
+ game.addChild(star);
+ lastStarSpawnTime = Date.now();
+ }
spaceship.update();
};
\ No newline at end of file
asteroid. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Spaceship like in galaga. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. Straight up and down. Seen from above.
Explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.