User prompt
give the floating enemy its own sprite
User prompt
implement a new enemy that floats about and does not go away until it has been killed
Code edit (1 edits merged)
Please save this source code
User prompt
polish the way "Level x" label appears and dissappears
Code edit (2 edits merged)
Please save this source code
User prompt
polish the "Level x" text
Code edit (1 edits merged)
Please save this source code
User prompt
when a new level starts the player should blink 3 times
User prompt
the player should only move back to its proper y position after the completion of the level up
User prompt
after the level up, the player should move back to it's proper y position gently, not just in one frame
User prompt
the power-ups should be 2 different, one for speed and another for cannons, stackable
User prompt
implement a power-up that gives dual cannons for a while
User prompt
but also, enemies.length is always shortened when an enemy is killed, thus better do it differently, fix that
User prompt
fix it
User prompt
Please fix the bug: 'Uncaught TypeError: starGraphics.setScale is not a function' in or related to this line: 'starGraphics.setScale(1 + .2 * Math.random());' Line Number: 159
Code edit (1 edits merged)
Please save this source code
User prompt
in the leveling up, add some extra speed effects
Code edit (2 edits merged)
Please save this source code
User prompt
In the move up interval, when the leveling up is happening, the player's X position should go to the center of the screen.
Code edit (1 edits merged)
Please save this source code
User prompt
While game.isLevelingUp, the player should move upwards on the screen in the same duration it takes, and then back down.
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
upon level up there should be an effect where the stars in the background greatly increase in speed for a few seconds to simulate a far travel in space
Code edit (9 edits merged)
Please save this source code
/**** * 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 Enemy1 = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy1', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3 + Math.random() * 3; // Random speed between 5 and 10 self.update = function () { self.y += self.speed + LK.ticks / 10000; // Increase speed over time }; }); var Enemy2 = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy2', { 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 self.x += Math.sin(LK.ticks / 100) * 5; // Add a sine wave movement pattern }; }); var Enemy3 = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy3', { 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 self.x += Math.cos(LK.ticks / 100) * 5; // Add a cosine wave movement pattern }; }); // Explosion class var Explosion = Container.expand(function () { var self = Container.call(this); var explosionGraphics = self.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5 }); // Initialize particles array self.particles = []; // Create particles for (var i = 0; i < 50; i++) { var particle = self.attachAsset('explosionParticle', { anchorX: 0.5, anchorY: 0.5, x: Math.random() * explosionGraphics.width - explosionGraphics.width / 2, y: Math.random() * explosionGraphics.height - explosionGraphics.height / 2 }); particle.speedX = Math.random() * 2 - 1; particle.speedY = Math.random() * 2 - 1; self.particles.push(particle); } self.update = function () { self.alpha -= 0.02; // Fade out explosionGraphics.scale.x += 0.05; // Scale up faster explosionGraphics.scale.y += 0.05; // Scale up faster // Update particles for (var i = self.particles.length - 1; i >= 0; i--) { self.particles[i].x += self.particles[i].speedX * 5; // Increase speed self.particles[i].y += self.particles[i].speedY * 5; // Increase speed self.particles[i].rotation += 0.2; // Add rotation self.particles[i].alpha -= 0.04; if (self.particles[i].alpha <= 0) { self.particles[i].destroy(); self.particles.splice(i, 1); } } if (self.alpha <= 0) { self.destroy(); } }; }); // Player class var Player = Container.expand(function () { var self = Container.call(this); self.baseSpeed = 10; 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; }; }); // Progress Bar class var ProgressBar = Container.expand(function () { var self = Container.call(this); var progressBarGraphics = self.attachAsset('progressBar', { anchorX: 0.0, anchorY: 0.0 }); self.lastLevelUp = 0; self.reset = function () { progressBarGraphics.width = 0; self.lastLevelUp = LK.ticks; }; self.update = function () { progressBarGraphics.width = (LK.ticks - self.lastLevelUp) / 2000 * 2048; // Fill the progress bar over time }; }); // 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); var level = 1; // Initialize progress bar var progressBar = game.addChild(new ProgressBar()); progressBar.y = 0; var isMouseDown = false; // Event listener for mouse down game.down = function (x, y, obj) { player.shoot(); playerDirection *= -1; isMouseDown = true; }; // Event listener for mouse up game.up = function (x, y, obj) { isMouseDown = false; }; // Update game state game.update = function () { progressBar.update(); // Update player's position with speed boost if power-up is active //if (isMouseDown) { player.x += (player.baseSpeed + powerUpActive * player.baseSpeed) * playerDirection; // } // Wrap player's position around the screen if (player.x > 2048 + player.width / 2) { player.x = -player.width / 2; } else if (player.x < -player.width / 2) { player.x = 2048 + player.width / 2; // Change direction if player hits the edge } var trailStar = new Star(); trailStar.x = player.x; trailStar.y = player.y + 50; trailStar.alpha = 0.5; trailStar.scale.set(2 + 2 * Math.random()); trailStar.update = function () { this.alpha -= 0.01; // Fade out if (this.alpha <= 0) { this.destroy(); } }; game.addChildAt(trailStar, game.getChildIndex(player)); if (powerUpActive) { var trailStar = new Star(); trailStar.x = player.x; trailStar.y = player.y; trailStar.alpha = 0.5; trailStar.scale.set(2 + 2 * Math.random()); trailStar.update = function () { this.alpha -= 0.01; // Fade out if (this.alpha <= 0) { this.destroy(); } }; game.addChildAt(trailStar, game.getChildIndex(player)); } // 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])) { var explosion = new Explosion(); explosion.x = enemies[l].x; explosion.y = enemies[l].y; game.addChild(explosion); bullets[k].destroy(); if (enemies[l] instanceof Enemy1) { enemies[l].destroy(); score += 1; } else if (enemies[l] instanceof Enemy2) { enemies[l].destroy(); score += 2; } else if (enemies[l] instanceof Enemy3) { enemies[l].destroy(); score += 3; } bullets.splice(k, 1); enemies.splice(l, 1); 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 && progressBar.width < 2040) { var enemyType = Math.floor(Math.random() * 3) + 1; // Randomly select an enemy type var enemy; switch (enemyType) { case 1: enemy = new Enemy1(); break; case 2: enemy = new Enemy2(); break; case 3: enemy = new Enemy3(); break; } 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 && progressBar.width < 2048) { 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; // Set a timeout to reset powerUpActive after 10 seconds (600 ticks) LK.setTimeout(function () { powerUpActive = 0; }, 10000); } } // Update stars for (var i = stars.length - 1; i >= 0; i--) { stars[i].update(); } // Check if the progress bar is full if (progressBar.width >= 2048) { // Play a level up sound LK.getSound('levelUp').play(); // Increase the player's speed player.speed += 1; // List of nice colors var colors = [0x000080, 0x008000, 0x800000, 0x808000, 0x800080, 0x008080]; // Select a random color from the list var randomColor = colors[Math.floor(Math.random() * colors.length)]; // Change the background color game.setBackgroundColor(randomColor); // Show a popup var levelText = new Text2('Level ' + (level + 1), { size: 300, fill: "#ffffff" }); levelText.anchor.set(0.5, 0.5); levelText.x = 2048 / 2; levelText.y = 2732 / 2; game.addChild(levelText); // Remove the text after 2 seconds LK.setTimeout(function () { levelText.destroy(); }, 2000); level++; // Reset the progress bar progressBar.reset(); } // 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(); } } };
/****
* 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 Enemy1 = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy1', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3 + Math.random() * 3; // Random speed between 5 and 10
self.update = function () {
self.y += self.speed + LK.ticks / 10000; // Increase speed over time
};
});
var Enemy2 = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy2', {
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
self.x += Math.sin(LK.ticks / 100) * 5; // Add a sine wave movement pattern
};
});
var Enemy3 = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy3', {
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
self.x += Math.cos(LK.ticks / 100) * 5; // Add a cosine wave movement pattern
};
});
// Explosion class
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
// Initialize particles array
self.particles = [];
// Create particles
for (var i = 0; i < 50; i++) {
var particle = self.attachAsset('explosionParticle', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * explosionGraphics.width - explosionGraphics.width / 2,
y: Math.random() * explosionGraphics.height - explosionGraphics.height / 2
});
particle.speedX = Math.random() * 2 - 1;
particle.speedY = Math.random() * 2 - 1;
self.particles.push(particle);
}
self.update = function () {
self.alpha -= 0.02; // Fade out
explosionGraphics.scale.x += 0.05; // Scale up faster
explosionGraphics.scale.y += 0.05; // Scale up faster
// Update particles
for (var i = self.particles.length - 1; i >= 0; i--) {
self.particles[i].x += self.particles[i].speedX * 5; // Increase speed
self.particles[i].y += self.particles[i].speedY * 5; // Increase speed
self.particles[i].rotation += 0.2; // Add rotation
self.particles[i].alpha -= 0.04;
if (self.particles[i].alpha <= 0) {
self.particles[i].destroy();
self.particles.splice(i, 1);
}
}
if (self.alpha <= 0) {
self.destroy();
}
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
self.baseSpeed = 10;
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;
};
});
// Progress Bar class
var ProgressBar = Container.expand(function () {
var self = Container.call(this);
var progressBarGraphics = self.attachAsset('progressBar', {
anchorX: 0.0,
anchorY: 0.0
});
self.lastLevelUp = 0;
self.reset = function () {
progressBarGraphics.width = 0;
self.lastLevelUp = LK.ticks;
};
self.update = function () {
progressBarGraphics.width = (LK.ticks - self.lastLevelUp) / 2000 * 2048; // Fill the progress bar over time
};
});
// 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);
var level = 1;
// Initialize progress bar
var progressBar = game.addChild(new ProgressBar());
progressBar.y = 0;
var isMouseDown = false;
// Event listener for mouse down
game.down = function (x, y, obj) {
player.shoot();
playerDirection *= -1;
isMouseDown = true;
};
// Event listener for mouse up
game.up = function (x, y, obj) {
isMouseDown = false;
};
// Update game state
game.update = function () {
progressBar.update();
// Update player's position with speed boost if power-up is active
//if (isMouseDown) {
player.x += (player.baseSpeed + powerUpActive * player.baseSpeed) * playerDirection;
// }
// Wrap player's position around the screen
if (player.x > 2048 + player.width / 2) {
player.x = -player.width / 2;
} else if (player.x < -player.width / 2) {
player.x = 2048 + player.width / 2;
// Change direction if player hits the edge
}
var trailStar = new Star();
trailStar.x = player.x;
trailStar.y = player.y + 50;
trailStar.alpha = 0.5;
trailStar.scale.set(2 + 2 * Math.random());
trailStar.update = function () {
this.alpha -= 0.01; // Fade out
if (this.alpha <= 0) {
this.destroy();
}
};
game.addChildAt(trailStar, game.getChildIndex(player));
if (powerUpActive) {
var trailStar = new Star();
trailStar.x = player.x;
trailStar.y = player.y;
trailStar.alpha = 0.5;
trailStar.scale.set(2 + 2 * Math.random());
trailStar.update = function () {
this.alpha -= 0.01; // Fade out
if (this.alpha <= 0) {
this.destroy();
}
};
game.addChildAt(trailStar, game.getChildIndex(player));
}
// 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])) {
var explosion = new Explosion();
explosion.x = enemies[l].x;
explosion.y = enemies[l].y;
game.addChild(explosion);
bullets[k].destroy();
if (enemies[l] instanceof Enemy1) {
enemies[l].destroy();
score += 1;
} else if (enemies[l] instanceof Enemy2) {
enemies[l].destroy();
score += 2;
} else if (enemies[l] instanceof Enemy3) {
enemies[l].destroy();
score += 3;
}
bullets.splice(k, 1);
enemies.splice(l, 1);
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 && progressBar.width < 2040) {
var enemyType = Math.floor(Math.random() * 3) + 1; // Randomly select an enemy type
var enemy;
switch (enemyType) {
case 1:
enemy = new Enemy1();
break;
case 2:
enemy = new Enemy2();
break;
case 3:
enemy = new Enemy3();
break;
}
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 && progressBar.width < 2048) {
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;
// Set a timeout to reset powerUpActive after 10 seconds (600 ticks)
LK.setTimeout(function () {
powerUpActive = 0;
}, 10000);
}
}
// Update stars
for (var i = stars.length - 1; i >= 0; i--) {
stars[i].update();
}
// Check if the progress bar is full
if (progressBar.width >= 2048) {
// Play a level up sound
LK.getSound('levelUp').play();
// Increase the player's speed
player.speed += 1;
// List of nice colors
var colors = [0x000080, 0x008000, 0x800000, 0x808000, 0x800080, 0x008080];
// Select a random color from the list
var randomColor = colors[Math.floor(Math.random() * colors.length)];
// Change the background color
game.setBackgroundColor(randomColor);
// Show a popup
var levelText = new Text2('Level ' + (level + 1), {
size: 300,
fill: "#ffffff"
});
levelText.anchor.set(0.5, 0.5);
levelText.x = 2048 / 2;
levelText.y = 2732 / 2;
game.addChild(levelText);
// Remove the text after 2 seconds
LK.setTimeout(function () {
levelText.destroy();
}, 2000);
level++;
// Reset the progress bar
progressBar.reset();
}
// 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();
}
}
};
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.