Code edit (1 edits merged)
Please save this source code
User prompt
their is a moon ithe corner of the screen in the gameplay can you remove that
User prompt
i cant hear the sounds
User prompt
very good, can you add more decor to the game in general (not the same assets new ones)
User prompt
add a pixelated moon picture at the bottom
User prompt
spot on but add more decore on the start screen
User prompt
make a screen before the game with a start button when yoh press it it starts the game
User prompt
scrap the idea
User prompt
its good just can you add a start butten so when you hit it ,it statrts the game
User prompt
make a title screen
User prompt
make that a asset
User prompt
- **Slow Motion:** Temporarily slows down all asteroids when picked up power up
User prompt
do dynamic difficulty
User prompt
Please fix the bug: 'TypeError: LK.effects.shakeScreen is not a function' in or related to this line: 'LK.effects.shakeScreen(0xff0000, 800, 20); // Strong shake on collision' Line Number: 88
User prompt
Please fix the bug: 'TypeError: LK.effects.shake is not a function' in or related to this line: 'LK.effects.shake({' Line Number: 88
User prompt
Please fix the bug: 'TypeError: LK.effects.shakeScreen is not a function' in or related to this line: 'LK.effects.shakeScreen(800, 20); // Strong shake on collision' Line Number: 88
User prompt
yes do thatt
User prompt
Make the score on top.
User prompt
Make every astro that the spaceship dodges, make that count as a point.
User prompt
No, just make them come down in your direction.
User prompt
Yes, but make the asteroids come for you.
User prompt
Make it go left to right. It can't move up or down.
Initial prompt
asteroid dodger
/****
* Classes
****/
// Asteroid class
var Asteroid = Container.expand(function () {
var self = Container.call(this);
var asteroidGraphics = self.attachAsset('asteroid', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
});
//<Assets used in the game will automatically appear here>
// Slow Motion Power-Up class
var SlowMotionPowerUp = Container.expand(function () {
var self = Container.call(this);
var powerupGraphics = self.attachAsset('slowmo', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.update = function () {
self.y += self.speed;
};
return self;
});
// 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 if needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Dedicated slow motion power-up asset
// Initialize spaceship
var spaceship = game.addChild(new Spaceship());
spaceship.x = 2048 / 2;
spaceship.y = 2732 - 200;
// Array to hold asteroids
var asteroids = [];
// Slow motion power-up variables
var slowMotionActive = false;
var slowMotionTimer = 0;
var SLOW_MOTION_DURATION = 180; // 3 seconds at 60fps
var SLOW_MOTION_FACTOR = 0.3; // Asteroids move at 30% speed
// Function to handle spaceship movement
function handleMove(x, y, obj) {
spaceship.x = x;
// spaceship.y = y; // Commented out to restrict vertical movement
}
// Game move event
game.move = handleMove;
// Game update function
game.update = function () {
// Dynamic difficulty variables
if (typeof asteroidSpawnInterval === "undefined") {
var asteroidSpawnInterval = 60; // Initial spawn interval (frames)
var asteroidBaseSpeed = 5; // Initial asteroid speed
var asteroidMaxSpeed = 30; // Cap asteroid speed
var asteroidMinInterval = 15; // Minimum interval between spawns
var asteroidDifficultyStep = 10; // Score step for difficulty increase
var asteroidLastDifficultyScore = 0;
}
// Increase difficulty based on score
var currentScore = LK.getScore();
if (currentScore - asteroidLastDifficultyScore >= asteroidDifficultyStep) {
asteroidLastDifficultyScore = currentScore;
// Increase speed, decrease interval
asteroidBaseSpeed = Math.min(asteroidBaseSpeed + 1, asteroidMaxSpeed);
asteroidSpawnInterval = Math.max(asteroidSpawnInterval - 5, asteroidMinInterval);
}
// Create new asteroids
if (LK.ticks % asteroidSpawnInterval == 0) {
var newAsteroid = new Asteroid();
newAsteroid.x = Math.random() * 2048;
newAsteroid.y = -50;
newAsteroid.speed = asteroidBaseSpeed;
asteroids.push(newAsteroid);
game.addChild(newAsteroid);
// 1 in 10 chance to spawn a slow motion power-up (but not if one is already active or present)
if (!slowMotionActive && Math.random() < 0.1 && typeof slowMotionPowerUp === "undefined") {
slowMotionPowerUp = new SlowMotionPowerUp();
slowMotionPowerUp.x = Math.random() * 2048;
slowMotionPowerUp.y = -100;
game.addChild(slowMotionPowerUp);
}
}
// Initialize score display
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Update asteroids
for (var i = asteroids.length - 1; i >= 0; i--) {
var asteroid = asteroids[i];
// Apply slow motion if active
if (slowMotionActive) {
asteroid.y += asteroid.speed * SLOW_MOTION_FACTOR;
} else {
asteroid.update();
}
// Check for collision with spaceship
if (spaceship.intersects(asteroid)) {
LK.effects.flashScreen(0xff0000, 1000);
// Play collision sound if available
if (LK.getSound && LK.getSound('crash')) {
LK.getSound('crash').play();
}
LK.showGameOver();
return;
}
// Remove off-screen asteroids and increment score
if (asteroid.y > 2732 + 50) {
// Near miss visual/audio effect if asteroid was close to spaceship horizontally
var dx = Math.abs(asteroid.x - spaceship.x);
if (dx < 200) {
LK.effects.flashScreen(0xffff00, 200); // Quick yellow flash for near miss
// Play near miss sound if available
if (LK.getSound && LK.getSound('nearMiss')) {
LK.getSound('nearMiss').play();
}
}
asteroid.destroy();
asteroids.splice(i, 1);
LK.setScore(LK.getScore() + 1); // Increment score for each asteroid dodged
scoreTxt.setText(LK.getScore()); // Update score display
// Play score up sound if available
if (LK.getSound && LK.getSound('scoreUp')) {
LK.getSound('scoreUp').play();
}
// Play asteroid whoosh sound if available
if (LK.getSound && LK.getSound('whoosh')) {
LK.getSound('whoosh').play();
}
}
}
// Handle slow motion power-up logic
if (typeof slowMotionPowerUp !== "undefined" && slowMotionPowerUp) {
// Move power-up
slowMotionPowerUp.y += slowMotionPowerUp.speed;
// Check for collision with spaceship
if (spaceship.intersects(slowMotionPowerUp)) {
slowMotionActive = true;
slowMotionTimer = SLOW_MOTION_DURATION;
// Visual feedback for slow motion activation
LK.effects.flashScreen(0x3399ff, 400);
slowMotionPowerUp.destroy();
slowMotionPowerUp = undefined;
} else if (slowMotionPowerUp.y > 2732 + 100) {
// Remove if off screen
slowMotionPowerUp.destroy();
slowMotionPowerUp = undefined;
}
}
// Handle slow motion timer
if (slowMotionActive) {
slowMotionTimer--;
if (slowMotionTimer <= 0) {
slowMotionActive = false;
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -16,14 +16,12 @@
//<Assets used in the game will automatically appear here>
// Slow Motion Power-Up class
var SlowMotionPowerUp = Container.expand(function () {
var self = Container.call(this);
- // Use asteroid asset for now, but tint blue for distinction
- var powerupGraphics = self.attachAsset('asteroid', {
+ var powerupGraphics = self.attachAsset('slowmo', {
anchorX: 0.5,
anchorY: 0.5
});
- powerupGraphics.tint = 0x3399ff;
self.speed = 6;
self.update = function () {
self.y += self.speed;
};
@@ -51,8 +49,9 @@
/****
* Game Code
****/
+// Dedicated slow motion power-up asset
// Initialize spaceship
var spaceship = game.addChild(new Spaceship());
spaceship.x = 2048 / 2;
spaceship.y = 2732 - 200;