User prompt
Add a visual button to erase the towers and add a separate asset for this.
User prompt
It should say which section you are in when you run away to the left.
User prompt
After 10 episodes are finished, let episode 2 come and then go on with 3, 4, 5, and so on.
User prompt
add a health bar to enemy soldiers ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Let the boss come in the 10th wave.
User prompt
Let the towers turn to the person they hit. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
increase the range of the towers
User prompt
Let each tower have its own special bullet.
User prompt
Let the laser gun shoot laser.
User prompt
Add 3 more towers
User prompt
Write how much the towers will ask for.
Code edit (1 edits merged)
Please save this source code
User prompt
War Simulator 3
Initial prompt
make a war game the name is war simulator 3
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Bullet = Container.expand(function (startX, startY, targetX, targetY, damage) { var self = Container.call(this); self.graphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.x = startX; self.y = startY; self.damage = damage; self.speed = 8; var dx = targetX - startX; var dy = targetY - startY; var distance = Math.sqrt(dx * dx + dy * dy); self.velocityX = dx / distance * self.speed; self.velocityY = dy / distance * self.speed; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; }; return self; }); var Enemy = Container.expand(function (enemyType) { var self = Container.call(this); self.enemyType = enemyType; self.health = 60; self.maxHealth = 60; self.damage = 15; self.speed = 1; self.targetX = 1024; self.targetY = 1366; if (enemyType === 'tank') { self.health = 120; self.maxHealth = 120; self.damage = 30; self.speed = 0.8; self.graphics = self.attachAsset('enemyTank', { anchorX: 0.5, anchorY: 0.5 }); } else if (enemyType === 'soldier') { self.health = 50; self.maxHealth = 50; self.damage = 10; self.speed = 1.2; self.graphics = self.attachAsset('enemySoldier', { anchorX: 0.5, anchorY: 0.5 }); } self.takeDamage = function (damage) { self.health -= damage; if (self.health <= 0) { self.health = 0; return true; } return false; }; self.update = function () { // Move towards base var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 5) { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } }; return self; }); var GridCell = Container.expand(function (gridX, gridY) { var self = Container.call(this); self.gridX = gridX; self.gridY = gridY; self.occupied = false; self.unit = null; self.graphics = self.attachAsset('gridCell', { anchorX: 0.5, anchorY: 0.5, alpha: 0.3 }); self.down = function (x, y, obj) { if (!self.occupied && playerMoney >= selectedUnitCost) { deployUnit(self.gridX, self.gridY); } }; return self; }); var Unit = Container.expand(function (unitType) { var self = Container.call(this); self.unitType = unitType; self.health = 100; self.maxHealth = 100; self.attackDamage = 20; self.attackRange = 150; self.attackCooldown = 0; self.attackSpeed = 60; // frames between attacks self.cost = 50; // Set unit-specific properties if (unitType === 'tank') { self.health = 150; self.maxHealth = 150; self.attackDamage = 40; self.attackRange = 200; self.attackSpeed = 90; self.cost = 100; self.graphics = self.attachAsset('tank', { anchorX: 0.5, anchorY: 0.5 }); } else if (unitType === 'soldier') { self.health = 80; self.maxHealth = 80; self.attackDamage = 15; self.attackRange = 120; self.attackSpeed = 45; self.cost = 30; self.graphics = self.attachAsset('soldier', { anchorX: 0.5, anchorY: 0.5 }); } else if (unitType === 'aircraft') { self.health = 100; self.maxHealth = 100; self.attackDamage = 25; self.attackRange = 250; self.attackSpeed = 60; self.cost = 80; self.graphics = self.attachAsset('aircraft', { anchorX: 0.5, anchorY: 0.5 }); } self.takeDamage = function (damage) { self.health -= damage; if (self.health <= 0) { self.health = 0; return true; // unit destroyed } return false; }; self.canAttack = function () { return self.attackCooldown <= 0; }; self.attack = function (target) { if (self.canAttack()) { self.attackCooldown = self.attackSpeed; return true; } return false; }; self.update = function () { if (self.attackCooldown > 0) { self.attackCooldown--; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2F4F2F }); /**** * Game Code ****/ var GRID_SIZE = 120; var GRID_COLS = 8; var GRID_ROWS = 6; var GRID_START_X = 400; var GRID_START_Y = 800; // Game state variables var playerMoney = 200; var currentWave = 1; var maxWaves = 10; var enemiesThisWave = 0; var maxEnemiesThisWave = 3; var enemySpawnTimer = 0; var enemySpawnDelay = 120; var selectedUnitType = 'soldier'; var selectedUnitCost = 30; var gameState = 'playing'; // 'playing', 'gameOver', 'victory' var baseHealth = 100; var maxBaseHealth = 100; // Game arrays var playerUnits = []; var enemies = []; var bullets = []; var gridCells = []; // Create base var base = game.addChild(LK.getAsset('base', { anchorX: 0.5, anchorY: 0.5 })); base.x = 1024; base.y = 1366; // Create grid for (var row = 0; row < GRID_ROWS; row++) { for (var col = 0; col < GRID_COLS; col++) { var cell = new GridCell(col, row); cell.x = GRID_START_X + col * GRID_SIZE; cell.y = GRID_START_Y + row * GRID_SIZE; gridCells.push(cell); game.addChild(cell); } } // UI Elements var moneyText = new Text2('Money: $' + playerMoney, { size: 60, fill: 0xFFFFFF }); moneyText.anchor.set(0, 0); moneyText.x = 120; moneyText.y = 100; LK.gui.topLeft.addChild(moneyText); var waveText = new Text2('Wave: ' + currentWave + '/' + maxWaves, { size: 60, fill: 0xFFFFFF }); waveText.anchor.set(0.5, 0); LK.gui.top.addChild(waveText); var baseHealthText = new Text2('Base Health: ' + baseHealth, { size: 50, fill: 0xFFFFFF }); baseHealthText.anchor.set(0.5, 0); baseHealthText.y = 80; LK.gui.top.addChild(baseHealthText); // Unit selection buttons var soldierButton = LK.getAsset('soldier', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); soldierButton.x = 200; soldierButton.y = 200; LK.gui.topLeft.addChild(soldierButton); var tankButton = LK.getAsset('tank', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); tankButton.x = 300; tankButton.y = 200; LK.gui.topLeft.addChild(tankButton); var aircraftButton = LK.getAsset('aircraft', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.3, scaleY: 1.3 }); aircraftButton.x = 400; aircraftButton.y = 200; LK.gui.topLeft.addChild(aircraftButton); // Cost labels for unit buttons var soldierCostText = new Text2('$30', { size: 30, fill: 0xFFD700 }); soldierCostText.anchor.set(0.5, 0); soldierCostText.x = 200; soldierCostText.y = 250; LK.gui.topLeft.addChild(soldierCostText); var tankCostText = new Text2('$100', { size: 30, fill: 0xFFD700 }); tankCostText.anchor.set(0.5, 0); tankCostText.x = 300; tankCostText.y = 250; LK.gui.topLeft.addChild(tankCostText); var aircraftCostText = new Text2('$80', { size: 30, fill: 0xFFD700 }); aircraftCostText.anchor.set(0.5, 0); aircraftCostText.x = 400; aircraftCostText.y = 250; LK.gui.topLeft.addChild(aircraftCostText); // Button event handlers soldierButton.down = function () { selectedUnitType = 'soldier'; selectedUnitCost = 30; updateButtonSelection(); }; tankButton.down = function () { selectedUnitType = 'tank'; selectedUnitCost = 100; updateButtonSelection(); }; aircraftButton.down = function () { selectedUnitType = 'aircraft'; selectedUnitCost = 80; updateButtonSelection(); }; function updateButtonSelection() { soldierButton.alpha = selectedUnitType === 'soldier' ? 1.0 : 0.6; tankButton.alpha = selectedUnitType === 'tank' ? 1.0 : 0.6; aircraftButton.alpha = selectedUnitType === 'aircraft' ? 1.0 : 0.6; // Update cost label highlighting soldierCostText.alpha = selectedUnitType === 'soldier' ? 1.0 : 0.6; tankCostText.alpha = selectedUnitType === 'tank' ? 1.0 : 0.6; aircraftCostText.alpha = selectedUnitType === 'aircraft' ? 1.0 : 0.6; } function deployUnit(gridX, gridY) { if (playerMoney >= selectedUnitCost) { var unit = new Unit(selectedUnitType); unit.x = GRID_START_X + gridX * GRID_SIZE; unit.y = GRID_START_Y + gridY * GRID_SIZE; playerUnits.push(unit); game.addChild(unit); // Mark grid cell as occupied var cellIndex = gridY * GRID_COLS + gridX; gridCells[cellIndex].occupied = true; gridCells[cellIndex].unit = unit; playerMoney -= selectedUnitCost; moneyText.setText('Money: $' + playerMoney); LK.getSound('unitDeploy').play(); } } function spawnEnemy() { var enemyType = Math.random() < 0.6 ? 'soldier' : 'tank'; var enemy = new Enemy(enemyType); // Spawn from top of screen enemy.x = Math.random() * 1500 + 200; enemy.y = 100; enemies.push(enemy); game.addChild(enemy); enemiesThisWave++; } function findNearestEnemy(unit) { var nearestEnemy = null; var nearestDistance = unit.attackRange; for (var i = 0; i < enemies.length; i++) { var enemy = enemies[i]; var dx = enemy.x - unit.x; var dy = enemy.y - unit.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance <= nearestDistance) { nearestEnemy = enemy; nearestDistance = distance; } } return nearestEnemy; } function createBullet(startX, startY, targetX, targetY, damage) { var bullet = new Bullet(startX, startY, targetX, targetY, damage); bullets.push(bullet); game.addChild(bullet); LK.getSound('shoot').play(); } function checkWaveComplete() { if (enemiesThisWave >= maxEnemiesThisWave && enemies.length === 0) { currentWave++; if (currentWave > maxWaves) { gameState = 'victory'; LK.showYouWin(); return; } // Start next wave enemiesThisWave = 0; maxEnemiesThisWave = Math.min(3 + currentWave, 15); enemySpawnDelay = Math.max(60, 120 - currentWave * 5); playerMoney += 50 + currentWave * 10; waveText.setText('Wave: ' + currentWave + '/' + maxWaves); moneyText.setText('Money: $' + playerMoney); } } // Initialize selection updateButtonSelection(); game.update = function () { if (gameState !== 'playing') return; // Spawn enemies if (enemiesThisWave < maxEnemiesThisWave) { enemySpawnTimer++; if (enemySpawnTimer >= enemySpawnDelay) { spawnEnemy(); enemySpawnTimer = 0; } } // Update units and handle combat for (var i = 0; i < playerUnits.length; i++) { var unit = playerUnits[i]; var target = findNearestEnemy(unit); if (target && unit.canAttack()) { if (unit.attack(target)) { createBullet(unit.x, unit.y, target.x, target.y, unit.attackDamage); } } } // Update enemies for (var i = enemies.length - 1; i >= 0; i--) { var enemy = enemies[i]; // Check if enemy reached base var distanceToBase = Math.sqrt(Math.pow(enemy.x - base.x, 2) + Math.pow(enemy.y - base.y, 2)); if (distanceToBase < 100) { baseHealth -= enemy.damage; baseHealthText.setText('Base Health: ' + Math.max(0, baseHealth)); if (baseHealth <= 0) { gameState = 'gameOver'; LK.showGameOver(); return; } enemy.destroy(); enemies.splice(i, 1); continue; } } // Update bullets and check collisions for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; // Check if bullet is out of bounds if (bullet.x < 0 || bullet.x > 2048 || bullet.y < 0 || bullet.y > 2732) { bullet.destroy(); bullets.splice(i, 1); continue; } // Check bullet-enemy collisions for (var j = enemies.length - 1; j >= 0; j--) { var enemy = enemies[j]; if (bullet.intersects(enemy)) { if (enemy.takeDamage(bullet.damage)) { playerMoney += 10; moneyText.setText('Money: $' + playerMoney); LK.getSound('enemyHit').play(); enemy.destroy(); enemies.splice(j, 1); } bullet.destroy(); bullets.splice(i, 1); break; } } } checkWaveComplete(); };
===================================================================
--- original.js
+++ change.js
@@ -263,8 +263,33 @@
});
aircraftButton.x = 400;
aircraftButton.y = 200;
LK.gui.topLeft.addChild(aircraftButton);
+// Cost labels for unit buttons
+var soldierCostText = new Text2('$30', {
+ size: 30,
+ fill: 0xFFD700
+});
+soldierCostText.anchor.set(0.5, 0);
+soldierCostText.x = 200;
+soldierCostText.y = 250;
+LK.gui.topLeft.addChild(soldierCostText);
+var tankCostText = new Text2('$100', {
+ size: 30,
+ fill: 0xFFD700
+});
+tankCostText.anchor.set(0.5, 0);
+tankCostText.x = 300;
+tankCostText.y = 250;
+LK.gui.topLeft.addChild(tankCostText);
+var aircraftCostText = new Text2('$80', {
+ size: 30,
+ fill: 0xFFD700
+});
+aircraftCostText.anchor.set(0.5, 0);
+aircraftCostText.x = 400;
+aircraftCostText.y = 250;
+LK.gui.topLeft.addChild(aircraftCostText);
// Button event handlers
soldierButton.down = function () {
selectedUnitType = 'soldier';
selectedUnitCost = 30;
@@ -283,8 +308,12 @@
function updateButtonSelection() {
soldierButton.alpha = selectedUnitType === 'soldier' ? 1.0 : 0.6;
tankButton.alpha = selectedUnitType === 'tank' ? 1.0 : 0.6;
aircraftButton.alpha = selectedUnitType === 'aircraft' ? 1.0 : 0.6;
+ // Update cost label highlighting
+ soldierCostText.alpha = selectedUnitType === 'soldier' ? 1.0 : 0.6;
+ tankCostText.alpha = selectedUnitType === 'tank' ? 1.0 : 0.6;
+ aircraftCostText.alpha = selectedUnitType === 'aircraft' ? 1.0 : 0.6;
}
function deployUnit(gridX, gridY) {
if (playerMoney >= selectedUnitCost) {
var unit = new Unit(selectedUnitType);
make a bird's eye view tank. In-Game asset. 2d. High contrast. No shadows
create ultra realastic bullet. In-Game asset. 2d. High contrast. No shadows
Make a bird's eye view airplane.. In-Game asset. 2d. High contrast. No shadows
Create a beautiful place with grassy, earthy views, but it should not have a roof; it should have walls.. In-Game asset. 2d. High contrast. No shadows
The enemy soldiers should look at us from a bird's eye view, but the soldier should look forward with a weapon in hand.. In-Game asset. 2d. High contrast. No shadows
Let's look at soldiers from a bird's eye view, but the soldier should look back and have a weapon in hand.. In-Game asset. 2d. High contrast. No shadows
create a missile rocket. In-Game asset. 2d. High contrast. No shadows
create bullet. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
create artillery. In-Game asset. 2d. High contrast. No shadows
create motionless giant rock. In-Game asset. 2d. High contrast. No shadows
create gridcell. In-Game asset. 2d. High contrast. No shadows
bird's eye view laser weapon 1024x. In-Game asset. 2d. High contrast. No shadows