User prompt
Add game over to all phases and fix collision in bullet to destroy the right enemy
User prompt
make sure that in every phase, you have to defeat all enemies for the portal to appear and add follow to enemy to follow the player
User prompt
Continue add colisão, follow, game over e outros nas fases a coans
User prompt
!fix does not go to the next phase when going to the open portal
User prompt
Make then walk faster to the portal
User prompt
Add the same function with all phases (infinites phases)
User prompt
When the player collide with the portal, it goes to the next stage
User prompt
If the portal is open, the player automatically walks to the portal, and goes to stage 2 with more enemies
User prompt
Add enemy follow, lk score, and game over lk
User prompt
Add bullet move
User prompt
The portal have a sprite, if all enemies are defeated, change to portal open
User prompt
Add all assets to serve for something
User prompt
Continue place more code and add functions move
User prompt
Make the game, but avançado
User prompt
Delete all code
Initial prompt
a shooting game
===================================================================
--- original.js
+++ change.js
@@ -14,16 +14,18 @@
player.y = 2732 - player.height;
// Hide the open portal
portalOpen.visible = false;
// Add more enemies for the current stage
+ enemies = [];
for (var i = 0; i < 5 + stageNumber; i++) {
var newEnemy = LK.getAsset('Enemy', {
anchorX: 0.5,
anchorY: 0.5
});
newEnemy.x = Math.random() * 2048;
newEnemy.y = Math.random() * 500;
game.addChild(newEnemy);
+ enemies.push(newEnemy);
}
}
var background = LK.getAsset('Background', {
anchorX: 0.5,
@@ -69,8 +71,9 @@
portalOpen.y = 2732 / 2 + 100;
portalOpen.visible = false; // Initially hide the open portal
game.addChild(portalOpen);
var currentStage = 1;
+var enemies = [];
var bullets = [];
function shootBullet() {
var bullet = LK.getAsset('Bullet', {
anchorX: 0.5,
@@ -88,16 +91,18 @@
player.y = y;
};
game.update = function () {
// Enemy follows the player
- var dx = player.x - enemy.x;
- var dy = player.y - enemy.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance > 5) {
- // Only move if the enemy is not too close
- enemy.x += dx / distance * 2; // Move enemy towards player
- enemy.y += dy / distance * 2;
- }
+ enemies.forEach(function (enemy) {
+ var dx = player.x - enemy.x;
+ var dy = player.y - enemy.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 5) {
+ // Only move if the enemy is not too close
+ enemy.x += dx / distance * 2; // Move enemy towards player
+ enemy.y += dy / distance * 2;
+ }
+ });
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].y -= 10;
if (bullets[i].y < 0) {
bullets[i].destroy();
@@ -105,10 +110,13 @@
} else if (bullets[i].intersects(enemy)) {
bullets[i].destroy();
bullets.splice(i, 1);
enemy.destroy(); // Destroy the enemy
- portal.visible = false; // Hide the closed portal
- portalOpen.visible = true; // Show the open portal
+ enemies.splice(enemies.indexOf(enemy), 1); // Remove enemy from the array
+ if (enemies.length === 0) {
+ portal.visible = false; // Hide the closed portal
+ portalOpen.visible = true; // Show the open portal
+ }
LK.setScore(LK.getScore() + 100); // Increase score by 100
// Check if player is hit by enemy
if (enemy.intersects(player)) {
LK.effects.flashScreen(0xff0000, 1000); // Flash screen red
character with a gun looking from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Bullet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
background of an abandoned street. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.