User prompt
Haz que el Sprite de torre cambie por torreatack cuando ataque
User prompt
Vlcrea variables para vida y dinero
Code edit (1 edits merged)
Please save this source code
User prompt
Agrega una variable boleana llamada "ParhShow" cuando is true camino tiene 0.1 de transparencia, cuando es false 0. Pon la variable en false
User prompt
Muévelo al lado derecho y centralos en el eje Y
User prompt
Los textos no se ven
User prompt
Agrega 3 textos en el lado izquierdo de UI para mostrar money, life ando Wave
User prompt
Agrega tres textos en el lado izquierda Para moneda, vida y oleada
User prompt
Haz que el botón de colocar torres este a la izquierda
Code edit (4 edits merged)
Please save this source code
User prompt
Haz que las torres se puedan colocar un poco más cerca entre sí
Code edit (9 edits merged)
Please save this source code
User prompt
Please fix the bug: 'p is not defined' in or related to this line: 'var caminoPositions = [{' Line Number: 374
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Agrega 16 caminos más
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Agrega 8 caminos más
Code edit (1 edits merged)
Please save this source code
User prompt
Elimina el delay entre caminos ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Elimina la pausa
User prompt
Haz que enemy test se mueva suavemente de un camino a otro ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Haz que se les pueda asignar una rotación a los caminos
/**** * 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 7; 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(); // Change to attack sprite var attackSprite = self.attachAsset('TorreinicialAttack', { anchorX: 0.5, anchorY: 0.5 }); attackSprite.rotation = towerGraphics.rotation; attackSprite.scaleY = towerGraphics.scaleY; self.removeChild(towerGraphics); towerGraphics = attackSprite; // 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, onFinish: function onFinish() { // Change back to normal sprite after attack animation var normalSprite = self.attachAsset(params.asset, { anchorX: 0.5, anchorY: 0.5 }); normalSprite.rotation = towerGraphics.rotation; normalSprite.scaleY = towerGraphics.scaleY; self.removeChild(towerGraphics); towerGraphics = normalSprite; } }); } }); } }; // 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 = 400; // Position button on the left side 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: 890, y: 40, rotation: 12 }, { x: 650, y: 150, rotation: 70 }, { x: 500, y: 340, rotation: 5 }, { x: 500, y: 470, rotation: Math.PI }, { x: 550, y: 540, rotation: -Math.PI / 4 }, { x: 700, y: 620, rotation: 0 }, { x: 900, y: 620, rotation: 0 }, { x: 1100, y: 620, rotation: 0 }, { x: 1250, y: 650, rotation: -20 }, { x: 1420, y: 740, rotation: Math.PI / 4 }, { x: 1530, y: 880, rotation: Math.PI }, { x: 1510, y: 1080, rotation: -12 }, { x: 1380, y: 1210, rotation: 20 }, { x: 1180, y: 1300, rotation: 9 }, { x: 950, y: 1370, rotation: 20 }, { x: 750, y: 1480, rotation: 70 }, { x: 655, y: 1610, rotation: 0 }, { x: 610, y: 1750, rotation: 0 }, { x: 610, y: 1900, rotation: Math.PI / 2 }]; 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.rotation = caminoPositions[i].rotation; // Apply rotation from positions array camino.alpha = 0.2; // Set transparency to 0.2 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 })); // Set starting position to first camino waypoint enemyTest.x = caminoPositions[0].x; enemyTest.y = caminoPositions[0].y; // Path following properties enemyTest.currentWaypointIndex = 0; enemyTest.isMoving = false; // Method to move to next waypoint enemyTest.moveToNextWaypoint = function () { if (this.isMoving) { return; } // Don't start new movement if already moving this.currentWaypointIndex = (this.currentWaypointIndex + 1) % caminoPositions.length; var nextWaypoint = caminoPositions[this.currentWaypointIndex]; // Calculate distance for movement duration var dx = nextWaypoint.x - this.x; var dy = nextWaypoint.y - this.y; var distance = Math.sqrt(dx * dx + dy * dy); var speed = 200; // pixels per second var duration = distance / speed * 1000; // Convert to milliseconds this.isMoving = true; // Use tween for smooth movement tween(this, { x: nextWaypoint.x, y: nextWaypoint.y }, { duration: duration, easing: tween.linear, onFinish: function onFinish() { enemyTest.isMoving = false; // Move to next waypoint immediately without delay enemyTest.moveToNextWaypoint(); } }); }; // Start the movement after a short delay LK.setTimeout(function () { enemyTest.moveToNextWaypoint(); }, 1000); // Start moving after 1 second // 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); // Add money, life and wave UI texts on the right side, centered vertically var moneyText = new Text2('Money: 100', { size: 80, fill: 0xFFFF00 }); moneyText.anchor.set(1, 0.5); moneyText.x = 1900; moneyText.y = 2350; game.addChild(moneyText); var lifeText = new Text2('Life: 20', { size: 80, fill: 0xFF0000 }); lifeText.anchor.set(1, 0.5); lifeText.x = 1900; lifeText.y = 2450; game.addChild(lifeText); var waveText = new Text2('Wave: 1', { size: 80, fill: 0x00FF00 }); waveText.anchor.set(1, 0.5); waveText.x = 1900; waveText.y = 2550; game.addChild(waveText); // Initialize game variables var playerMoney = 100; var playerLife = 20; var currentWave = 1; var PathShow = false; // Boolean to control path visibility var vida = 20; // Player's life/health var dinero = 100; // Player's money/currency // 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 = 120; // 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 () { // Update UI texts with current values moneyText.setText('Money: ' + playerMoney); lifeText.setText('Life: ' + playerLife); waveText.setText('Wave: ' + currentWave); // Update path visibility based on PathShow variable for (var i = 0; i < caminoObjects.length; i++) { if (PathShow) { caminoObjects[i].alpha = 0.1; } else { caminoObjects[i].alpha = 0; } } }; // 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 = 170; // 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 = 170; 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
@@ -153,8 +153,17 @@
game.addChild(bullet);
self.lastShotTime = currentTime;
// Play bullet shooting sound
LK.getSound('Balababa').play();
+ // Change to attack sprite
+ var attackSprite = self.attachAsset('TorreinicialAttack', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ attackSprite.rotation = towerGraphics.rotation;
+ attackSprite.scaleY = towerGraphics.scaleY;
+ self.removeChild(towerGraphics);
+ towerGraphics = attackSprite;
// Add squash animation to tower
tween.stop(towerGraphics, {
scaleX: true
}); // Stop any existing scale tweens
@@ -167,9 +176,20 @@
tween(towerGraphics, {
scaleX: 1.0
}, {
duration: 150,
- easing: tween.easeOut
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ // Change back to normal sprite after attack animation
+ var normalSprite = self.attachAsset(params.asset, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ normalSprite.rotation = towerGraphics.rotation;
+ normalSprite.scaleY = towerGraphics.scaleY;
+ self.removeChild(towerGraphics);
+ towerGraphics = normalSprite;
+ }
});
}
});
}