User prompt
erase wave
User prompt
decrease enemy speed to slugish
User prompt
every wave only 5 enemies spawn
User prompt
fix spawn enemy
User prompt
every waves just spawn 5 enemys
User prompt
fix enemy numbers
User prompt
enemy movement very low
User prompt
reduce the number of enemies that appear each wave to only 5
User prompt
enemy spawn just 5
User prompt
enemy one hit dead
User prompt
enemy spawn just for
User prompt
one hit death
User prompt
reduce bullet quantity
User prompt
erase bounching
User prompt
bounching bullet
User prompt
bullet super speed
User prompt
reduce quantity of enemy for stability game
User prompt
slow speed enemy
User prompt
multiple direct bullte storm
User prompt
multiple directional shoot
Code edit (1 edits merged)
Please save this source code
User prompt
Fantasy Arena Clash
Initial prompt
make fantasy battle arena with random obstacle
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Bullet = Container.expand(function () { var self = Container.call(this); var bulletSprite = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 20; // Increase bullet speed for super speed effect self.damage = 25; self.directionX = 0; self.directionY = 0; self.update = function () { self.x += self.directionX * self.speed; self.y += self.directionY * self.speed; // Remove bullet if it goes off-screen if (self.x < -50 || self.x > 2098 || self.y < -50 || self.y > 2782) { self.destroy(); } }; return self; }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemySprite = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.health = 50; self.speed = 0.5; // Decrease speed for slower movement self.damage = 10; self.attackCooldown = 0; self.update = function () { if (!player) { return; } // Calculate direction to player var dx = player.x - self.x; var dy = player.y - self.y; var distanceSquared = dx * dx + dy * dy; // Move towards player if (distanceSquared > 0) { var distance = Math.sqrt(distanceSquared); self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } // Attack player if close enough and cooldown is done if (distanceSquared < 10000 && self.attackCooldown <= 0) { if (player.takeDamage(self.damage)) { self.attackCooldown = 60; // 1 second cooldown } } // Decrease attack cooldown if (self.attackCooldown > 0) { self.attackCooldown--; } }; self.takeDamage = function (amount) { self.health -= amount; // Flash red LK.effects.flashObject(self, 0xff0000, 200); if (self.health <= 0) { // Increase score waveManager.killCount++; LK.setScore(LK.getScore() + 10); scoreText.setText("Score: " + LK.getScore()); // Play death sound LK.getSound('enemyDeath').play(); // Remove from enemies array var index = enemies.indexOf(self); if (index !== -1) { enemies.splice(index, 1); } // Show exploded effect var explodedEffect = LK.getAsset('exploded', { anchorX: 0.5, anchorY: 0.5 }); explodedEffect.x = self.x; explodedEffect.y = self.y; game.addChild(explodedEffect); explodedEffect.alpha = 1; // Ensure visibility tween(explodedEffect, { alpha: 0 }, { duration: 1000, onFinish: function onFinish() { explodedEffect.destroy(); } }); // Destroy the enemy self.destroy(); return true; } return false; }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerSprite = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.health = 100; self.maxHealth = 100; self.speed = 5; self.baseSpeed = 5; self.attackCooldown = 0; self.invulnerable = 0; self.update = function () { // Decrease cooldowns if (self.attackCooldown > 0) { self.attackCooldown--; } if (self.invulnerable > 0) { self.invulnerable--; // Flash effect when invulnerable playerSprite.alpha = self.invulnerable % 10 < 5 ? 0.5 : 1; } else { playerSprite.alpha = 1; } // Limit player position to screen bounds self.x = Math.max(60, Math.min(1988, self.x)); self.y = Math.max(60, Math.min(2672, self.y)); }; self.takeDamage = function (amount) { if (self.invulnerable > 0) { return false; } self.health = 0; // Update health bar updateHealthBar(); // Set invulnerability frames self.invulnerable = 60; // 1 second // Play hit sound LK.getSound('playerHit').play(); // Flash red LK.effects.flashObject(self, 0xff0000, 500); // Show exploded effect var explodedEffect = LK.getAsset('exploded', { anchorX: 0.5, anchorY: 0.5 }); explodedEffect.x = self.x; explodedEffect.y = self.y; game.addChild(explodedEffect); explodedEffect.alpha = 1; // Ensure visibility tween.to(explodedEffect, { alpha: 0 }, 1000).onComplete(function () { explodedEffect.destroy(); }); return true; }; self.heal = function (amount) { self.health += amount; if (self.health > self.maxHealth) { self.health = self.maxHealth; } // Update health bar updateHealthBar(); // Play powerup sound LK.getSound('powerup').play(); // Flash green LK.effects.flashObject(self, 0x00ff00, 500); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ // Game state variables var player = null; var bullets = []; var enemies = []; var obstacles = []; var dragTarget = null; var isAttacking = false; var attackDirection = { x: 0, y: 0 }; var healthBar = null; var healthBarBg = null; var scoreText = null; var waveText = null; // Define waveManager to track kills and waves var waveManager = { killCount: 0, currentWave: 1 }; // Initialize game function initGame() { // Add background image var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5 }); background.x = 2048 / 2; background.y = 2732 / 2; game.addChild(background); // Create player player = new Player(); player.x = 2048 / 2; player.y = 2732 / 2; game.addChild(player); // Create health bar background healthBarBg = LK.getAsset('healthBarBg', { anchorX: 0, anchorY: 0, width: 300, height: 30, tint: 0x333333 }); // Create health bar healthBar = LK.getAsset('healthBar', { anchorX: 0, anchorY: 0, width: 300, height: 30, tint: 0x2ecc71 }); // Create score text scoreText = new Text2("Score: 0", { size: 40, fill: 0xFFFFFF }); scoreText.anchor.set(1, 0); // Add UI elements to GUI LK.gui.topRight.addChild(scoreText); LK.gui.bottomLeft.addChild(healthBarBg); LK.gui.bottomLeft.addChild(healthBar); healthBarBg.x = 20; healthBarBg.y = -50; healthBar.x = 20; healthBar.y = -50; // Position score text scoreText.x = -20; scoreText.y = 20; // Position wave text // Reset score LK.setScore(0); // Continuously spawn enemies LK.setInterval(function () { var enemy = new Enemy(); // Position enemy at edge of screen var side = Math.floor(Math.random() * 4); switch (side) { case 0: // Top enemy.x = Math.random() * 2048; enemy.y = -50; break; case 1: // Right enemy.x = 2048 + 50; enemy.y = Math.random() * 2732; break; case 2: // Bottom enemy.x = Math.random() * 2048; enemy.y = 2732 + 50; break; case 3: // Left enemy.x = -50; enemy.y = Math.random() * 2732; break; } game.addChild(enemy); enemies.push(enemy); }, 10000); // Spawn an enemy every 10 seconds // Play background music LK.playMusic('battleMusic'); } // Update health bar display function updateHealthBar() { if (player && healthBar) { var healthPercent = player.health / player.maxHealth; healthBar.width = 300 * healthPercent; // Change color based on health if (healthPercent > 0.6) { healthBar.tint = 0x2ecc71; // Green } else if (healthPercent > 0.3) { healthBar.tint = 0xf39c12; // Orange } else { healthBar.tint = 0xe74c3c; // Red } } } // Create obstacles for the current wave function createObstacles() { // Clear existing obstacles for (var i = obstacles.length - 1; i >= 0; i--) { game.removeChild(obstacles[i]); obstacles[i].destroy(); } obstacles = []; // Number of obstacles based on wave var numObstacles = 3 + Math.min(5, waveManager.currentWave); } // Place obstacle at a random position that doesn't overlap with player function placeObstacleRandomly(obstacle) { var positioned = false; var attempts = 0; while (!positioned && attempts < 20) { obstacle.x = 100 + Math.random() * (2048 - 200); obstacle.y = 100 + Math.random() * (2732 - 200); // Check if too close to player var dx = obstacle.x - player.x; var dy = obstacle.y - player.y; var distToPlayer = Math.sqrt(dx * dx + dy * dy); // Check if overlapping with other obstacles var overlapping = false; for (var i = 0; i < obstacles.length; i++) { if (obstacle.intersects(obstacles[i])) { overlapping = true; break; } } if (distToPlayer > 300 && !overlapping) { positioned = true; } attempts++; } } // Fire a bullet in the given direction function fireBullet(dirX, dirY) { if (player.attackCooldown > 0) { return; } // Normalize direction var length = Math.sqrt(dirX * dirX + dirY * dirY); if (length > 0) { dirX /= length; dirY /= length; } var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; bullet.directionX = dirX; bullet.directionY = dirY; game.addChild(bullet); bullets.push(bullet); // Set attack cooldown player.attackCooldown = 60; // 1 second // Play attack sound LK.getSound('playerAttack').play(); } // Handle player movement with the specified dx, dy direction function movePlayer(dx, dy) { if (!player) { return; } // Normalize direction var length = Math.sqrt(dx * dx + dy * dy); if (length > 0) { dx /= length; dy /= length; } // Calculate new position var newX = player.x + dx * player.speed; var newY = player.y + dy * player.speed; // Check boundaries if (newX < 40) { newX = 40; } if (newX > 2048 - 40) { newX = 2048 - 40; } if (newY < 40) { newY = 40; } if (newY > 2732 - 40) { newY = 2732 - 40; } // Apply movement player.x = newX; player.y = newY; } // Simple intersection check for collision detection function intersectsSimple(objA, objB) { return !(objA.x + objA.width / 2 < objB.x - objB.width / 2 || objA.x - objA.width / 2 > objB.x + objB.width / 2 || objA.y + objA.height / 2 < objB.y - objB.height / 2 || objA.y - objA.height / 2 > objB.y + objB.height / 2); } // Movement input handlers for drag controls game.down = function (x, y, obj) { dragTarget = { x: x, y: y }; isAttacking = false; }; game.move = function (x, y, obj) { if (dragTarget) { // Calculate drag distance and direction var dx = x - dragTarget.x; var dy = y - dragTarget.y; var distance = Math.sqrt(dx * dx + dy * dy); // If drag is long enough, it's an attack if (distance > 100) { isAttacking = true; attackDirection.x = dx / distance; attackDirection.y = dy / distance; // Fire a single bullet in the swipe direction fireBullet(attackDirection.x, attackDirection.y); } else { isAttacking = false; // Otherwise it's movement if (distance > 5) { movePlayer(dx, dy); } } } }; game.up = function (x, y, obj) { dragTarget = null; isAttacking = false; }; // Main game update function game.update = function () { // Skip updates if player is dead if (player && player.health <= 0) { LK.showGameOver(); return; } // Update player if (player) { player.update(); } // Update bullets for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; bullet.update(); // Check collision with enemies for (var j = enemies.length - 1; j >= 0; j--) { var enemy = enemies[j]; if (bullet.intersects(enemy)) { enemy.takeDamage(enemy.health); // One-hit death // Remove bullet bullet.destroy(); bullets.splice(i, 1); break; } } } // Update enemies for (var i = 0; i < enemies.length; i++) { var enemy = enemies[i]; enemy.update(); } // Removed wave progression logic }; // Initialize the game initGame();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletSprite = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 20; // Increase bullet speed for super speed effect
self.damage = 25;
self.directionX = 0;
self.directionY = 0;
self.update = function () {
self.x += self.directionX * self.speed;
self.y += self.directionY * self.speed;
// Remove bullet if it goes off-screen
if (self.x < -50 || self.x > 2098 || self.y < -50 || self.y > 2782) {
self.destroy();
}
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemySprite = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 50;
self.speed = 0.5; // Decrease speed for slower movement
self.damage = 10;
self.attackCooldown = 0;
self.update = function () {
if (!player) {
return;
}
// Calculate direction to player
var dx = player.x - self.x;
var dy = player.y - self.y;
var distanceSquared = dx * dx + dy * dy;
// Move towards player
if (distanceSquared > 0) {
var distance = Math.sqrt(distanceSquared);
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
// Attack player if close enough and cooldown is done
if (distanceSquared < 10000 && self.attackCooldown <= 0) {
if (player.takeDamage(self.damage)) {
self.attackCooldown = 60; // 1 second cooldown
}
}
// Decrease attack cooldown
if (self.attackCooldown > 0) {
self.attackCooldown--;
}
};
self.takeDamage = function (amount) {
self.health -= amount;
// Flash red
LK.effects.flashObject(self, 0xff0000, 200);
if (self.health <= 0) {
// Increase score
waveManager.killCount++;
LK.setScore(LK.getScore() + 10);
scoreText.setText("Score: " + LK.getScore());
// Play death sound
LK.getSound('enemyDeath').play();
// Remove from enemies array
var index = enemies.indexOf(self);
if (index !== -1) {
enemies.splice(index, 1);
}
// Show exploded effect
var explodedEffect = LK.getAsset('exploded', {
anchorX: 0.5,
anchorY: 0.5
});
explodedEffect.x = self.x;
explodedEffect.y = self.y;
game.addChild(explodedEffect);
explodedEffect.alpha = 1; // Ensure visibility
tween(explodedEffect, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
explodedEffect.destroy();
}
});
// Destroy the enemy
self.destroy();
return true;
}
return false;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerSprite = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.maxHealth = 100;
self.speed = 5;
self.baseSpeed = 5;
self.attackCooldown = 0;
self.invulnerable = 0;
self.update = function () {
// Decrease cooldowns
if (self.attackCooldown > 0) {
self.attackCooldown--;
}
if (self.invulnerable > 0) {
self.invulnerable--;
// Flash effect when invulnerable
playerSprite.alpha = self.invulnerable % 10 < 5 ? 0.5 : 1;
} else {
playerSprite.alpha = 1;
}
// Limit player position to screen bounds
self.x = Math.max(60, Math.min(1988, self.x));
self.y = Math.max(60, Math.min(2672, self.y));
};
self.takeDamage = function (amount) {
if (self.invulnerable > 0) {
return false;
}
self.health = 0;
// Update health bar
updateHealthBar();
// Set invulnerability frames
self.invulnerable = 60; // 1 second
// Play hit sound
LK.getSound('playerHit').play();
// Flash red
LK.effects.flashObject(self, 0xff0000, 500);
// Show exploded effect
var explodedEffect = LK.getAsset('exploded', {
anchorX: 0.5,
anchorY: 0.5
});
explodedEffect.x = self.x;
explodedEffect.y = self.y;
game.addChild(explodedEffect);
explodedEffect.alpha = 1; // Ensure visibility
tween.to(explodedEffect, {
alpha: 0
}, 1000).onComplete(function () {
explodedEffect.destroy();
});
return true;
};
self.heal = function (amount) {
self.health += amount;
if (self.health > self.maxHealth) {
self.health = self.maxHealth;
}
// Update health bar
updateHealthBar();
// Play powerup sound
LK.getSound('powerup').play();
// Flash green
LK.effects.flashObject(self, 0x00ff00, 500);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Game state variables
var player = null;
var bullets = [];
var enemies = [];
var obstacles = [];
var dragTarget = null;
var isAttacking = false;
var attackDirection = {
x: 0,
y: 0
};
var healthBar = null;
var healthBarBg = null;
var scoreText = null;
var waveText = null;
// Define waveManager to track kills and waves
var waveManager = {
killCount: 0,
currentWave: 1
};
// Initialize game
function initGame() {
// Add background image
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
background.x = 2048 / 2;
background.y = 2732 / 2;
game.addChild(background);
// Create player
player = new Player();
player.x = 2048 / 2;
player.y = 2732 / 2;
game.addChild(player);
// Create health bar background
healthBarBg = LK.getAsset('healthBarBg', {
anchorX: 0,
anchorY: 0,
width: 300,
height: 30,
tint: 0x333333
});
// Create health bar
healthBar = LK.getAsset('healthBar', {
anchorX: 0,
anchorY: 0,
width: 300,
height: 30,
tint: 0x2ecc71
});
// Create score text
scoreText = new Text2("Score: 0", {
size: 40,
fill: 0xFFFFFF
});
scoreText.anchor.set(1, 0);
// Add UI elements to GUI
LK.gui.topRight.addChild(scoreText);
LK.gui.bottomLeft.addChild(healthBarBg);
LK.gui.bottomLeft.addChild(healthBar);
healthBarBg.x = 20;
healthBarBg.y = -50;
healthBar.x = 20;
healthBar.y = -50;
// Position score text
scoreText.x = -20;
scoreText.y = 20;
// Position wave text
// Reset score
LK.setScore(0);
// Continuously spawn enemies
LK.setInterval(function () {
var enemy = new Enemy();
// Position enemy at edge of screen
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
// Top
enemy.x = Math.random() * 2048;
enemy.y = -50;
break;
case 1:
// Right
enemy.x = 2048 + 50;
enemy.y = Math.random() * 2732;
break;
case 2:
// Bottom
enemy.x = Math.random() * 2048;
enemy.y = 2732 + 50;
break;
case 3:
// Left
enemy.x = -50;
enemy.y = Math.random() * 2732;
break;
}
game.addChild(enemy);
enemies.push(enemy);
}, 10000); // Spawn an enemy every 10 seconds
// Play background music
LK.playMusic('battleMusic');
}
// Update health bar display
function updateHealthBar() {
if (player && healthBar) {
var healthPercent = player.health / player.maxHealth;
healthBar.width = 300 * healthPercent;
// Change color based on health
if (healthPercent > 0.6) {
healthBar.tint = 0x2ecc71; // Green
} else if (healthPercent > 0.3) {
healthBar.tint = 0xf39c12; // Orange
} else {
healthBar.tint = 0xe74c3c; // Red
}
}
}
// Create obstacles for the current wave
function createObstacles() {
// Clear existing obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
game.removeChild(obstacles[i]);
obstacles[i].destroy();
}
obstacles = [];
// Number of obstacles based on wave
var numObstacles = 3 + Math.min(5, waveManager.currentWave);
}
// Place obstacle at a random position that doesn't overlap with player
function placeObstacleRandomly(obstacle) {
var positioned = false;
var attempts = 0;
while (!positioned && attempts < 20) {
obstacle.x = 100 + Math.random() * (2048 - 200);
obstacle.y = 100 + Math.random() * (2732 - 200);
// Check if too close to player
var dx = obstacle.x - player.x;
var dy = obstacle.y - player.y;
var distToPlayer = Math.sqrt(dx * dx + dy * dy);
// Check if overlapping with other obstacles
var overlapping = false;
for (var i = 0; i < obstacles.length; i++) {
if (obstacle.intersects(obstacles[i])) {
overlapping = true;
break;
}
}
if (distToPlayer > 300 && !overlapping) {
positioned = true;
}
attempts++;
}
}
// Fire a bullet in the given direction
function fireBullet(dirX, dirY) {
if (player.attackCooldown > 0) {
return;
}
// Normalize direction
var length = Math.sqrt(dirX * dirX + dirY * dirY);
if (length > 0) {
dirX /= length;
dirY /= length;
}
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
bullet.directionX = dirX;
bullet.directionY = dirY;
game.addChild(bullet);
bullets.push(bullet);
// Set attack cooldown
player.attackCooldown = 60; // 1 second
// Play attack sound
LK.getSound('playerAttack').play();
}
// Handle player movement with the specified dx, dy direction
function movePlayer(dx, dy) {
if (!player) {
return;
}
// Normalize direction
var length = Math.sqrt(dx * dx + dy * dy);
if (length > 0) {
dx /= length;
dy /= length;
}
// Calculate new position
var newX = player.x + dx * player.speed;
var newY = player.y + dy * player.speed;
// Check boundaries
if (newX < 40) {
newX = 40;
}
if (newX > 2048 - 40) {
newX = 2048 - 40;
}
if (newY < 40) {
newY = 40;
}
if (newY > 2732 - 40) {
newY = 2732 - 40;
}
// Apply movement
player.x = newX;
player.y = newY;
}
// Simple intersection check for collision detection
function intersectsSimple(objA, objB) {
return !(objA.x + objA.width / 2 < objB.x - objB.width / 2 || objA.x - objA.width / 2 > objB.x + objB.width / 2 || objA.y + objA.height / 2 < objB.y - objB.height / 2 || objA.y - objA.height / 2 > objB.y + objB.height / 2);
}
// Movement input handlers for drag controls
game.down = function (x, y, obj) {
dragTarget = {
x: x,
y: y
};
isAttacking = false;
};
game.move = function (x, y, obj) {
if (dragTarget) {
// Calculate drag distance and direction
var dx = x - dragTarget.x;
var dy = y - dragTarget.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// If drag is long enough, it's an attack
if (distance > 100) {
isAttacking = true;
attackDirection.x = dx / distance;
attackDirection.y = dy / distance;
// Fire a single bullet in the swipe direction
fireBullet(attackDirection.x, attackDirection.y);
} else {
isAttacking = false;
// Otherwise it's movement
if (distance > 5) {
movePlayer(dx, dy);
}
}
}
};
game.up = function (x, y, obj) {
dragTarget = null;
isAttacking = false;
};
// Main game update function
game.update = function () {
// Skip updates if player is dead
if (player && player.health <= 0) {
LK.showGameOver();
return;
}
// Update player
if (player) {
player.update();
}
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
bullet.update();
// Check collision with enemies
for (var j = enemies.length - 1; j >= 0; j--) {
var enemy = enemies[j];
if (bullet.intersects(enemy)) {
enemy.takeDamage(enemy.health); // One-hit death
// Remove bullet
bullet.destroy();
bullets.splice(i, 1);
break;
}
}
}
// Update enemies
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
enemy.update();
}
// Removed wave progression logic
};
// Initialize the game
initGame();
top down defend scifi strong hold. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
top down scifi image military slugish tank. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
brutal fire explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
dark brown top down wide meadow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows