User prompt
add animated particles to the explosion
Code edit (1 edits merged)
Please save this source code
User prompt
put the explosion effect in the correct place according to the killed enemy
User prompt
add an explosion particle effect when enemies die
User prompt
add moving stars to the background to simulate movement
User prompt
implement the powerup
User prompt
Please fix the bug: 'ReferenceError: powerUpActive is not defined' in or related to this line: 'player.x += (5 + powerUpActive * 5) * playerDirection;' Line Number: 97
User prompt
be creative and make it more interesting
User prompt
make the player change direction when clicking to shoot
User prompt
make the player move back and forth since it's only a one click game
Initial prompt
One Button Shooter
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10 - Math.random() * 5; // Random speed between -10 and -15
self.update = function () {
self.y += self.speed;
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5 + Math.random() * 5; // Random speed between 5 and 10
self.update = function () {
self.y += self.speed + LK.ticks / 10000; // Increase speed over time
};
});
// 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 () {
self.alpha -= 0.02; // Fade out
if (self.alpha <= 0) {
self.destroy();
}
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y - playerGraphics.height / 2;
bullets.push(bullet);
game.addChild(bullet);
};
});
// PowerUp class
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += 5;
};
});
// 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 = 1 + Math.random() * 3; // Random speed between 1 and 4
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + 50) {
self.y = -50;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize stars array
var stars = [];
// Add stars to the game
for (var i = 0; i < 100; i++) {
var star = new Star();
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
stars.push(star);
game.addChild(star);
}
// Initialize arrays and variables
var bullets = [];
var enemies = [];
var powerUpActive = 0; // Initialize powerUpActive variable
var powerUps = []; // Initialize powerUps array
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 200;
var playerDirection = 1;
// Score display
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle shooting
game.down = function (x, y, obj) {
player.shoot();
playerDirection *= -1;
};
// Update game state
game.update = function () {
// Update player's position with speed boost if power-up is active
player.x += (5 + powerUpActive * 5) * playerDirection;
// Change direction if player hits the edge
if (player.x > 2048 - player.width / 2 || player.x < player.width / 2) {
playerDirection *= -1;
}
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
if (bullets[i].y < -50) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (enemies[j].y > 2732 + 50) {
enemies[j].destroy();
enemies.splice(j, 1);
}
}
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = enemies.length - 1; l >= 0; l--) {
if (bullets[k].intersects(enemies[l])) {
// Add explosion particle effect
var explosion = new Explosion();
explosion.x = enemies[l].x + enemies[l].width / 2;
explosion.y = enemies[l].y + enemies[l].height / 2;
game.addChild(explosion);
bullets[k].destroy();
enemies[l].destroy();
bullets.splice(k, 1);
enemies.splice(l, 1);
score++;
scoreTxt.setText(score);
break;
}
}
}
// Update powerUps
for (var i = powerUps.length - 1; i >= 0; i--) {
powerUps[i].update();
if (powerUps[i].y > 2732 + 50) {
powerUps[i].destroy();
powerUps.splice(i, 1);
}
}
// Spawn enemies and occasionally power-ups
if (LK.ticks % 60 == 0) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = -50;
enemies.push(enemy);
game.addChild(enemy);
// Spawn a power-up every 10th enemy
if (enemies.length % 10 == 0) {
var powerUp = new PowerUp();
powerUp.x = Math.random() * 2048;
powerUp.y = -50;
powerUps.push(powerUp);
game.addChild(powerUp);
}
}
// Check for powerUp collision with player
for (var n = powerUps.length - 1; n >= 0; n--) {
if (powerUps[n].intersects(player)) {
powerUps[n].destroy();
powerUps.splice(n, 1);
powerUpActive = 1;
}
}
// Reset powerUpActive after some time
if (powerUpActive && LK.ticks % 600 == 0) {
powerUpActive = 0;
}
// Update stars
for (var i = stars.length - 1; i >= 0; i--) {
stars[i].update();
}
// Check for game over
for (var m = enemies.length - 1; m >= 0; m--) {
if (enemies[m].intersects(player)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -151,19 +151,19 @@
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = enemies.length - 1; l >= 0; l--) {
if (bullets[k].intersects(enemies[l])) {
+ // Add explosion particle effect
+ var explosion = new Explosion();
+ explosion.x = enemies[l].x + enemies[l].width / 2;
+ explosion.y = enemies[l].y + enemies[l].height / 2;
+ game.addChild(explosion);
bullets[k].destroy();
enemies[l].destroy();
bullets.splice(k, 1);
enemies.splice(l, 1);
score++;
scoreTxt.setText(score);
- // Add explosion particle effect
- var explosion = new Explosion();
- explosion.x = enemies[l].x + enemies[l].width / 2;
- explosion.y = enemies[l].y + enemies[l].height / 2;
- game.addChild(explosion);
break;
}
}
}
explosion toony. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
SKULL BALL. A ball with a skull on, billard ball with skull. Studio Ghibli. Ghibli style. Mobile game. Colorful. hand drawn. cute. fun. In-Game asset. 2d. Blank background. High contrast. No shadows.