User prompt
When the enemies get behind us, the game is over.
User prompt
I can't hear sounds. Solve the problem.
User prompt
ammo drops by 5 per level
User prompt
Make the texts in the game Turkish ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
I can't open the menu. Remove the menu button. Add the language option to the part where we pause the game (eng/tr) ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
I can't open the menu. Fix this. Also, move the menu button under the stop button. Do what I said. Fix these.
User prompt
I can't open the menu. Fix this. Also, move the menu button under the stop button. ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
I can't open the menu
User prompt
Add a small menu to the game, settings, English/Turkish language options, etc. ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
I killed all the enemies at level 4 but I can't go to level 5. Fix this. And if there are the same problems in other levels, fix those problems too (when I kill the enemies at level 3, I get 320 points)
User prompt
I killed all the enemies at level 3 but I can't go to level 4. Fix this. And if there are the same problems in other levels, fix those problems too (I get 240 points when I kill the enemies at level 3)
User prompt
I killed all the enemies in level 3 but I can't go to level 4. Fix this. And if there are the same problems in other levels, fix those problems too.
User prompt
I killed all the enemies in level 3 but I can't go to level 4. Fix this. And if there are the same problems in other levels, fix those problems too.
User prompt
I kill all the enemies in level 1 but I can't go to level 2. If this problem exists in other levels, fix them too.
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading '0')' in or related to this line: 'var maxAmmo = ammoPerLevel[0]; // Start with level 1 ammo' Line Number: 123
User prompt
Add 5 more levels by increasing the difficulty
User prompt
Let the pirates get off the ship a very little faster
User prompt
The pirates should leave the ship a little slower.
User prompt
Create a new skin for the ship and the enemies will leave the ship a little slower.
User prompt
Let the pirate ship come from behind and the enemies leave that ship in the same order so that the ship does not advance too far. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.speed = 12;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.moveSpeed = 1 + Math.random() * 2;
self.directionX = (Math.random() - 0.5) * 2;
self.directionY = (Math.random() - 0.5) * 2;
self.update = function () {
self.x += self.directionX * self.moveSpeed;
self.y += self.directionY * self.moveSpeed;
// Keep enemies moving downward (toward player)
if (self.directionY < 0) {
self.directionY = 1;
}
// Bounce off side walls only
if (self.x <= 30 || self.x >= 2018) {
self.directionX *= -1;
}
// Remove enemies that go off bottom of screen
if (self.y > 2782) {
var index = enemies.indexOf(self);
if (index > -1) {
enemies.splice(index, 1);
}
self.destroy();
}
};
return self;
});
var PirateShip = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('pirateShip', {
anchorX: 0.5,
anchorY: 0.5
});
self.moveSpeed = shipSpeedPerLevel[0]; // Start with level 1 speed
self.enemySpawnTimer = 0;
self.enemySpawnRate = enemySpawnRatePerLevel[0]; // Start with level 1 spawn rate
self.maxEnemiesFromShip = enemiesPerLevel[0]; // Start with level 1 enemy count
self.enemiesSpawnedFromShip = 0;
self.update = function () {
// Move ship horizontally across top of screen
self.x += self.moveSpeed;
// Reverse direction when hitting screen edges
if (self.x <= 100 || self.x >= 1948) {
self.moveSpeed *= -1;
}
// Spawn enemies from ship
self.enemySpawnTimer++;
if (self.enemySpawnTimer >= self.enemySpawnRate && self.enemiesSpawnedFromShip < self.maxEnemiesFromShip) {
spawnEnemyFromShip(self.x, self.y + 80);
self.enemySpawnTimer = 0;
self.enemiesSpawnedFromShip++;
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.isReady = true;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var player = game.addChild(new Player());
player.x = 1024;
player.y = 2500;
var bullets = [];
var enemies = [];
var enemySpawnTimer = 0;
var difficultyTimer = 0;
var baseSpawnRate = 180; // frames between spawns
var currentSpawnRate = baseSpawnRate;
var maxAmmo = ammoPerLevel[0]; // Start with level 1 ammo
var currentAmmo = maxAmmo;
var maxEnemies = maxEnemiesPerLevel[0]; // Start with level 1 max enemies
var enemiesSpawned = 0;
// Level system variables
var currentLevel = 1;
var maxLevel = 5;
var enemiesKilled = 0;
var enemiesPerLevel = [10, 15, 20, 25, 30]; // Enemies to kill per level
var shipSpeedPerLevel = [2, 2.5, 3, 3.5, 4]; // Ship speed per level
var enemySpawnRatePerLevel = [120, 100, 80, 60, 40]; // Spawn rate per level (lower = faster)
var maxEnemiesPerLevel = [8, 12, 16, 20, 25]; // Max enemies on screen per level
var ammoPerLevel = [20, 25, 30, 35, 40]; // Ammo given per level
// Add pirate ship
var pirateShip = game.addChild(new PirateShip());
pirateShip.x = 200;
pirateShip.y = 150;
// UI Elements
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var readyIndicator = new Text2('READY', {
size: 60,
fill: 0x00FF00
});
readyIndicator.anchor.set(0.5, 0.5);
LK.gui.center.addChild(readyIndicator);
var ammoTxt = new Text2('Cephane: 20', {
size: 60,
fill: 0xFFFFFF
});
ammoTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(ammoTxt);
var levelTxt = new Text2('Level: 1', {
size: 60,
fill: 0xFFD700
});
levelTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(levelTxt);
function updateScore() {
scoreTxt.setText('Score: ' + LK.getScore());
}
function updateAmmo() {
ammoTxt.setText('Cephane: ' + currentAmmo);
}
function updateLevel() {
levelTxt.setText('Level: ' + currentLevel);
}
function advanceLevel() {
if (currentLevel >= maxLevel) {
LK.showYouWin();
return;
}
currentLevel++;
enemiesKilled = 0;
enemiesSpawned = 0;
// Update pirate ship stats for new level
pirateShip.moveSpeed = Math.abs(pirateShip.moveSpeed) > 0 ? pirateShip.moveSpeed > 0 ? shipSpeedPerLevel[currentLevel - 1] : -shipSpeedPerLevel[currentLevel - 1] : shipSpeedPerLevel[currentLevel - 1];
pirateShip.enemySpawnRate = enemySpawnRatePerLevel[currentLevel - 1];
pirateShip.maxEnemiesFromShip = enemiesPerLevel[currentLevel - 1];
pirateShip.enemiesSpawnedFromShip = 0;
// Refill ammo for new level
currentAmmo = ammoPerLevel[currentLevel - 1];
maxAmmo = ammoPerLevel[currentLevel - 1];
// Update displays
updateLevel();
updateAmmo();
// Flash screen green to indicate level up
LK.effects.flashScreen(0x00ff00, 500);
}
function spawnEnemy() {
if (enemiesSpawned >= maxEnemies) return;
var enemy = new Enemy();
// Spawn from top (opposite direction from player)
enemy.x = Math.random() * 2048;
enemy.y = -30; // Spawn from top of screen
// Set enemy to move toward bottom (toward player)
enemy.directionX = (Math.random() - 0.5) * 0.5;
enemy.directionY = 1; // Always move down toward player
enemy.moveSpeed = 1 + Math.random() * 2; // Ensure speed is set
enemies.push(enemy);
game.addChild(enemy);
enemiesSpawned++;
LK.getSound('enemySpawn').play();
}
function spawnEnemyFromShip(shipX, shipY) {
if (enemiesSpawned >= maxEnemies) return;
var enemy = new Enemy();
// Spawn from pirate ship position
enemy.x = shipX + (Math.random() - 0.5) * 100; // Small random offset from ship
enemy.y = shipY;
// Set enemy to move toward bottom (toward player)
enemy.directionX = (Math.random() - 0.5) * 0.5;
enemy.directionY = 1; // Always move down toward player
enemy.moveSpeed = 1 + Math.random() * 2;
// Add tween animation for enemy dropping from ship
tween(enemy, {
y: shipY + 50
}, {
duration: 500,
easing: tween.easeOut
});
enemies.push(enemy);
game.addChild(enemy);
enemiesSpawned++;
LK.getSound('enemySpawn').play();
}
function shootBullet(targetX, targetY) {
if (!player.isReady || currentAmmo <= 0) return;
currentAmmo--;
updateAmmo();
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
// Calculate direction to target
var dx = targetX - player.x;
var dy = targetY - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Normalize and set speed
bullet.speedX = dx / distance * bullet.speed;
bullet.speedY = dy / distance * bullet.speed;
bullets.push(bullet);
game.addChild(bullet);
player.isReady = false;
readyIndicator.setText('SHOOTING');
readyIndicator.tint = 0xff0000;
LK.getSound('shoot').play();
}
function returnBulletToPlayer(bullet) {
// Animate bullet returning to player
tween(bullet, {
x: player.x,
y: player.y
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
bullet.destroy();
var index = bullets.indexOf(bullet);
if (index > -1) {
bullets.splice(index, 1);
}
player.isReady = true;
readyIndicator.setText('READY');
readyIndicator.tint = 0x00ff00;
}
});
}
game.down = function (x, y, obj) {
if (player.isReady) {
shootBullet(x, y);
}
};
game.update = function () {
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Check if bullet is off screen
if (bullet.x < -50 || bullet.x > 2098 || bullet.y < -50 || bullet.y > 2782) {
returnBulletToPlayer(bullet);
continue;
}
// Check collision with enemies
var hitEnemy = false;
for (var j = enemies.length - 1; j >= 0; j--) {
var enemy = enemies[j];
if (bullet.intersects(enemy)) {
// Hit enemy
LK.setScore(LK.getScore() + 10);
updateScore();
enemiesKilled++;
// Flash effect on enemy
LK.effects.flashObject(enemy, 0xffffff, 200);
// Remove enemy
enemy.destroy();
enemies.splice(j, 1);
// Return bullet to player
returnBulletToPlayer(bullet);
hitEnemy = true;
LK.getSound('hit').play();
// Check if level is completed
if (enemiesKilled >= enemiesPerLevel[currentLevel - 1]) {
advanceLevel();
}
break;
}
}
if (hitEnemy) break;
}
// Check if player collides with enemies
for (var k = 0; k < enemies.length; k++) {
var enemy = enemies[k];
if (player.intersects(enemy)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
// Disable regular enemy spawning - enemies now only come from pirate ship
// enemySpawnTimer++;
// if (enemySpawnTimer >= currentSpawnRate && enemiesSpawned < maxEnemies) {
// spawnEnemy();
// enemySpawnTimer = 0;
// }
// Increase difficulty over time
difficultyTimer++;
if (difficultyTimer >= 600) {
// Every 10 seconds
if (currentSpawnRate > 60) {
currentSpawnRate -= 5;
}
difficultyTimer = 0;
}
// Check if game should end (no ammo and no bullets in flight)
if (currentAmmo <= 0 && bullets.length === 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
// Check win condition (completed all levels)
if (currentLevel > maxLevel) {
LK.showYouWin();
return;
}
// Limit number of enemies on screen based on current level
if (enemies.length > maxEnemiesPerLevel[currentLevel - 1]) {
var oldestEnemy = enemies.shift();
oldestEnemy.destroy();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -57,12 +57,12 @@
var shipGraphics = self.attachAsset('pirateShip', {
anchorX: 0.5,
anchorY: 0.5
});
- self.moveSpeed = 2;
+ self.moveSpeed = shipSpeedPerLevel[0]; // Start with level 1 speed
self.enemySpawnTimer = 0;
- self.enemySpawnRate = 120; // Spawn enemy every 120 frames (a little faster)
- self.maxEnemiesFromShip = 18;
+ self.enemySpawnRate = enemySpawnRatePerLevel[0]; // Start with level 1 spawn rate
+ self.maxEnemiesFromShip = enemiesPerLevel[0]; // Start with level 1 enemy count
self.enemiesSpawnedFromShip = 0;
self.update = function () {
// Move ship horizontally across top of screen
self.x += self.moveSpeed;
@@ -108,12 +108,21 @@
var enemySpawnTimer = 0;
var difficultyTimer = 0;
var baseSpawnRate = 180; // frames between spawns
var currentSpawnRate = baseSpawnRate;
-var maxAmmo = 20;
+var maxAmmo = ammoPerLevel[0]; // Start with level 1 ammo
var currentAmmo = maxAmmo;
-var maxEnemies = 18;
+var maxEnemies = maxEnemiesPerLevel[0]; // Start with level 1 max enemies
var enemiesSpawned = 0;
+// Level system variables
+var currentLevel = 1;
+var maxLevel = 5;
+var enemiesKilled = 0;
+var enemiesPerLevel = [10, 15, 20, 25, 30]; // Enemies to kill per level
+var shipSpeedPerLevel = [2, 2.5, 3, 3.5, 4]; // Ship speed per level
+var enemySpawnRatePerLevel = [120, 100, 80, 60, 40]; // Spawn rate per level (lower = faster)
+var maxEnemiesPerLevel = [8, 12, 16, 20, 25]; // Max enemies on screen per level
+var ammoPerLevel = [20, 25, 30, 35, 40]; // Ammo given per level
// Add pirate ship
var pirateShip = game.addChild(new PirateShip());
pirateShip.x = 200;
pirateShip.y = 150;
@@ -135,14 +144,45 @@
fill: 0xFFFFFF
});
ammoTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(ammoTxt);
+var levelTxt = new Text2('Level: 1', {
+ size: 60,
+ fill: 0xFFD700
+});
+levelTxt.anchor.set(0, 0);
+LK.gui.topLeft.addChild(levelTxt);
function updateScore() {
scoreTxt.setText('Score: ' + LK.getScore());
}
function updateAmmo() {
ammoTxt.setText('Cephane: ' + currentAmmo);
}
+function updateLevel() {
+ levelTxt.setText('Level: ' + currentLevel);
+}
+function advanceLevel() {
+ if (currentLevel >= maxLevel) {
+ LK.showYouWin();
+ return;
+ }
+ currentLevel++;
+ enemiesKilled = 0;
+ enemiesSpawned = 0;
+ // Update pirate ship stats for new level
+ pirateShip.moveSpeed = Math.abs(pirateShip.moveSpeed) > 0 ? pirateShip.moveSpeed > 0 ? shipSpeedPerLevel[currentLevel - 1] : -shipSpeedPerLevel[currentLevel - 1] : shipSpeedPerLevel[currentLevel - 1];
+ pirateShip.enemySpawnRate = enemySpawnRatePerLevel[currentLevel - 1];
+ pirateShip.maxEnemiesFromShip = enemiesPerLevel[currentLevel - 1];
+ pirateShip.enemiesSpawnedFromShip = 0;
+ // Refill ammo for new level
+ currentAmmo = ammoPerLevel[currentLevel - 1];
+ maxAmmo = ammoPerLevel[currentLevel - 1];
+ // Update displays
+ updateLevel();
+ updateAmmo();
+ // Flash screen green to indicate level up
+ LK.effects.flashScreen(0x00ff00, 500);
+}
function spawnEnemy() {
if (enemiesSpawned >= maxEnemies) return;
var enemy = new Enemy();
// Spawn from top (opposite direction from player)
@@ -241,8 +281,9 @@
if (bullet.intersects(enemy)) {
// Hit enemy
LK.setScore(LK.getScore() + 10);
updateScore();
+ enemiesKilled++;
// Flash effect on enemy
LK.effects.flashObject(enemy, 0xffffff, 200);
// Remove enemy
enemy.destroy();
@@ -250,8 +291,12 @@
// Return bullet to player
returnBulletToPlayer(bullet);
hitEnemy = true;
LK.getSound('hit').play();
+ // Check if level is completed
+ if (enemiesKilled >= enemiesPerLevel[currentLevel - 1]) {
+ advanceLevel();
+ }
break;
}
}
if (hitEnemy) break;
@@ -285,15 +330,15 @@
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
- // Check win condition (all enemies destroyed)
- if (enemiesSpawned >= maxEnemies && enemies.length === 0) {
+ // Check win condition (completed all levels)
+ if (currentLevel > maxLevel) {
LK.showYouWin();
return;
}
- // Limit number of enemies on screen
- if (enemies.length > 15) {
+ // Limit number of enemies on screen based on current level
+ if (enemies.length > maxEnemiesPerLevel[currentLevel - 1]) {
var oldestEnemy = enemies.shift();
oldestEnemy.destroy();
}
};
\ No newline at end of file