User prompt
add a power up that can kill the boss ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add boss
User prompt
Please fix the bug: 'TypeError: player.children[0].setHealth is not a function. (In 'player.children[0].setHealth(player.health)', 'player.children[0].setHealth' is undefined)' in or related to this line: 'player.children[0].setHealth(player.health); // Update health bar (healthBar is at index 0)' Line Number: 780
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toGlobal')' in or related to this line: 'var settingsPos = LK.gui.topRight.toLocal(obj.parent.toGlobal(obj.position));' Line Number: 726
User prompt
add a settings menu, have a button that opens the settings page when clicked, let's adjust the brightness, music and volume from the settings ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
If ammo drops to 0, we can't fire any more bullets.
User prompt
REMOVE INVENTORY SYSTEM
User prompt
When we buy power ups, let them show their effect in Dirk. Add ammo bar to inventory and have ammo packs in various places on the map so that we have more ammo when we buy them. ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toGlobal')' in or related to this line: 'var localPos = slot.toLocal(obj.parent.toGlobal(obj.position));' Line Number: 316
User prompt
The inventory button is too small, make it bigger
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toGlobal')' in or related to this line: 'var buttonPos = LK.gui.topRight.toLocal(obj.parent.toGlobal(obj.position));' Line Number: 589
User prompt
add inventory and inventory button
User prompt
add fight music
User prompt
Write Rombo:Arena Showdown instead of cube fight
User prompt
add start menu
User prompt
add bomb sound
User prompt
add enemy kill sound
User prompt
add bullet sound
User prompt
add enemy death animation ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
add death animation ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add a special power to the game to fill health ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Place some special power-ups in the game, a random power-up will come at a random time, for example 2x damage or a bomb ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
1. After killing opponents, too many opponents spawn, fix this bug
Code edit (1 edits merged)
Please save this source code
User prompt
Rombo: Arena Showdown
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var AmmoBar = Container.expand(function () {
var self = Container.call(this);
var bgBar = self.attachAsset('ammoBarBg', {
anchorX: 0.5,
anchorY: 0.5
});
var ammoBar = self.attachAsset('ammoBar', {
anchorX: 0.5,
anchorY: 0.5
});
self.maxAmmo = 100;
self.currentAmmo = 100;
self.setAmmo = function (ammo) {
self.currentAmmo = Math.max(0, Math.min(self.maxAmmo, ammo));
var ammoPercent = self.currentAmmo / self.maxAmmo;
ammoBar.scaleX = ammoPercent;
if (ammoPercent > 0.6) {
ammoBar.tint = 0x0088ff;
} else if (ammoPercent > 0.3) {
ammoBar.tint = 0xffaa00;
} else {
ammoBar.tint = 0xff4444;
}
};
return self;
});
var AmmoPack = Container.expand(function () {
var self = Container.call(this);
var ammoPackGraphics = self.attachAsset('ammoPack', {
anchorX: 0.5,
anchorY: 0.5
});
self.bobTimer = 0;
self.baseY = 0;
self.collected = false;
self.ammoAmount = 25;
self.update = function () {
self.bobTimer += 0.1;
self.y = self.baseY + Math.sin(self.bobTimer) * 10;
ammoPackGraphics.rotation += 0.03;
};
self.collect = function () {
if (self.collected) return;
self.collected = true;
LK.getSound('powerupPickup').play();
tween(self, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
if (player) {
player.addAmmo(self.ammoAmount);
}
};
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 12;
self.damage = damageBoostActive ? 50 : 25;
self.isPlayerBullet = true;
self.direction = {
x: 0,
y: 0
};
self.update = function () {
self.x += self.direction.x * self.speed;
self.y += self.direction.y * self.speed;
};
return self;
});
var Enemy = Container.expand(function (enemyType) {
var self = Container.call(this);
var assetName = 'enemy' + (enemyType || 1);
var enemyGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 75;
self.maxHealth = 75;
self.shootCooldown = 0;
self.shootDelay = 60;
self.speed = 2;
self.enemyType = enemyType || 1;
self.moveTimer = 0;
self.lastPlayerX = 0;
self.lastPlayerY = 0;
var healthBar = self.addChild(new HealthBar());
healthBar.y = -35;
healthBar.maxHealth = self.maxHealth;
healthBar.setHealth(self.health);
if (self.enemyType === 1) {
self.speed = 3;
self.shootDelay = 45;
} else if (self.enemyType === 2) {
self.speed = 1.5;
self.shootDelay = 40;
} else if (self.enemyType === 3) {
self.speed = 2.5;
self.shootDelay = 50;
}
self.takeDamage = function (damage) {
self.health -= damage;
healthBar.setHealth(self.health);
LK.effects.flashObject(self, 0xffffff, 200);
if (self.health <= 0) {
LK.getSound('enemyDeath').play();
LK.setScore(LK.getScore() + 100);
scoreText.setText(LK.getScore());
// Death animation
tween(self, {
scaleX: 0,
scaleY: 0,
rotation: Math.PI * 2,
alpha: 0
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
return true;
}
return false;
};
self.update = function () {
if (self.shootCooldown > 0) {
self.shootCooldown--;
}
self.moveTimer++;
if (player) {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (self.enemyType === 1) {
// Aggressive rusher
if (distance > 100) {
var moveX = dx / distance * self.speed;
var moveY = dy / distance * self.speed;
self.x += moveX;
self.y += moveY;
}
} else if (self.enemyType === 2) {
// Tactical shooter - keeps distance
if (distance < 200) {
var moveX = -(dx / distance) * self.speed;
var moveY = -(dy / distance) * self.speed;
self.x += moveX;
self.y += moveY;
} else if (distance > 300) {
var moveX = dx / distance * self.speed * 0.5;
var moveY = dy / distance * self.speed * 0.5;
self.x += moveX;
self.y += moveY;
}
} else if (self.enemyType === 3) {
// Flanking opponent - moves in circles
var angle = Math.atan2(dy, dx) + Math.PI / 2;
var circleRadius = 150;
if (distance > circleRadius + 50) {
var moveX = dx / distance * self.speed;
var moveY = dy / distance * self.speed;
self.x += moveX;
self.y += moveY;
} else {
self.x += Math.cos(angle) * self.speed;
self.y += Math.sin(angle) * self.speed;
}
}
// Keep enemies within arena bounds
self.x = Math.max(100, Math.min(1948, self.x));
self.y = Math.max(200, Math.min(2500, self.y));
// Shoot at player
if (self.shootCooldown <= 0 && distance < 400) {
self.shootAtPlayer();
self.shootCooldown = self.shootDelay;
}
}
};
self.shootAtPlayer = function () {
if (player) {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var bullet = new EnemyBullet();
bullet.x = self.x;
bullet.y = self.y;
bullet.direction.x = dx / distance;
bullet.direction.y = dy / distance;
enemyBullets.push(bullet);
game.addChild(bullet);
LK.getSound('bullet').play();
}
};
return self;
});
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('enemyBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.damage = 20;
self.isPlayerBullet = false;
self.direction = {
x: 0,
y: 0
};
self.update = function () {
self.x += self.direction.x * self.speed;
self.y += self.direction.y * self.speed;
};
return self;
});
var HealthBar = Container.expand(function () {
var self = Container.call(this);
var bgBar = self.attachAsset('healthBarBg', {
anchorX: 0.5,
anchorY: 0.5
});
var healthBar = self.attachAsset('healthBar', {
anchorX: 0.5,
anchorY: 0.5
});
self.maxHealth = 100;
self.currentHealth = 100;
self.setHealth = function (health) {
self.currentHealth = Math.max(0, Math.min(self.maxHealth, health));
var healthPercent = self.currentHealth / self.maxHealth;
healthBar.scaleX = healthPercent;
if (healthPercent > 0.6) {
healthBar.tint = 0x00ff00;
} else if (healthPercent > 0.3) {
healthBar.tint = 0xffff00;
} else {
healthBar.tint = 0xff0000;
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.maxHealth = 100;
self.shootCooldown = 0;
self.shootDelay = 15;
self.ammo = 100;
self.maxAmmo = 100;
var healthBar = self.addChild(new HealthBar());
healthBar.y = -40;
var ammoBar = self.addChild(new AmmoBar());
ammoBar.y = -55;
ammoBar.maxAmmo = self.maxAmmo;
ammoBar.setAmmo(self.ammo);
self.consumeAmmo = function (amount) {
self.ammo = Math.max(0, self.ammo - amount);
ammoBar.setAmmo(self.ammo);
return self.ammo > 0;
};
self.addAmmo = function (amount) {
self.ammo = Math.min(self.maxAmmo, self.ammo + amount);
ammoBar.setAmmo(self.ammo);
};
self.takeDamage = function (damage) {
self.health -= damage;
healthBar.setHealth(self.health);
LK.getSound('hit').play();
LK.effects.flashObject(self, 0xff0000, 300);
if (self.health <= 0) {
// Death animation
tween(self, {
scaleX: 0.5,
scaleY: 0.5,
rotation: Math.PI,
alpha: 0.3
}, {
duration: 800,
easing: tween.easeIn,
onFinish: function onFinish() {
LK.showGameOver();
}
});
}
};
self.update = function () {
if (self.shootCooldown > 0) {
self.shootCooldown--;
}
};
return self;
});
var PowerUp = Container.expand(function (powerType) {
var self = Container.call(this);
self.powerType = powerType || 'damage';
var assetName = 'powerup' + (powerType === 'damage' ? 'Damage' : powerType === 'bomb' ? 'Bomb' : 'Health');
var powerupGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
self.bobTimer = 0;
self.baseY = 0;
self.collected = false;
self.update = function () {
self.bobTimer += 0.1;
self.y = self.baseY + Math.sin(self.bobTimer) * 10;
powerupGraphics.rotation += 0.05;
};
self.collect = function () {
if (self.collected) return;
self.collected = true;
LK.getSound('powerupPickup').play();
tween(self, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
if (self.powerType === 'damage') {
activateDamageBoost();
} else if (self.powerType === 'bomb') {
activateBomb();
} else if (self.powerType === 'health') {
activateHealthBoost();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
var gameState = 'start'; // 'start', 'playing', 'gameOver'
var player = null;
var enemies = [];
var bullets = [];
var enemyBullets = [];
var wave = 1;
var enemiesKilled = 0;
var dragNode = null;
var isSpawningWave = false;
var powerups = [];
var ammoPacks = [];
var damageBoostActive = false;
var damageBoostTimer = 0;
var powerupSpawnTimer = 0;
var powerupSpawnInterval = 600; // 10 seconds at 60fps
var ammoPackSpawnTimer = 0;
var ammoPackSpawnInterval = 900; // 15 seconds at 60fps
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 50;
var waveText = new Text2('Wave: 1', {
size: 50,
fill: 0xFFFFFF
});
waveText.anchor.set(0, 0);
LK.gui.topRight.addChild(waveText);
waveText.x = -200;
waveText.y = 50;
// Start Menu UI
var titleText = new Text2('ROMBO: ARENA SHOWDOWN', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(titleText);
titleText.y = -200;
var startButton = new Text2('TAP TO START', {
size: 80,
fill: 0x00FF00
});
startButton.anchor.set(0.5, 0.5);
LK.gui.center.addChild(startButton);
startButton.y = 100;
var instructionText = new Text2('Drag your rombo to move • Auto-shoot enemy rombos\nCollect power-ups to survive the arena!', {
size: 45,
fill: 0xCCCCCC
});
instructionText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(instructionText);
instructionText.y = 250;
// Hide game UI initially
scoreText.visible = false;
waveText.visible = false;
// Start the game
function startGame() {
gameState = 'playing';
// Hide start menu
titleText.visible = false;
startButton.visible = false;
instructionText.visible = false;
// Show game UI
scoreText.visible = true;
waveText.visible = true;
// Initialize game
initializePlayer();
spawnEnemies();
// Start fight music
LK.playMusic('fightMusic');
}
// Initialize player
function initializePlayer() {
player = game.addChild(new Player());
player.x = 1024;
player.y = 1800;
}
// Initialize enemies for current wave
function spawnEnemies() {
enemies = [];
var enemyCount = Math.min(3, 2 + Math.floor(wave / 3));
for (var i = 0; i < enemyCount; i++) {
var enemyType = i % 3 + 1;
var enemy = game.addChild(new Enemy(enemyType));
// Spawn enemies at random positions around the arena
var angle = i / enemyCount * Math.PI * 2;
var radius = 300 + Math.random() * 200;
enemy.x = 1024 + Math.cos(angle) * radius;
enemy.y = 1000 + Math.sin(angle) * radius;
// Keep within bounds
enemy.x = Math.max(100, Math.min(1948, enemy.x));
enemy.y = Math.max(200, Math.min(2500, enemy.y));
enemies.push(enemy);
}
}
// Find nearest enemy to player
function findNearestEnemy() {
if (!player || enemies.length === 0) return null;
var nearestEnemy = null;
var nearestDistance = Infinity;
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
var dx = enemy.x - player.x;
var dy = enemy.y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < nearestDistance) {
nearestDistance = distance;
nearestEnemy = enemy;
}
}
return nearestDistance < 350 ? nearestEnemy : null;
}
// Player shooting
function playerShoot() {
if (!player || player.shootCooldown > 0) return;
if (player.ammo <= 0) return; // Can't shoot without ammo
var target = findNearestEnemy();
if (!target) return;
if (!player.consumeAmmo(1)) return; // Consume 1 ammo per shot
var dx = target.x - player.x;
var dy = target.y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
bullet.direction.x = dx / distance;
bullet.direction.y = dy / distance;
bullets.push(bullet);
game.addChild(bullet);
player.shootCooldown = player.shootDelay;
LK.getSound('shoot').play();
}
// Touch controls
function handleMove(x, y, obj) {
if (dragNode && player) {
player.x = x;
player.y = y;
// Keep player within arena bounds
player.x = Math.max(50, Math.min(1998, player.x));
player.y = Math.max(250, Math.min(2600, player.y));
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
if (gameState === 'start') {
startGame();
} else if (gameState === 'playing') {
if (player) {
dragNode = player;
handleMove(x, y, obj);
}
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Power-up functions
function activateDamageBoost() {
damageBoostActive = true;
damageBoostTimer = 300; // 5 seconds at 60fps
LK.effects.flashScreen(0x0088ff, 500);
}
function activateBomb() {
LK.getSound('bombSound').play();
LK.getSound('bombExplode').play();
LK.effects.flashScreen(0xff8800, 800);
// Damage all enemies
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
var enemyDied = enemy.takeDamage(50);
if (enemyDied) {
enemies.splice(i, 1);
enemiesKilled++;
}
}
// Clear all enemy bullets
for (var i = enemyBullets.length - 1; i >= 0; i--) {
enemyBullets[i].destroy();
}
enemyBullets = [];
}
function activateHealthBoost() {
if (player) {
var healAmount = 40;
player.health = Math.min(player.maxHealth, player.health + healAmount);
player.children[0].setHealth(player.health); // Update health bar (healthBar is at index 0)
LK.effects.flashScreen(0x00ff00, 500);
tween(player, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(player, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
}
}
function spawnRandomPowerup() {
var rand = Math.random();
var powerType;
if (rand < 0.4) {
powerType = 'damage';
} else if (rand < 0.7) {
powerType = 'health';
} else {
powerType = 'bomb';
}
var powerup = new PowerUp(powerType);
powerup.x = 200 + Math.random() * 1648;
powerup.y = 400 + Math.random() * 1800;
powerup.baseY = powerup.y;
powerups.push(powerup);
game.addChild(powerup);
}
function spawnAmmoPack() {
var ammoPack = new AmmoPack();
ammoPack.x = 200 + Math.random() * 1648;
ammoPack.y = 400 + Math.random() * 1800;
ammoPack.baseY = ammoPack.y;
ammoPacks.push(ammoPack);
game.addChild(ammoPack);
}
// Main game loop
game.update = function () {
// Only update game when playing
if (gameState !== 'playing') return;
// Handle damage boost timer
if (damageBoostActive) {
damageBoostTimer--;
if (damageBoostTimer <= 0) {
damageBoostActive = false;
}
}
// Handle power-up spawning
powerupSpawnTimer++;
if (powerupSpawnTimer >= powerupSpawnInterval) {
spawnRandomPowerup();
powerupSpawnTimer = 0;
powerupSpawnInterval = 600 + Math.random() * 600; // Random interval between 10-20 seconds
}
// Handle ammo pack spawning
ammoPackSpawnTimer++;
if (ammoPackSpawnTimer >= ammoPackSpawnInterval) {
spawnAmmoPack();
ammoPackSpawnTimer = 0;
ammoPackSpawnInterval = 900 + Math.random() * 600; // Random interval between 15-25 seconds
}
// Update power-ups
for (var i = powerups.length - 1; i >= 0; i--) {
var powerup = powerups[i];
if (player && powerup.intersects(player)) {
powerup.collect();
powerups.splice(i, 1);
}
}
// Update ammo packs
for (var i = ammoPacks.length - 1; i >= 0; i--) {
var ammoPack = ammoPacks[i];
if (player && ammoPack.intersects(player)) {
ammoPack.collect();
ammoPacks.splice(i, 1);
}
}
// Auto-shoot at nearest enemy
playerShoot();
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Check bounds
if (bullet.x < 0 || bullet.x > 2048 || bullet.y < 0 || bullet.y > 2732) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check collision with enemies
for (var j = enemies.length - 1; j >= 0; j--) {
var enemy = enemies[j];
if (bullet.intersects(enemy)) {
var enemyDied = enemy.takeDamage(bullet.damage);
bullet.destroy();
bullets.splice(i, 1);
if (enemyDied) {
enemies.splice(j, 1);
enemiesKilled++;
}
break;
}
}
}
// Update enemy bullets
for (var i = enemyBullets.length - 1; i >= 0; i--) {
var bullet = enemyBullets[i];
// Check bounds
if (bullet.x < 0 || bullet.x > 2048 || bullet.y < 0 || bullet.y > 2732) {
bullet.destroy();
enemyBullets.splice(i, 1);
continue;
}
// Check collision with player
if (player && bullet.intersects(player)) {
player.takeDamage(bullet.damage);
bullet.destroy();
enemyBullets.splice(i, 1);
}
}
// Check if wave is complete
if (enemies.length === 0 && !isSpawningWave) {
isSpawningWave = true;
wave++;
waveText.setText('Wave: ' + wave);
// Small delay before next wave
LK.setTimeout(function () {
spawnEnemies();
isSpawningWave = false;
}, 1000);
}
}; ===================================================================
--- original.js
+++ change.js
@@ -6,8 +6,69 @@
/****
* Classes
****/
+var AmmoBar = Container.expand(function () {
+ var self = Container.call(this);
+ var bgBar = self.attachAsset('ammoBarBg', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var ammoBar = self.attachAsset('ammoBar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.maxAmmo = 100;
+ self.currentAmmo = 100;
+ self.setAmmo = function (ammo) {
+ self.currentAmmo = Math.max(0, Math.min(self.maxAmmo, ammo));
+ var ammoPercent = self.currentAmmo / self.maxAmmo;
+ ammoBar.scaleX = ammoPercent;
+ if (ammoPercent > 0.6) {
+ ammoBar.tint = 0x0088ff;
+ } else if (ammoPercent > 0.3) {
+ ammoBar.tint = 0xffaa00;
+ } else {
+ ammoBar.tint = 0xff4444;
+ }
+ };
+ return self;
+});
+var AmmoPack = Container.expand(function () {
+ var self = Container.call(this);
+ var ammoPackGraphics = self.attachAsset('ammoPack', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.bobTimer = 0;
+ self.baseY = 0;
+ self.collected = false;
+ self.ammoAmount = 25;
+ self.update = function () {
+ self.bobTimer += 0.1;
+ self.y = self.baseY + Math.sin(self.bobTimer) * 10;
+ ammoPackGraphics.rotation += 0.03;
+ };
+ self.collect = function () {
+ if (self.collected) return;
+ self.collected = true;
+ LK.getSound('powerupPickup').play();
+ tween(self, {
+ scaleX: 0,
+ scaleY: 0,
+ alpha: 0
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ self.destroy();
+ }
+ });
+ if (player) {
+ player.addAmmo(self.ammoAmount);
+ }
+ };
+ return self;
+});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
@@ -206,10 +267,25 @@
self.health = 100;
self.maxHealth = 100;
self.shootCooldown = 0;
self.shootDelay = 15;
+ self.ammo = 100;
+ self.maxAmmo = 100;
var healthBar = self.addChild(new HealthBar());
healthBar.y = -40;
+ var ammoBar = self.addChild(new AmmoBar());
+ ammoBar.y = -55;
+ ammoBar.maxAmmo = self.maxAmmo;
+ ammoBar.setAmmo(self.ammo);
+ self.consumeAmmo = function (amount) {
+ self.ammo = Math.max(0, self.ammo - amount);
+ ammoBar.setAmmo(self.ammo);
+ return self.ammo > 0;
+ };
+ self.addAmmo = function (amount) {
+ self.ammo = Math.min(self.maxAmmo, self.ammo + amount);
+ ammoBar.setAmmo(self.ammo);
+ };
self.takeDamage = function (damage) {
self.health -= damage;
healthBar.setHealth(self.health);
LK.getSound('hit').play();
@@ -297,12 +373,15 @@
var enemiesKilled = 0;
var dragNode = null;
var isSpawningWave = false;
var powerups = [];
+var ammoPacks = [];
var damageBoostActive = false;
var damageBoostTimer = 0;
var powerupSpawnTimer = 0;
var powerupSpawnInterval = 600; // 10 seconds at 60fps
+var ammoPackSpawnTimer = 0;
+var ammoPackSpawnInterval = 900; // 15 seconds at 60fps
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
@@ -402,10 +481,12 @@
}
// Player shooting
function playerShoot() {
if (!player || player.shootCooldown > 0) return;
+ if (player.ammo <= 0) return; // Can't shoot without ammo
var target = findNearestEnemy();
if (!target) return;
+ if (!player.consumeAmmo(1)) return; // Consume 1 ammo per shot
var dx = target.x - player.x;
var dy = target.y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var bullet = new Bullet();
@@ -507,8 +588,16 @@
powerup.baseY = powerup.y;
powerups.push(powerup);
game.addChild(powerup);
}
+function spawnAmmoPack() {
+ var ammoPack = new AmmoPack();
+ ammoPack.x = 200 + Math.random() * 1648;
+ ammoPack.y = 400 + Math.random() * 1800;
+ ammoPack.baseY = ammoPack.y;
+ ammoPacks.push(ammoPack);
+ game.addChild(ammoPack);
+}
// Main game loop
game.update = function () {
// Only update game when playing
if (gameState !== 'playing') return;
@@ -525,16 +614,31 @@
spawnRandomPowerup();
powerupSpawnTimer = 0;
powerupSpawnInterval = 600 + Math.random() * 600; // Random interval between 10-20 seconds
}
+ // Handle ammo pack spawning
+ ammoPackSpawnTimer++;
+ if (ammoPackSpawnTimer >= ammoPackSpawnInterval) {
+ spawnAmmoPack();
+ ammoPackSpawnTimer = 0;
+ ammoPackSpawnInterval = 900 + Math.random() * 600; // Random interval between 15-25 seconds
+ }
// Update power-ups
for (var i = powerups.length - 1; i >= 0; i--) {
var powerup = powerups[i];
if (player && powerup.intersects(player)) {
powerup.collect();
powerups.splice(i, 1);
}
}
+ // Update ammo packs
+ for (var i = ammoPacks.length - 1; i >= 0; i--) {
+ var ammoPack = ammoPacks[i];
+ if (player && ammoPack.intersects(player)) {
+ ammoPack.collect();
+ ammoPacks.splice(i, 1);
+ }
+ }
// Auto-shoot at nearest enemy
playerShoot();
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
Bomb. In-Game asset. High contrast. No shadows. 2d
Heart. In-Game asset. 2d. High contrast. No shadows
Fire. In-Game asset. 2d. High contrast. No shadows
2D ammo pack. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Sharp katana with bloods. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat