User prompt
fes que si la ai arriba a 1000 gasti per forza coloci una torra o millori
User prompt
fes que si te torras danyadas posi una torra de curacio aprop
User prompt
posa una barra de vida a las torras
User prompt
posa a cada torra un assets difarent
User prompt
crea torras que curan a altras torras i torras que fan dany daria
User prompt
fes que cada cop que mato una torra emb donan diners
User prompt
Please fix the bug: 'TypeError: tower.canUpgrade is not a function' in or related to this line: 'if (tower.canUpgrade()) {' Line Number: 1623
User prompt
fes que el cami que seguiexen las units pasi per totas las torras
User prompt
crea varias clases de units
User prompt
crea varias classes de torres
User prompt
fes que las units ataquin a la base
User prompt
fes visibla las monedas que tinc
User prompt
fes que las torras es puguin millorar
User prompt
posa una barra de vida a las units
User prompt
fes que els meus units no ataquin
User prompt
treu la vida a las torres
User prompt
fes que las defensas no es puguin atacar
User prompt
fes que el enemic defensi la base
User prompt
fes casellas per posar torres que posara el enemic
User prompt
fes un cami per las units ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
crea un joc de dafensa la base pero tu ets el que ataca
User prompt
Base Assault
Initial prompt
crea un joc de dafensa la base pero tu ets el que ataca
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var AttackUnit = Container.expand(function () { var self = Container.call(this); var unitGraphics = self.attachAsset('attackUnit', { anchorX: 0.5, anchorY: 0.5 }); self.health = 100; self.maxHealth = 100; self.speed = 2; self.damage = 25; self.range = 150; self.shootCooldown = 0; self.target = null; self.lastX = 0; self.lastY = 0; self.currentWaypoint = 0; self.isMovingToWaypoint = false; self.pathWaypoints = [{ x: 400, y: self.y }, { x: 700, y: 1200 }, { x: 1000, y: 800 }, { x: 1300, y: 1400 }, { x: 1600, y: 1000 }]; self.followPath = function () { if (self.isMovingToWaypoint) return; if (self.currentWaypoint >= self.pathWaypoints.length) { // Reached end of path, move directly to base self.x += self.speed; return; } var waypoint = self.pathWaypoints[self.currentWaypoint]; var distance = Math.sqrt(Math.pow(waypoint.x - self.x, 2) + Math.pow(waypoint.y - self.y, 2)); var duration = distance / self.speed * 16.67; // Convert speed to ms (60fps = 16.67ms per frame) self.isMovingToWaypoint = true; tween(self, { x: waypoint.x, y: waypoint.y }, { duration: duration, easing: tween.linear, onFinish: function onFinish() { self.currentWaypoint++; self.isMovingToWaypoint = false; } }); }; self.update = function () { self.lastX = self.x; self.lastY = self.y; // Move towards enemy base using waypoints if (!self.target || !self.target.parent) { self.followPath(); } // Find target if (!self.target && enemyTowers.length > 0) { var closestTower = null; var closestDistance = Infinity; for (var i = 0; i < enemyTowers.length; i++) { var tower = enemyTowers[i]; var distance = Math.sqrt(Math.pow(tower.x - self.x, 2) + Math.pow(tower.y - self.y, 2)); if (distance < closestDistance) { closestDistance = distance; closestTower = tower; } } if (closestTower && closestDistance <= self.range) { self.target = closestTower; } } // Check if can target base if (!self.target && enemyBase) { var distanceToBase = Math.sqrt(Math.pow(enemyBase.x - self.x, 2) + Math.pow(enemyBase.y - self.y, 2)); if (distanceToBase <= self.range) { self.target = enemyBase; } } // Shoot at target if (self.target && self.shootCooldown <= 0) { var bullet = new UnitBullet(); bullet.x = self.x; bullet.y = self.y; bullet.target = self.target; bullet.damage = self.damage; unitBullets.push(bullet); game.addChild(bullet); LK.getSound('shoot').play(); self.shootCooldown = 60; // 1 second at 60fps } if (self.shootCooldown > 0) { self.shootCooldown--; } }; self.takeDamage = function (damage) { self.health -= damage; if (self.health <= 0) { return true; // Unit is dead } return false; }; return self; }); var EnemyBase = Container.expand(function () { var self = Container.call(this); var baseGraphics = self.attachAsset('enemyBase', { anchorX: 0.5, anchorY: 0.5 }); self.health = 500; self.maxHealth = 500; self.takeDamage = function (damage) { self.health -= damage; LK.effects.flashObject(self, 0xff0000, 300); if (self.health <= 0) { return true; // Base destroyed - player wins! } return false; }; return self; }); // Game arrays to track entities var EnemyTower = Container.expand(function () { var self = Container.call(this); var towerGraphics = self.attachAsset('enemyTower', { anchorX: 0.5, anchorY: 0.5 }); self.health = 150; self.maxHealth = 150; self.range = 200; self.damage = 30; self.shootCooldown = 0; self.target = null; self.update = function () { // Find target if (!self.target || !self.target.parent) { self.target = null; var closestUnit = null; var closestDistance = Infinity; for (var i = 0; i < playerUnits.length; i++) { var unit = playerUnits[i]; var distance = Math.sqrt(Math.pow(unit.x - self.x, 2) + Math.pow(unit.y - self.y, 2)); if (distance < closestDistance && distance <= self.range) { closestDistance = distance; closestUnit = unit; } } self.target = closestUnit; } // Shoot at target if (self.target && self.shootCooldown <= 0) { var bullet = new TowerBullet(); bullet.x = self.x; bullet.y = self.y; bullet.target = self.target; bullet.damage = self.damage; towerBullets.push(bullet); game.addChild(bullet); LK.getSound('shoot').play(); self.shootCooldown = 90; // 1.5 seconds at 60fps } if (self.shootCooldown > 0) { self.shootCooldown--; } }; self.takeDamage = function (damage) { self.health -= damage; LK.effects.flashObject(self, 0xff0000, 200); if (self.health <= 0) { return true; // Tower is destroyed } return false; }; return self; }); var TowerBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('towerBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 6; self.target = null; self.damage = 30; self.update = function () { if (!self.target || !self.target.parent) { // Target destroyed, remove bullet return; } // Move towards target var dx = self.target.x - self.x; var dy = self.target.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 10) { // Hit target if (self.target.takeDamage) { self.target.takeDamage(self.damage); LK.getSound('hit').play(); } return; // Bullet will be removed } // Normalize and move self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; }; return self; }); var UnitBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('unitBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.target = null; self.damage = 25; self.update = function () { if (!self.target || !self.target.parent) { // Target destroyed, remove bullet return; } // Move towards target var dx = self.target.x - self.x; var dy = self.target.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 10) { // Hit target if (self.target.takeDamage) { self.target.takeDamage(self.damage); LK.getSound('hit').play(); } return; // Bullet will be removed } // Normalize and move self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2d5016 }); /**** * Game Code ****/ // Game arrays to track entities // Initialize game assets var playerUnits = []; var enemyTowers = []; var unitBullets = []; var towerBullets = []; var enemyBase; // Game resources var coins = 150; var unitCost = 50; // UI Elements var coinsText = new Text2('Coins: ' + coins, { size: 60, fill: 0xFFFFFF }); coinsText.anchor.set(0, 0); LK.gui.topRight.addChild(coinsText); var healthText = new Text2('Base Health: 500', { size: 50, fill: 0xFFFFFF }); healthText.anchor.set(0.5, 0); LK.gui.top.addChild(healthText); var spawnButton = new Text2('SPAWN UNIT (50 coins)', { size: 50, fill: 0x00FF00 }); spawnButton.anchor.set(0.5, 1); spawnButton.interactive = true; spawnButton.down = function () { if (coins >= unitCost) { spawnUnit(); } }; LK.gui.bottom.addChild(spawnButton); // Create enemy base enemyBase = game.addChild(new EnemyBase()); enemyBase.x = 1800; enemyBase.y = 2732 / 2; // Create enemy towers for (var i = 0; i < 4; i++) { var tower = new EnemyTower(); tower.x = 1200 + i % 2 * 200; tower.y = 800 + Math.floor(i / 2) * 400; enemyTowers.push(tower); game.addChild(tower); } function spawnUnit() { if (coins >= unitCost) { coins -= unitCost; coinsText.setText('Coins: ' + coins); var unit = new AttackUnit(); unit.x = 100; unit.y = 500 + playerUnits.length % 5 * 150; // Set custom waypoints based on spawn position to create varied paths unit.pathWaypoints = [{ x: 400, y: unit.y }, { x: 700, y: unit.y < 1366 ? 1200 : 800 }, { x: 1000, y: unit.y < 1366 ? 800 : 1400 }, { x: 1300, y: unit.y < 1366 ? 1400 : 1000 }, { x: 1600, y: 1366 }]; playerUnits.push(unit); game.addChild(unit); LK.getSound('unitSpawn').play(); } } // Coin generation timer var coinTimer = 0; // Touch controls for spawning units game.down = function (x, y, obj) { if (coins >= unitCost) { spawnUnit(); } }; game.update = function () { // Generate coins over time coinTimer++; if (coinTimer >= 120) { // Every 2 seconds coins += 25; coinsText.setText('Coins: ' + coins); coinTimer = 0; } // Update unit bullets for (var i = unitBullets.length - 1; i >= 0; i--) { var bullet = unitBullets[i]; if (!bullet.target || !bullet.target.parent) { bullet.destroy(); unitBullets.splice(i, 1); continue; } var dx = bullet.target.x - bullet.x; var dy = bullet.target.y - bullet.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 15) { // Hit target var isDead = bullet.target.takeDamage(bullet.damage); if (isDead) { // Remove from appropriate array if (bullet.target === enemyBase) { // Player wins! LK.effects.flashScreen(0x00ff00, 2000); LK.showYouWin(); return; } else { // Remove tower for (var j = 0; j < enemyTowers.length; j++) { if (enemyTowers[j] === bullet.target) { enemyTowers[j].destroy(); enemyTowers.splice(j, 1); coins += 75; // Bonus for destroying tower coinsText.setText('Coins: ' + coins); break; } } } } bullet.destroy(); unitBullets.splice(i, 1); } } // Update tower bullets for (var i = towerBullets.length - 1; i >= 0; i--) { var bullet = towerBullets[i]; if (!bullet.target || !bullet.target.parent) { bullet.destroy(); towerBullets.splice(i, 1); continue; } var dx = bullet.target.x - bullet.x; var dy = bullet.target.y - bullet.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 15) { // Hit target var isDead = bullet.target.takeDamage(bullet.damage); if (isDead) { // Remove unit for (var j = 0; j < playerUnits.length; j++) { if (playerUnits[j] === bullet.target) { playerUnits[j].destroy(); playerUnits.splice(j, 1); break; } } } bullet.destroy(); towerBullets.splice(i, 1); } } // Check if player has no units and insufficient coins (lose condition) if (playerUnits.length === 0 && coins < unitCost) { // Check if there are still towers or base with health if (enemyTowers.length > 0 || enemyBase && enemyBase.health > 0) { LK.effects.flashScreen(0xff0000, 2000); LK.showGameOver(); return; } } // Update base health display if (enemyBase) { healthText.setText('Base Health: ' + enemyBase.health); } };
===================================================================
--- original.js
+++ change.js
@@ -1,5 +1,10 @@
/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
* Classes
****/
var AttackUnit = Container.expand(function () {
var self = Container.call(this);
@@ -15,14 +20,55 @@
self.shootCooldown = 0;
self.target = null;
self.lastX = 0;
self.lastY = 0;
+ self.currentWaypoint = 0;
+ self.isMovingToWaypoint = false;
+ self.pathWaypoints = [{
+ x: 400,
+ y: self.y
+ }, {
+ x: 700,
+ y: 1200
+ }, {
+ x: 1000,
+ y: 800
+ }, {
+ x: 1300,
+ y: 1400
+ }, {
+ x: 1600,
+ y: 1000
+ }];
+ self.followPath = function () {
+ if (self.isMovingToWaypoint) return;
+ if (self.currentWaypoint >= self.pathWaypoints.length) {
+ // Reached end of path, move directly to base
+ self.x += self.speed;
+ return;
+ }
+ var waypoint = self.pathWaypoints[self.currentWaypoint];
+ var distance = Math.sqrt(Math.pow(waypoint.x - self.x, 2) + Math.pow(waypoint.y - self.y, 2));
+ var duration = distance / self.speed * 16.67; // Convert speed to ms (60fps = 16.67ms per frame)
+ self.isMovingToWaypoint = true;
+ tween(self, {
+ x: waypoint.x,
+ y: waypoint.y
+ }, {
+ duration: duration,
+ easing: tween.linear,
+ onFinish: function onFinish() {
+ self.currentWaypoint++;
+ self.isMovingToWaypoint = false;
+ }
+ });
+ };
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
- // Move towards enemy base
+ // Move towards enemy base using waypoints
if (!self.target || !self.target.parent) {
- self.x += self.speed;
+ self.followPath();
}
// Find target
if (!self.target && enemyTowers.length > 0) {
var closestTower = null;
@@ -272,8 +318,25 @@
coinsText.setText('Coins: ' + coins);
var unit = new AttackUnit();
unit.x = 100;
unit.y = 500 + playerUnits.length % 5 * 150;
+ // Set custom waypoints based on spawn position to create varied paths
+ unit.pathWaypoints = [{
+ x: 400,
+ y: unit.y
+ }, {
+ x: 700,
+ y: unit.y < 1366 ? 1200 : 800
+ }, {
+ x: 1000,
+ y: unit.y < 1366 ? 800 : 1400
+ }, {
+ x: 1300,
+ y: unit.y < 1366 ? 1400 : 1000
+ }, {
+ x: 1600,
+ y: 1366
+ }];
playerUnits.push(unit);
game.addChild(unit);
LK.getSound('unitSpawn').play();
}
coinIcon. In-Game asset. 2d. High contrast. No shadows
enemyBase. In-Game asset. 2d. High contrast. No shadows
enemyTower. In-Game asset. 2d. High contrast. No shadows
towerBullet. In-Game asset. 2d. High contrast. No shadows
towerSlot. In-Game asset. 2d. High contrast. No shadows
upgradeIndicator. In-Game asset. 2d. High contrast. No shadows
heavyTowerAsset. In-Game asset. 2d. High contrast. No shadows
fastTowerAsset. In-Game asset. 2d. High contrast. No shadows
healTowerAsset. In-Game asset. 2d. High contrast. No shadows
sniperTowerAsset. In-Game asset. 2d. High contrast. No shadows
areaTowerAsset. In-Game asset. 2d. High contrast. No shadows
meleeUnitAsset. In-Game asset. 2d. High contrast. No shadows
laserTowerAsset. In-Game asset. 2d. High contrast. No shadows
poisonTowerAsset. In-Game asset. 2d. High contrast. No shadows
slowTowerAsset. In-Game asset. 2d. High contrast. No shadows
resurrectionTowerAsset. In-Game asset. 2d. High contrast. No shadows