User prompt
Agrégale rotación a los caminos
Code edit (1 edits merged)
Please save this source code
User prompt
Crea un objeto llamado camino, asignarles una transparencia de 0.2, haz que las torres no se puedan colocar en el
User prompt
Elimina las upgrade de dmg, alcance y carencia de disparos. Agrega 2 marcos de izquierda a derecha aprovechando lo alto de UI. Un botón de comprar. La mejora de la izquierda es dmg +1 el de la izquierda carencia de disparos +30%
User prompt
Elimina torre rápida y los otros 3 botones
User prompt
Elimina los textos de info, remplaza info menú por upgrade menú
Code edit (2 edits merged)
Please save this source code
User prompt
Remplaza los valores de damage a 1. Haz que 1 = 1 capa, 2 = 2 capas
User prompt
Cambia damage para que 1 sea 1 capa y 2 dos, etc
User prompt
Agrégale al test de enemigo vida en forma de capas, verde -> azul -> rojo ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Haz los textos de info cortos
Code edit (1 edits merged)
Please save this source code
User prompt
Desplaza tower info text al lado izquierdo y alineación izquierda
User prompt
Reposiciona los textos creando dos columnas de dos filas debido a que total damage no se ve
User prompt
Separa los textos de stat en dos columnas en el lado izquierdo y el botón de borrar al lado derecho
User prompt
Reposiciona y aumenta de tamaño los textos de info menú para aprovechar todo el largo de UI
User prompt
Reposiciona los textos de info menú para aprovechar todo UI
User prompt
Mejora la apariencia de menú info aprovechando todo UI
User prompt
El texto de total damage no se actualiza cuando se está en el menú info
User prompt
Haz que el texto de tota daño se actualice cuando está el menú abierto
User prompt
Agrega una variable local a cada torre que muestre el daño realizado
User prompt
Haz que teste enemy ni se mueva
User prompt
Agrega un botón para eliminar torre en info torre
User prompt
Haz una función reusable para fast tower y tower así ahorrar en líneas de codigo
User prompt
Optimiza la creación de torres usando funciones reusables
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('Bala', {
anchorX: 0.5,
anchorY: 0.5
});
self.target = null;
self.speed = 600; // pixels per second
self.damage = 0;
self.update = function () {
if (self.target && self.target.parent) {
// Calculate direction to target
var dx = self.target.x - self.x;
var dy = self.target.y - self.y;
var distanceSquared = dx * dx + dy * dy;
// If close enough to target, hit it (using squared distance to avoid sqrt)
if (distanceSquared < 400) {
// 20 * 20 = 400
// Apply damage to enemy using its takeDamage method
if (self.target.takeDamage) {
self.target.takeDamage(self.damage);
}
// Add damage to tower's total damage counter
if (self.towerRef && self.towerRef.parent) {
self.towerRef.totalDamage += self.damage;
}
// Remove bullet
self.destroy();
return;
}
// Move towards target
var distance = Math.sqrt(distanceSquared);
var moveX = dx / distance * self.speed * frameTime; // 60 FPS
var moveY = dy / distance * self.speed * frameTime;
self.x += moveX;
self.y += moveY;
// Rotate bullet to face target
self.rotation = Math.atan2(dy, dx);
} else {
// Target is gone, remove bullet
self.destroy();
}
};
return self;
});
// Reusable tower creation function
var Gameplay = Container.expand(function () {
var self = Container.call(this);
var gameplayGraphics = self.attachAsset('gameplayBackground', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var UI = Container.expand(function () {
var self = Container.call(this);
var uiGraphics = self.attachAsset('uiBackground', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Reusable tower creation function
function createTowerBase(params) {
return Container.expand(function () {
var self = Container.call(this);
// Tower parameters
self.damage = params.damage;
self.cadence = params.cadence;
self.range = params.range;
self.rangeSquared = self.range * self.range; // Cache squared range for optimization
self.totalDamage = 0; // Track total damage dealt by this tower
var areaGraphics = self.attachAsset('Area', {
anchorX: 0.5,
anchorY: 0.5
});
// Scale the area to match the tower's actual range
var areaScale = self.range * 2 / 100; // Area asset is 100x100, so scale to range diameter
areaGraphics.scaleX = areaScale;
areaGraphics.scaleY = areaScale;
areaGraphics.alpha = 0.3;
areaGraphics.visible = false; // Hide range area by default
var towerGraphics = self.attachAsset(params.asset, {
anchorX: 0.5,
anchorY: 0.5
});
// Method to show range area
self.showRange = function () {
areaGraphics.visible = true;
};
// Method to hide range area
self.hideRange = function () {
areaGraphics.visible = false;
};
// Tower selection state
self.isSelected = false;
// Tower placement state
self.isPlaced = false;
// Shooting properties
self.lastShotTime = 0;
self.bullets = [];
// Method to find enemies in range
self.findEnemiesInRange = function () {
var enemies = [];
// Check if enemyTest is in range
if (enemyTest && enemyTest.parent) {
var dx = enemyTest.x - self.x;
var dy = enemyTest.y - self.y;
var distanceSquared = dx * dx + dy * dy;
if (distanceSquared <= self.rangeSquared) {
enemies.push(enemyTest);
}
}
return enemies;
};
// Method to shoot at target
self.shoot = function (target) {
var currentTime = Date.now();
if (currentTime - self.lastShotTime >= self.cadence) {
var bullet = new Bullet();
// Calculate direction to target for bullet offset
var dx = target.x - self.x;
var dy = target.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var offsetDistance = 50; // Distance to spawn bullet ahead of tower
// Spawn bullet slightly ahead in the direction of the target
bullet.x = self.x + dx / distance * offsetDistance;
bullet.y = self.y + dy / distance * offsetDistance;
bullet.target = target;
bullet.damage = self.damage;
bullet.towerRef = self; // Store reference to the tower that fired this bullet
self.bullets.push(bullet);
game.addChild(bullet);
self.lastShotTime = currentTime;
// Play bullet shooting sound
LK.getSound('Balababa').play();
// Add squash animation to tower
tween.stop(towerGraphics, {
scaleX: true
}); // Stop any existing scale tweens
tween(towerGraphics, {
scaleX: 0.7
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(towerGraphics, {
scaleX: 1.0
}, {
duration: 150,
easing: tween.easeOut
});
}
});
}
};
// Update method for tower
self.update = function () {
// Clean up destroyed bullets
for (var i = self.bullets.length - 1; i >= 0; i--) {
if (!self.bullets[i].parent) {
self.bullets.splice(i, 1);
}
}
// Only shoot if tower is placed (check cached status)
if (self.isPlaced) {
// Find and shoot at enemies
var enemies = self.findEnemiesInRange();
if (enemies.length > 0) {
var target = enemies[0];
// Calculate angle to target
var dx = target.x - self.x;
var dy = target.y - self.y;
var targetAngle = Math.atan2(dy, dx);
// Rotate tower to face target
towerGraphics.rotation = targetAngle;
// Flip tower horizontally if target is on the left side
if (dx < 0) {
towerGraphics.scaleY = -1; // Flip on Y axis when target is to the left
} else {
towerGraphics.scaleY = 1; // Normal orientation when target is to the right
}
// Shoot at the first enemy found
self.shoot(target);
}
}
};
// Handle tower selection
self.down = function (x, y, obj) {
// Deselect all other towers first
for (var i = 0; i < placedTowers.length; i++) {
if (placedTowers[i] !== self) {
placedTowers[i].isSelected = false;
placedTowers[i].hideRange();
}
}
// Toggle selection for this tower
self.isSelected = !self.isSelected;
if (self.isSelected) {
self.showRange();
updateTowerUpgrade(self); // Update UI with this tower's upgrade options
} else {
self.hideRange();
updateTowerUpgrade(null); // Clear UI when deselected
}
};
return self;
});
}
var Tower = createTowerBase({
damage: 1,
// Damage dealt per shot
cadence: 1000,
// Time between shots in milliseconds (1 second)
range: 400,
// Range in pixels
asset: 'torreInicial'
});
var draggedTower = null;
var isDragging = false;
var placedTowers = []; // Track all placed towers
// Cache frequently used values
var gameplayBounds = null;
var uiBounds = null;
var frameTime = 1 / 60; // Cache frame time calculation
// Reusable tower creation function that accepts tower constructor
function createTowerButton(color, x, y, TowerClass) {
var buttonBG = game.addChild(LK.getAsset('BGbuttonTower', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
}));
buttonBG.x = x;
buttonBG.y = y;
var button = game.addChild(new TowerClass());
button.x = x;
button.y = y;
button.tint = color;
// Store reference to button background for easy access
button.buttonBG = buttonBG;
button.down = function (x, y, obj) {
isDragging = true;
draggedTower = game.addChild(new TowerClass());
draggedTower.x = button.x;
draggedTower.y = button.y;
draggedTower.alpha = 0.7;
draggedTower.tint = color;
draggedTower.showRange(); // Show range area when dragging
};
return button;
}
// Game down handler to deselect towers when clicking on gameplay area
game.down = function (x, y, obj) {
// Check if click is in gameplay area (not on UI or towers)
var gameplayBounds = getGameplayBounds();
var clickInGameplay = x >= gameplayBounds.left && x <= gameplayBounds.right && y >= gameplayBounds.top && y <= gameplayBounds.bottom;
if (clickInGameplay) {
// Deselect all towers
for (var i = 0; i < placedTowers.length; i++) {
placedTowers[i].isSelected = false;
placedTowers[i].hideRange();
}
updateTowerUpgrade(null); // Clear tower upgrade when no tower is selected
}
};
// Helper functions for bounds calculations
function getGameplayBounds() {
return {
left: gameplay.x - gameplay.width / 2,
right: gameplay.x + gameplay.width / 2,
top: gameplay.y - gameplay.height / 2,
bottom: gameplay.y + gameplay.height / 2,
centerX: gameplay.x,
centerY: gameplay.y
};
}
function getUIBounds() {
return {
left: ui.x - ui.width / 2,
right: ui.x + ui.width / 2,
top: ui.y - ui.height / 2,
bottom: ui.y + ui.height / 2
};
}
function isPointInUI(x, y) {
var bounds = getUIBounds();
return x >= bounds.left && x <= bounds.right && y >= bounds.top && y <= bounds.bottom;
}
function calculateDragOffset(x, y) {
var bounds = getGameplayBounds();
var distanceFromCenterX = Math.abs(x - bounds.centerX);
var distanceFromCenterY = Math.abs(y - bounds.centerY);
var maxDistanceX = gameplay.width / 2;
var maxDistanceY = gameplay.height / 2;
var normalizedDistanceX = distanceFromCenterX / maxDistanceX;
var normalizedDistanceY = distanceFromCenterY / maxDistanceY;
var maxOffset = 200;
var offsetMagnitudeX = maxOffset * normalizedDistanceX;
var offsetMagnitudeY = maxOffset * normalizedDistanceY;
var offsetX = 0;
var offsetY = 0;
if (x >= bounds.centerX && y <= bounds.centerY) {
offsetX = offsetMagnitudeX;
offsetY = -offsetMagnitudeY;
} else if (x <= bounds.centerX && y <= bounds.centerY) {
offsetX = -offsetMagnitudeX;
offsetY = -offsetMagnitudeY;
} else if (x <= bounds.centerX && y >= bounds.centerY) {
offsetX = -offsetMagnitudeX;
offsetY = offsetMagnitudeY;
} else if (x >= bounds.centerX && y >= bounds.centerY) {
offsetX = offsetMagnitudeX;
offsetY = offsetMagnitudeY;
}
return {
offsetX: offsetX,
offsetY: offsetY
};
}
// Layer management - objects are added in z-index order (bottom to top)
// Background layer
var gameplay = game.addChild(new Gameplay());
gameplay.x = 1024;
gameplay.y = 1093;
// Game objects layer (towers will be added here)
// UI layer
var ui = game.addChild(new UI());
ui.x = 1024;
ui.y = 2459;
// Create single tower creation button
var towerButtons = [];
var startX = 1024; // Center the single button
towerButtons.push(createTowerButton(0xffffff, startX, 2459, Tower)); // White tower (normal)
// Create path objects with transparency
var caminoObjects = [];
// Add several camino objects to create a path
var caminoPositions = [{
x: 600,
y: 200
}, {
x: 800,
y: 1000
}, {
x: 1000,
y: 1100
}, {
x: 1200,
y: 1200
}, {
x: 1400,
y: 1300
}];
for (var i = 0; i < caminoPositions.length; i++) {
var camino = game.addChild(LK.getAsset('camino', {
anchorX: 0.5,
anchorY: 0.5
}));
camino.x = caminoPositions[i].x;
camino.y = caminoPositions[i].y;
camino.alpha = 0.2; // Set transparency to 0.2
// Add random rotation to each camino
camino.rotation = Math.random() * Math.PI * 2; // Random rotation between 0 and 2π radians
caminoObjects.push(camino);
}
// Enemy test object in the center with health layers
var enemyTest = game.addChild(LK.getAsset('Puntero', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 5,
color: 0x00ff00 // Start with green
}));
enemyTest.x = 1024;
enemyTest.y = 1093;
// Health system for enemy
enemyTest.maxHealth = 3; // Total health across all layers (3 layers)
enemyTest.currentHealth = enemyTest.maxHealth;
enemyTest.healthLayers = [{
min: 3,
max: 3,
color: 0x00ff00
},
// Green layer (1 HP)
{
min: 2,
max: 2,
color: 0x0000ff
},
// Blue layer (1 HP)
{
min: 1,
max: 1,
color: 0xff0000
} // Red layer (1 HP)
];
// Method to update enemy color based on health
enemyTest.updateHealthColor = function () {
for (var i = 0; i < this.healthLayers.length; i++) {
var layer = this.healthLayers[i];
if (this.currentHealth >= layer.min && this.currentHealth <= layer.max) {
// Animate color transition using tween
tween(this, {
tint: layer.color
}, {
duration: 200,
easing: tween.easeOut
});
break;
}
}
};
// Method to take damage
enemyTest.takeDamage = function (damage) {
var oldHealth = this.currentHealth;
this.currentHealth = Math.max(0, this.currentHealth - damage);
// Check if we crossed a layer boundary
var oldLayer = -1;
var newLayer = -1;
for (var i = 0; i < this.healthLayers.length; i++) {
var layer = this.healthLayers[i];
if (oldHealth >= layer.min && oldHealth <= layer.max) {
oldLayer = i;
}
if (this.currentHealth >= layer.min && this.currentHealth <= layer.max) {
newLayer = i;
}
}
// Update color if we changed layers or if this is the first damage
if (oldLayer !== newLayer || oldHealth === this.maxHealth) {
this.updateHealthColor();
}
// Check if enemy is dead
if (this.currentHealth <= 0) {
// Enemy is destroyed, respawn with full health
this.currentHealth = this.maxHealth;
this.updateHealthColor();
}
};
// Initialize enemy color
enemyTest.updateHealthColor();
// Enemy is now stationary - no movement code needed
// UI mode management
var UI_MODE_TOWER_CREATION = 'creation';
var UI_MODE_TOWER_UPGRADE = 'upgrade';
var currentUIMode = UI_MODE_TOWER_CREATION;
// UI Upgrade panel for selected tower
var towerUpgradeContainer = game.addChild(new Container());
towerUpgradeContainer.x = 1024;
towerUpgradeContainer.y = 2250;
var upgradeTitle = towerUpgradeContainer.addChild(new Text2('Upgrade Tower', {
size: 100,
fill: 0xFFFFFF
}));
upgradeTitle.anchor.set(0.5, 0);
upgradeTitle.x = 0;
upgradeTitle.y = 0;
// Left upgrade frame - Damage +1
var leftUpgradeFrame = towerUpgradeContainer.addChild(LK.getAsset('uiBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.4,
scaleY: 0.8
}));
leftUpgradeFrame.x = -400;
leftUpgradeFrame.y = 180;
leftUpgradeFrame.tint = 0x444444;
var leftUpgradeTitle = towerUpgradeContainer.addChild(new Text2('Damage +1', {
size: 60,
fill: 0xFFFFFF
}));
leftUpgradeTitle.anchor.set(0.5, 0.5);
leftUpgradeTitle.x = -400;
leftUpgradeTitle.y = 120;
var leftUpgradeBuyButton = towerUpgradeContainer.addChild(LK.getAsset('BGbuttonTower', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
}));
leftUpgradeBuyButton.x = -400;
leftUpgradeBuyButton.y = 220;
leftUpgradeBuyButton.tint = 0x00FF00;
var leftUpgradeBuyText = towerUpgradeContainer.addChild(new Text2('BUY', {
size: 50,
fill: 0x000000
}));
leftUpgradeBuyText.anchor.set(0.5, 0.5);
leftUpgradeBuyText.x = -400;
leftUpgradeBuyText.y = 220;
// Right upgrade frame - Fire Rate +30%
var rightUpgradeFrame = towerUpgradeContainer.addChild(LK.getAsset('uiBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.4,
scaleY: 0.8
}));
rightUpgradeFrame.x = 400;
rightUpgradeFrame.y = 180;
rightUpgradeFrame.tint = 0x444444;
var rightUpgradeTitle = towerUpgradeContainer.addChild(new Text2('Fire Rate +30%', {
size: 50,
fill: 0xFFFFFF
}));
rightUpgradeTitle.anchor.set(0.5, 0.5);
rightUpgradeTitle.x = 400;
rightUpgradeTitle.y = 120;
var rightUpgradeBuyButton = towerUpgradeContainer.addChild(LK.getAsset('BGbuttonTower', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
}));
rightUpgradeBuyButton.x = 400;
rightUpgradeBuyButton.y = 220;
rightUpgradeBuyButton.tint = 0x00FF00;
var rightUpgradeBuyText = towerUpgradeContainer.addChild(new Text2('BUY', {
size: 50,
fill: 0x000000
}));
rightUpgradeBuyText.anchor.set(0.5, 0.5);
rightUpgradeBuyText.x = 400;
rightUpgradeBuyText.y = 220;
// Store reference to currently selected tower
var selectedTowerForUpgrade = null;
// Function to switch UI modes
function setUIMode(mode) {
currentUIMode = mode;
if (mode === UI_MODE_TOWER_CREATION) {
// Show tower creation buttons and their backgrounds
for (var i = 0; i < towerButtons.length; i++) {
towerButtons[i].visible = true;
if (towerButtons[i].buttonBG) {
towerButtons[i].buttonBG.visible = true;
}
}
// Hide tower upgrade panel
towerUpgradeContainer.visible = false;
} else if (mode === UI_MODE_TOWER_UPGRADE) {
// Hide tower creation buttons and their backgrounds
for (var i = 0; i < towerButtons.length; i++) {
towerButtons[i].visible = false;
if (towerButtons[i].buttonBG) {
towerButtons[i].buttonBG.visible = false;
}
}
// Show tower upgrade panel
towerUpgradeContainer.visible = true;
}
}
// Function to update tower upgrade display
function updateTowerUpgrade(tower) {
if (tower) {
// Store reference to selected tower for upgrades
selectedTowerForUpgrade = tower;
// Switch to tower upgrade mode when a tower is selected
setUIMode(UI_MODE_TOWER_UPGRADE);
} else {
// Clear reference to selected tower
selectedTowerForUpgrade = null;
// Switch back to tower creation mode when no tower is selected
setUIMode(UI_MODE_TOWER_CREATION);
}
}
// Left upgrade buy button click handler - Damage +1
leftUpgradeBuyButton.down = function (x, y, obj) {
if (selectedTowerForUpgrade) {
selectedTowerForUpgrade.damage += 1;
// Flash button to show upgrade
LK.effects.flashObject(leftUpgradeBuyButton, 0xFFFFFF, 300);
}
};
// Right upgrade buy button click handler - Fire Rate +30%
rightUpgradeBuyButton.down = function (x, y, obj) {
if (selectedTowerForUpgrade) {
// Reduce cadence by 30% (faster shooting)
selectedTowerForUpgrade.cadence = Math.max(100, Math.floor(selectedTowerForUpgrade.cadence * 0.7));
// Flash button to show upgrade
LK.effects.flashObject(rightUpgradeBuyButton, 0xFFFFFF, 300);
}
};
// Initialize with no tower selected and tower creation mode
updateTowerUpgrade(null);
setUIMode(UI_MODE_TOWER_CREATION);
// Top overlay layer (pointer on top of everything)
var puntero = game.addChild(LK.getAsset('Puntero', {
anchorX: 0.5,
anchorY: 0.5
}));
puntero.x = 1024;
puntero.y = 1366;
puntero.alpha = 0;
// Game move handler for dragging
game.move = function (x, y, obj) {
puntero.x = x;
puntero.y = y;
if (isDragging && draggedTower) {
var gameplayBounds = getGameplayBounds();
var uiBounds = getUIBounds();
var offset = calculateDragOffset(x, y);
var targetX = x + offset.offsetX;
var targetY = y + offset.offsetY;
// Apply boundary constraints
if (targetY > uiBounds.top) {
targetY = uiBounds.top - 70;
}
if (targetY < gameplayBounds.top) {
targetY = gameplayBounds.top + 70;
}
if (targetX < uiBounds.left) {
targetX = uiBounds.left + 70;
}
if (targetX > uiBounds.right) {
targetX = uiBounds.right - 70;
}
// Check if tower is too close to existing towers
var minDistance = 200; // Minimum distance between towers
var minDistanceSquared = minDistance * minDistance;
var tooCloseToOtherTowers = false;
for (var i = 0; i < placedTowers.length; i++) {
var existingTower = placedTowers[i];
var dx = targetX - existingTower.x;
var dy = targetY - existingTower.y;
var distanceSquared = dx * dx + dy * dy;
if (distanceSquared < minDistanceSquared) {
tooCloseToOtherTowers = true;
break;
}
}
// Check if tower would be placed on camino path
var onCamino = false;
for (var i = 0; i < caminoObjects.length; i++) {
var camino = caminoObjects[i];
var dx = targetX - camino.x;
var dy = targetY - camino.y;
var distanceSquared = dx * dx + dy * dy;
// Check if tower center would overlap with camino (considering both sizes)
var overlapDistance = 150; // Reasonable overlap distance
if (distanceSquared < overlapDistance * overlapDistance) {
onCamino = true;
break;
}
}
// Update area tint based on pointer position and tower proximity
var pointerInUI = isPointInUI(puntero.x, puntero.y);
var cannotPlace = pointerInUI || tooCloseToOtherTowers || onCamino;
if (cannotPlace) {
// Apply red tint to area when cannot place tower
if (draggedTower.children[0]) {
draggedTower.children[0].tint = 0xff0000;
}
} else {
// Remove tint from area when tower can be placed
if (draggedTower.children[0]) {
draggedTower.children[0].tint = 0xFFFFFF;
}
}
// Smooth movement
var smoothness = 0.15;
draggedTower.x += (targetX - draggedTower.x) * smoothness;
draggedTower.y += (targetY - draggedTower.y) * smoothness;
}
};
// Game update handler
game.update = function () {
// No need to update info texts since we removed them
};
// Game release handler
game.up = function (x, y, obj) {
if (isDragging && draggedTower) {
var gameplayBounds = getGameplayBounds();
var uiBounds = getUIBounds();
var pointerInUI = isPointInUI(puntero.x, puntero.y);
var towerInUI = draggedTower.x >= uiBounds.left && draggedTower.x <= uiBounds.right && draggedTower.y >= uiBounds.top && draggedTower.y <= uiBounds.bottom;
if (pointerInUI || towerInUI) {
draggedTower.destroy();
} else if (draggedTower.x >= gameplayBounds.left && draggedTower.x <= gameplayBounds.right && draggedTower.y >= gameplayBounds.top && draggedTower.y <= gameplayBounds.bottom) {
// Check if tower is too close to existing towers
var minDistance = 200; // Minimum distance between towers
var minDistanceSquared = minDistance * minDistance;
var canPlace = true;
for (var i = 0; i < placedTowers.length; i++) {
var existingTower = placedTowers[i];
var dx = draggedTower.x - existingTower.x;
var dy = draggedTower.y - existingTower.y;
var distanceSquared = dx * dx + dy * dy;
if (distanceSquared < minDistanceSquared) {
canPlace = false;
break;
}
}
// Check if tower would be placed on camino path
if (canPlace) {
for (var i = 0; i < caminoObjects.length; i++) {
var camino = caminoObjects[i];
var dx = draggedTower.x - camino.x;
var dy = draggedTower.y - camino.y;
var distanceSquared = dx * dx + dy * dy;
var overlapDistance = 150;
if (distanceSquared < overlapDistance * overlapDistance) {
canPlace = false;
break;
}
}
}
if (canPlace) {
draggedTower.alpha = 1.0;
draggedTower.tint = 0xffffff;
draggedTower.hideRange(); // Hide range area when placed
draggedTower.isPlaced = true; // Set placement status
placedTowers.push(draggedTower); // Add to placed towers array
LK.getSound('TorreColocada').play(); // Play tower placement sound
} else {
// Tower is too close to existing towers, destroy it
draggedTower.destroy();
}
} else {
draggedTower.destroy();
}
isDragging = false;
draggedTower = null;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -377,8 +377,10 @@
}));
camino.x = caminoPositions[i].x;
camino.y = caminoPositions[i].y;
camino.alpha = 0.2; // Set transparency to 0.2
+ // Add random rotation to each camino
+ camino.rotation = Math.random() * Math.PI * 2; // Random rotation between 0 and 2π radians
caminoObjects.push(camino);
}
// Enemy test object in the center with health layers
var enemyTest = game.addChild(LK.getAsset('Puntero', {