User prompt
It’s not shooting out the direction I’m pointing in
User prompt
When I turn the direction I’m shooting isn’t coming from the tip of the triangle
User prompt
It’s not shooting out of the right part and it’s not changing the direction where it shoots out when I turn
User prompt
Make longest tip of the triangle the front and where it shoots and the direction it moves
User prompt
Make the player slower and steering less sensitive and make the tip of the triangle the front
User prompt
Don’t make the buttons hollow and make it auto move forward forever
User prompt
The buttons don’t work and it’s still not moving forward
User prompt
The buttons don’t work and it’s constantly moving left
User prompt
Make my rocket ship a triangle shape and make it pixel art and all the stuff is hollow
User prompt
Make turning less sensitive and have it move ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the shoot one in the middle and left one on the left of the shoot and right on the right side and make them big
Code edit (1 edits merged)
Please save this source code
User prompt
Pixel Asteroid Blaster
Initial prompt
Make a game like asteroids game with the player that turns and has to shoot asteroids but make it black and white in pixel art and there buttons to turn and one to shoot
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Asteroid = Container.expand(function (size) {
var self = Container.call(this);
// Size can be 0 (small), 1 (medium), or 2 (large)
self.size = size || 2;
var assetId;
if (self.size === 0) {
assetId = 'asteroidSmall';
} else if (self.size === 1) {
assetId = 'asteroidMedium';
} else {
assetId = 'asteroidLarge';
}
var asteroidGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
// Random velocity
var speed = (3 - self.size) * 0.8 + 0.5; // Smaller asteroids move faster
var angle = Math.random() * Math.PI * 2;
self.velocity = {
x: Math.cos(angle) * speed,
y: Math.sin(angle) * speed
};
// Random rotation
self.rotationSpeed = (Math.random() - 0.5) * 0.05;
self.update = function () {
// Move
self.x += self.velocity.x;
self.y += self.velocity.y;
// Rotate
asteroidGraphics.rotation += self.rotationSpeed;
// Wrap around screen edges
if (self.x < -50) {
self.x = 2098;
}
if (self.x > 2098) {
self.x = -50;
}
if (self.y < -50) {
self.y = 2782;
}
if (self.y > 2782) {
self.y = -50;
}
};
self.getPoints = function () {
return (3 - self.size) * 100; // Small: 300, Medium: 200, Large: 100
};
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bulletShape', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.velocity = {
x: 0,
y: 0
};
self.lifespan = 60; // 1 second at 60fps
self.age = 0;
self.update = function () {
self.x += self.velocity.x;
self.y += self.velocity.y;
self.age++;
// Wrap around screen edges
if (self.x < 0) {
self.x = 2048;
}
if (self.x > 2048) {
self.x = 0;
}
if (self.y < 0) {
self.y = 2732;
}
if (self.y > 2732) {
self.y = 0;
}
};
return self;
});
var Button = Container.expand(function (assetId) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5
});
self.isPressed = false;
self.down = function (x, y, obj) {
self.isPressed = true;
buttonGraphics.alpha = 0.8;
};
self.up = function (x, y, obj) {
self.isPressed = false;
buttonGraphics.alpha = 0.5;
};
return self;
});
var Ship = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('shipShape', {
anchorX: 0.5,
anchorY: 0.5
});
// Ship properties
self.rotation = 0;
self.rotationSpeed = 0.1;
self.isRotatingLeft = false;
self.isRotatingRight = false;
self.isFiring = false;
self.fireDelay = 15; // frames between shots
self.fireTimer = 0;
self.invulnerable = false;
self.invulnerableTime = 0;
self.update = function () {
// Handle rotation
if (self.isRotatingLeft) {
self.rotation -= self.rotationSpeed;
}
if (self.isRotatingRight) {
self.rotation += self.rotationSpeed;
}
shipGraphics.rotation = self.rotation;
// Handle firing
if (self.isFiring) {
if (self.fireTimer <= 0) {
self.fireTimer = self.fireDelay;
return true; // Signal to create a bullet
}
}
if (self.fireTimer > 0) {
self.fireTimer--;
}
// Handle invulnerability
if (self.invulnerable) {
self.invulnerableTime--;
shipGraphics.alpha = Math.sin(LK.ticks * 0.5) * 0.5 + 0.5;
if (self.invulnerableTime <= 0) {
self.invulnerable = false;
shipGraphics.alpha = 1;
}
}
return false;
};
self.makeInvulnerable = function (frames) {
self.invulnerable = true;
self.invulnerableTime = frames;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Game variables
var ship;
var bullets = [];
var asteroids = [];
var score = 0;
var lives = 3;
var level = 1;
var gameStarted = false;
var gameOver = false;
// UI elements
var leftButton;
var rightButton;
var fireButton;
var scoreTxt;
var livesTxt;
var levelTxt;
var startText;
// Initialize the game
function initGame() {
// Create ship
ship = new Ship();
ship.x = 2048 / 2;
ship.y = 2732 / 2;
ship.makeInvulnerable(120); // 2 seconds
game.addChild(ship);
// Create control buttons
leftButton = new Button('rotateLeftButton');
leftButton.x = 120;
leftButton.y = 2732 - 120;
game.addChild(leftButton);
rightButton = new Button('rotateRightButton');
rightButton.x = 280;
rightButton.y = 2732 - 120;
game.addChild(rightButton);
fireButton = new Button('fireButton');
fireButton.x = 2048 - 120;
fireButton.y = 2732 - 120;
game.addChild(fireButton);
// Create UI text
scoreTxt = new Text2('SCORE: 0', {
size: 40,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreTxt);
livesTxt = new Text2('LIVES: 3', {
size: 40,
fill: 0xFFFFFF
});
livesTxt.anchor.set(0, 0);
LK.gui.top.addChild(livesTxt);
levelTxt = new Text2('LEVEL: 1', {
size: 40,
fill: 0xFFFFFF
});
levelTxt.anchor.set(1, 0);
LK.gui.topLeft.addChild(levelTxt);
// Start screen text
if (!gameStarted) {
startText = new Text2('TAP TO START', {
size: 80,
fill: 0xFFFFFF
});
startText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(startText);
}
// Clear any existing game objects
bullets = [];
asteroids = [];
// Initialize asteroids for the first level
createAsteroidsForLevel(level);
// Start game music
LK.playMusic('gameMusic', {
loop: true
});
}
function createAsteroidsForLevel(level) {
// Number of asteroids based on level
var numAsteroids = Math.min(4 + level, 12);
for (var i = 0; i < numAsteroids; i++) {
var asteroid = new Asteroid(2); // Start with large asteroids
// Position the asteroid away from the player
do {
asteroid.x = Math.random() * 2048;
asteroid.y = Math.random() * 2732;
} while (distance(asteroid.x, asteroid.y, ship.x, ship.y) < 300);
asteroids.push(asteroid);
game.addChild(asteroid);
}
}
function distance(x1, y1, x2, y2) {
return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
function createBullet() {
var bullet = new Bullet();
// Position bullet at ship's position
bullet.x = ship.x;
bullet.y = ship.y;
// Calculate bullet velocity based on ship's rotation
var angle = ship.rotation;
bullet.velocity.x = Math.cos(angle) * bullet.speed;
bullet.velocity.y = Math.sin(angle) * bullet.speed;
bullets.push(bullet);
game.addChild(bullet);
// Play shoot sound
LK.getSound('shoot').play();
}
function updateAsteroids() {
for (var i = asteroids.length - 1; i >= 0; i--) {
var asteroid = asteroids[i];
asteroid.update();
// Check for collision with the ship
if (!ship.invulnerable && asteroid.intersects(ship)) {
// Player loses a life
lives--;
livesTxt.setText('LIVES: ' + lives);
// Play explosion sound
LK.getSound('explosion').play();
// Flash screen
LK.effects.flashScreen(0xFF0000, 500);
// Make ship invulnerable for a few seconds
ship.makeInvulnerable(180);
// Game over if no lives left
if (lives <= 0) {
LK.setScore(score);
LK.showGameOver();
gameOver = true;
return;
}
}
}
}
function updateBullets() {
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
bullet.update();
// Remove bullets that have lived too long
if (bullet.age > bullet.lifespan) {
game.removeChild(bullet);
bullets.splice(i, 1);
continue;
}
// Check for collisions with asteroids
var hitAsteroid = false;
for (var j = asteroids.length - 1; j >= 0; j--) {
var asteroid = asteroids[j];
if (bullet.intersects(asteroid)) {
hitAsteroid = true;
// Add score based on asteroid size
score += asteroid.getPoints();
scoreTxt.setText('SCORE: ' + score);
// Play explosion sound
LK.getSound('explosion').play();
// Break asteroid into smaller pieces if it's not already the smallest
if (asteroid.size > 0) {
for (var k = 0; k < 2; k++) {
var newAsteroid = new Asteroid(asteroid.size - 1);
newAsteroid.x = asteroid.x;
newAsteroid.y = asteroid.y;
asteroids.push(newAsteroid);
game.addChild(newAsteroid);
}
}
// Remove the asteroid
game.removeChild(asteroid);
asteroids.splice(j, 1);
break;
}
}
if (hitAsteroid) {
// Remove the bullet
game.removeChild(bullet);
bullets.splice(i, 1);
}
}
// Check if all asteroids are destroyed
if (asteroids.length === 0) {
// Next level
level++;
levelTxt.setText('LEVEL: ' + level);
// Create new asteroids for the next level
createAsteroidsForLevel(level);
}
}
// Main game update function
game.update = function () {
if (!gameStarted) {
return;
}
// Update ship controls
ship.isRotatingLeft = leftButton.isPressed;
ship.isRotatingRight = rightButton.isPressed;
ship.isFiring = fireButton.isPressed;
// Update ship
if (ship.update()) {
createBullet();
}
// Update bullets and check for collisions
updateBullets();
// Update asteroids and check for collisions
updateAsteroids();
};
// Event handlers
game.down = function (x, y, obj) {
if (!gameStarted) {
gameStarted = true;
if (startText) {
LK.gui.center.removeChild(startText);
startText = null;
}
}
};
// Initialize the game when this script runs
initGame(); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,387 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var Asteroid = Container.expand(function (size) {
+ var self = Container.call(this);
+ // Size can be 0 (small), 1 (medium), or 2 (large)
+ self.size = size || 2;
+ var assetId;
+ if (self.size === 0) {
+ assetId = 'asteroidSmall';
+ } else if (self.size === 1) {
+ assetId = 'asteroidMedium';
+ } else {
+ assetId = 'asteroidLarge';
+ }
+ var asteroidGraphics = self.attachAsset(assetId, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Random velocity
+ var speed = (3 - self.size) * 0.8 + 0.5; // Smaller asteroids move faster
+ var angle = Math.random() * Math.PI * 2;
+ self.velocity = {
+ x: Math.cos(angle) * speed,
+ y: Math.sin(angle) * speed
+ };
+ // Random rotation
+ self.rotationSpeed = (Math.random() - 0.5) * 0.05;
+ self.update = function () {
+ // Move
+ self.x += self.velocity.x;
+ self.y += self.velocity.y;
+ // Rotate
+ asteroidGraphics.rotation += self.rotationSpeed;
+ // Wrap around screen edges
+ if (self.x < -50) {
+ self.x = 2098;
+ }
+ if (self.x > 2098) {
+ self.x = -50;
+ }
+ if (self.y < -50) {
+ self.y = 2782;
+ }
+ if (self.y > 2782) {
+ self.y = -50;
+ }
+ };
+ self.getPoints = function () {
+ return (3 - self.size) * 100; // Small: 300, Medium: 200, Large: 100
+ };
+ return self;
+});
+var Bullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bulletShape', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 10;
+ self.velocity = {
+ x: 0,
+ y: 0
+ };
+ self.lifespan = 60; // 1 second at 60fps
+ self.age = 0;
+ self.update = function () {
+ self.x += self.velocity.x;
+ self.y += self.velocity.y;
+ self.age++;
+ // Wrap around screen edges
+ if (self.x < 0) {
+ self.x = 2048;
+ }
+ if (self.x > 2048) {
+ self.x = 0;
+ }
+ if (self.y < 0) {
+ self.y = 2732;
+ }
+ if (self.y > 2732) {
+ self.y = 0;
+ }
+ };
+ return self;
+});
+var Button = Container.expand(function (assetId) {
+ var self = Container.call(this);
+ var buttonGraphics = self.attachAsset(assetId, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.5
+ });
+ self.isPressed = false;
+ self.down = function (x, y, obj) {
+ self.isPressed = true;
+ buttonGraphics.alpha = 0.8;
+ };
+ self.up = function (x, y, obj) {
+ self.isPressed = false;
+ buttonGraphics.alpha = 0.5;
+ };
+ return self;
+});
+var Ship = Container.expand(function () {
+ var self = Container.call(this);
+ var shipGraphics = self.attachAsset('shipShape', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Ship properties
+ self.rotation = 0;
+ self.rotationSpeed = 0.1;
+ self.isRotatingLeft = false;
+ self.isRotatingRight = false;
+ self.isFiring = false;
+ self.fireDelay = 15; // frames between shots
+ self.fireTimer = 0;
+ self.invulnerable = false;
+ self.invulnerableTime = 0;
+ self.update = function () {
+ // Handle rotation
+ if (self.isRotatingLeft) {
+ self.rotation -= self.rotationSpeed;
+ }
+ if (self.isRotatingRight) {
+ self.rotation += self.rotationSpeed;
+ }
+ shipGraphics.rotation = self.rotation;
+ // Handle firing
+ if (self.isFiring) {
+ if (self.fireTimer <= 0) {
+ self.fireTimer = self.fireDelay;
+ return true; // Signal to create a bullet
+ }
+ }
+ if (self.fireTimer > 0) {
+ self.fireTimer--;
+ }
+ // Handle invulnerability
+ if (self.invulnerable) {
+ self.invulnerableTime--;
+ shipGraphics.alpha = Math.sin(LK.ticks * 0.5) * 0.5 + 0.5;
+ if (self.invulnerableTime <= 0) {
+ self.invulnerable = false;
+ shipGraphics.alpha = 1;
+ }
+ }
+ return false;
+ };
+ self.makeInvulnerable = function (frames) {
+ self.invulnerable = true;
+ self.invulnerableTime = frames;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
backgroundColor: 0x000000
-});
\ No newline at end of file
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var ship;
+var bullets = [];
+var asteroids = [];
+var score = 0;
+var lives = 3;
+var level = 1;
+var gameStarted = false;
+var gameOver = false;
+// UI elements
+var leftButton;
+var rightButton;
+var fireButton;
+var scoreTxt;
+var livesTxt;
+var levelTxt;
+var startText;
+// Initialize the game
+function initGame() {
+ // Create ship
+ ship = new Ship();
+ ship.x = 2048 / 2;
+ ship.y = 2732 / 2;
+ ship.makeInvulnerable(120); // 2 seconds
+ game.addChild(ship);
+ // Create control buttons
+ leftButton = new Button('rotateLeftButton');
+ leftButton.x = 120;
+ leftButton.y = 2732 - 120;
+ game.addChild(leftButton);
+ rightButton = new Button('rotateRightButton');
+ rightButton.x = 280;
+ rightButton.y = 2732 - 120;
+ game.addChild(rightButton);
+ fireButton = new Button('fireButton');
+ fireButton.x = 2048 - 120;
+ fireButton.y = 2732 - 120;
+ game.addChild(fireButton);
+ // Create UI text
+ scoreTxt = new Text2('SCORE: 0', {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ scoreTxt.anchor.set(0, 0);
+ LK.gui.topRight.addChild(scoreTxt);
+ livesTxt = new Text2('LIVES: 3', {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ livesTxt.anchor.set(0, 0);
+ LK.gui.top.addChild(livesTxt);
+ levelTxt = new Text2('LEVEL: 1', {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ levelTxt.anchor.set(1, 0);
+ LK.gui.topLeft.addChild(levelTxt);
+ // Start screen text
+ if (!gameStarted) {
+ startText = new Text2('TAP TO START', {
+ size: 80,
+ fill: 0xFFFFFF
+ });
+ startText.anchor.set(0.5, 0.5);
+ LK.gui.center.addChild(startText);
+ }
+ // Clear any existing game objects
+ bullets = [];
+ asteroids = [];
+ // Initialize asteroids for the first level
+ createAsteroidsForLevel(level);
+ // Start game music
+ LK.playMusic('gameMusic', {
+ loop: true
+ });
+}
+function createAsteroidsForLevel(level) {
+ // Number of asteroids based on level
+ var numAsteroids = Math.min(4 + level, 12);
+ for (var i = 0; i < numAsteroids; i++) {
+ var asteroid = new Asteroid(2); // Start with large asteroids
+ // Position the asteroid away from the player
+ do {
+ asteroid.x = Math.random() * 2048;
+ asteroid.y = Math.random() * 2732;
+ } while (distance(asteroid.x, asteroid.y, ship.x, ship.y) < 300);
+ asteroids.push(asteroid);
+ game.addChild(asteroid);
+ }
+}
+function distance(x1, y1, x2, y2) {
+ return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
+}
+function createBullet() {
+ var bullet = new Bullet();
+ // Position bullet at ship's position
+ bullet.x = ship.x;
+ bullet.y = ship.y;
+ // Calculate bullet velocity based on ship's rotation
+ var angle = ship.rotation;
+ bullet.velocity.x = Math.cos(angle) * bullet.speed;
+ bullet.velocity.y = Math.sin(angle) * bullet.speed;
+ bullets.push(bullet);
+ game.addChild(bullet);
+ // Play shoot sound
+ LK.getSound('shoot').play();
+}
+function updateAsteroids() {
+ for (var i = asteroids.length - 1; i >= 0; i--) {
+ var asteroid = asteroids[i];
+ asteroid.update();
+ // Check for collision with the ship
+ if (!ship.invulnerable && asteroid.intersects(ship)) {
+ // Player loses a life
+ lives--;
+ livesTxt.setText('LIVES: ' + lives);
+ // Play explosion sound
+ LK.getSound('explosion').play();
+ // Flash screen
+ LK.effects.flashScreen(0xFF0000, 500);
+ // Make ship invulnerable for a few seconds
+ ship.makeInvulnerable(180);
+ // Game over if no lives left
+ if (lives <= 0) {
+ LK.setScore(score);
+ LK.showGameOver();
+ gameOver = true;
+ return;
+ }
+ }
+ }
+}
+function updateBullets() {
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ var bullet = bullets[i];
+ bullet.update();
+ // Remove bullets that have lived too long
+ if (bullet.age > bullet.lifespan) {
+ game.removeChild(bullet);
+ bullets.splice(i, 1);
+ continue;
+ }
+ // Check for collisions with asteroids
+ var hitAsteroid = false;
+ for (var j = asteroids.length - 1; j >= 0; j--) {
+ var asteroid = asteroids[j];
+ if (bullet.intersects(asteroid)) {
+ hitAsteroid = true;
+ // Add score based on asteroid size
+ score += asteroid.getPoints();
+ scoreTxt.setText('SCORE: ' + score);
+ // Play explosion sound
+ LK.getSound('explosion').play();
+ // Break asteroid into smaller pieces if it's not already the smallest
+ if (asteroid.size > 0) {
+ for (var k = 0; k < 2; k++) {
+ var newAsteroid = new Asteroid(asteroid.size - 1);
+ newAsteroid.x = asteroid.x;
+ newAsteroid.y = asteroid.y;
+ asteroids.push(newAsteroid);
+ game.addChild(newAsteroid);
+ }
+ }
+ // Remove the asteroid
+ game.removeChild(asteroid);
+ asteroids.splice(j, 1);
+ break;
+ }
+ }
+ if (hitAsteroid) {
+ // Remove the bullet
+ game.removeChild(bullet);
+ bullets.splice(i, 1);
+ }
+ }
+ // Check if all asteroids are destroyed
+ if (asteroids.length === 0) {
+ // Next level
+ level++;
+ levelTxt.setText('LEVEL: ' + level);
+ // Create new asteroids for the next level
+ createAsteroidsForLevel(level);
+ }
+}
+// Main game update function
+game.update = function () {
+ if (!gameStarted) {
+ return;
+ }
+ // Update ship controls
+ ship.isRotatingLeft = leftButton.isPressed;
+ ship.isRotatingRight = rightButton.isPressed;
+ ship.isFiring = fireButton.isPressed;
+ // Update ship
+ if (ship.update()) {
+ createBullet();
+ }
+ // Update bullets and check for collisions
+ updateBullets();
+ // Update asteroids and check for collisions
+ updateAsteroids();
+};
+// Event handlers
+game.down = function (x, y, obj) {
+ if (!gameStarted) {
+ gameStarted = true;
+ if (startText) {
+ LK.gui.center.removeChild(startText);
+ startText = null;
+ }
+ }
+};
+// Initialize the game when this script runs
+initGame();
\ No newline at end of file