User prompt
Let them come from above, not from below
User prompt
If there is still no enemy coming from the opposite direction, create a mob called enemy and let them come from the opposite direction.
User prompt
The enemy is not coming from the enemy, let the enemy come from the opposite side
User prompt
Write "cehpane" instead of ammo
User prompt
Let the enemies come from the opposite direction and let's say you have 20 ammunition and 18 enemies come
Code edit (1 edits merged)
Please save this source code
User prompt
Ball Shooter Arena
Initial prompt
bir top olsun ardından o top ile düşmanları vuramlım vurdukça puan kazanalım
/****
* 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 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 = 20;
var currentAmmo = maxAmmo;
var maxEnemies = 18;
var enemiesSpawned = 0;
// 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);
function updateScore() {
scoreTxt.setText('Score: ' + LK.getScore());
}
function updateAmmo() {
ammoTxt.setText('Cephane: ' + currentAmmo);
}
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 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();
// 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();
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;
}
}
// Spawn enemies
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 (all enemies destroyed)
if (enemiesSpawned >= maxEnemies && enemies.length === 0) {
LK.showYouWin();
return;
}
// Limit number of enemies on screen
if (enemies.length > 15) {
var oldestEnemy = enemies.shift();
oldestEnemy.destroy();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -32,18 +32,18 @@
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 upward (toward player)
- if (self.directionY > 0) {
- self.directionY = -1;
+ // 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 top of screen
- if (self.y < -50) {
+ // Remove enemies that go off bottom of screen
+ if (self.y > 2782) {
var index = enemies.indexOf(self);
if (index > -1) {
enemies.splice(index, 1);
}
@@ -112,14 +112,14 @@
}
function spawnEnemy() {
if (enemiesSpawned >= maxEnemies) return;
var enemy = new Enemy();
- // Spawn from bottom (opposite direction from player)
+ // Spawn from top (opposite direction from player)
enemy.x = Math.random() * 2048;
- enemy.y = 2762; // Spawn from bottom of screen
- // Set enemy to move toward top (toward player)
+ 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 up toward player
+ 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++;