User prompt
Oyun kasmaması için, Ram yenileme çalışması ekle.
User prompt
Yapay zeka hareketleri çok daha akıllıca olsun
User prompt
Oyuncu kulelerinin altında Player yazsın.
User prompt
Birim gönderimi, kule biriminin daima yarısı olsun.
User prompt
Düşman kulelerinin hareketleri aynı olmasın, hepsi farklı bir strateji sergilesin.
User prompt
Her düşmana rastgele bir isim ver. Sahip olduğu kulelerin alt kısmında düşman isimleri yazsın.
User prompt
Birimler sıra halinde değil de; Dağınık şekilde ilerlesinler.
User prompt
Oyun ekran boyutunun tamamını %50 oranında Büyüt.
User prompt
Birden fazla düşman olsun. Düşmanlar da birbirleri ile savaşabilsin.
User prompt
Oyun ekran boyutunun tamamını %50 oranında küçült.
User prompt
Birimler savaşırken küçük görsel oluştur. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
**Seçim vurguları**: Seçili kulelerin etrafında dönen renk halkaları - **Hedef göstergeleri**: Sürüklerken hedef kulenin renkli yanıp sönmesi ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Powerup geliştirmelerine de, düşmana asker gönderiyor gibi, asker gönderelim. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
**Güçlendirici objeler**: Haritada rastgele beliren, geçici güç veren objeler. Asker göndererek bunları aktif etme. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
**Özel kule tipleri**: Savunma kulesi (mor), hızlı saldırı kulesi (turuncu), üretim kulesi (altın)
User prompt
**Parçacık sistemleri**: Savaş sırasında patlama efektleri, kulelerde birim üretimi sırasında ışık parçacıkları ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
**Renk geçişleri**: Kulelerin sahiplik değişimi sırasında yumuşak renk geçişleri ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Kulelerde, ne kadar fazla birim varsa; birim üretim hızı ona nazaran bir tık fazla olsun.
User prompt
Sağ alt kenara Reset butonu ekle. Basınca herşey sıfırlansın.
User prompt
Seviye sayısını 3 yerine 10 yap. ona göre zorluk sistemi belirle.
User prompt
Başlangıçta, her zaman düşman kulesinden 10 birim fazla olacak şekilde başlasın.
User prompt
Maksimum asker sayısı 50 yerine 100 olsun.
User prompt
Game over olunca herşey sıfırdan başlasın.
User prompt
Oyun başlayınca 5 saniye rakip beklesin. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Düşman birlikleri ile karşılaşan askerler savaşsın ve birbirini yok etsin.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var PathLine = Container.expand(function () { var self = Container.call(this); self.points = []; self.graphics = []; self.setPath = function (points) { // Clear old graphics for (var i = 0; i < self.graphics.length; i++) { self.graphics[i].destroy(); } self.graphics = []; self.points = points; // Draw new path for (var i = 0; i < points.length - 1; i++) { var dist = Math.sqrt(Math.pow(points[i + 1].x - points[i].x, 2) + Math.pow(points[i + 1].y - points[i].y, 2)); var segments = Math.floor(dist / 20); for (var j = 0; j < segments; j++) { var t = j / segments; var dot = self.attachAsset('path', { anchorX: 0.5, anchorY: 0.5 }); dot.x = points[i].x + (points[i + 1].x - points[i].x) * t; dot.y = points[i].y + (points[i + 1].y - points[i].y) * t; dot.alpha = 0.5; self.graphics.push(dot); } } }; self.clear = function () { for (var i = 0; i < self.graphics.length; i++) { self.graphics[i].destroy(); } self.graphics = []; self.points = []; }; return self; }); var Tower = Container.expand(function () { var self = Container.call(this); self.owner = 0; // 0 = neutral, 1 = player, 2 = enemy self.unitCount = 0; self.maxUnits = 100; self.spawnRate = 30; // ticks between spawns self.lastSpawn = 0; var towerGraphics = self.attachAsset('tower', { anchorX: 0.5, anchorY: 0.5 }); self.countText = new Text2('0', { size: 60, fill: 0xFFFFFF }); self.countText.anchor.set(0.5, 0.5); self.addChild(self.countText); self.setOwner = function (newOwner) { var oldOwner = self.owner; self.owner = newOwner; var targetColor; if (newOwner === 0) { targetColor = 0x888888; // neutral gray } else if (newOwner === 1) { targetColor = 0x4a90e2; // player blue } else { targetColor = 0xe74c3c; // enemy red } // Only animate if ownership actually changed if (oldOwner !== newOwner) { // Smooth color transition over 500ms tween(towerGraphics, { tint: targetColor }, { duration: 500, easing: tween.easeInOut }); } else { // Immediate color change if no ownership change towerGraphics.tint = targetColor; } }; self.addUnits = function (count) { self.unitCount = Math.min(self.unitCount + count, self.maxUnits); self.countText.setText(Math.floor(self.unitCount)); }; self.removeUnits = function (count) { self.unitCount = Math.max(0, self.unitCount - count); self.countText.setText(Math.floor(self.unitCount)); return count; }; self.update = function () { if (self.owner > 0) { // Calculate dynamic spawn rate based on unit count // More units = faster production (lower spawn rate number) // Base rate is 30, reduced by unit count factor var dynamicSpawnRate = Math.max(10, self.spawnRate - Math.floor(self.unitCount / 10)); if (LK.ticks - self.lastSpawn > dynamicSpawnRate) { self.addUnits(1); self.lastSpawn = LK.ticks; } } }; return self; }); var Unit = Container.expand(function () { var self = Container.call(this); self.owner = 1; self.speed = 3; self.targetTower = null; self.pathIndex = 0; self.path = []; var unitGraphics = self.attachAsset('unit', { anchorX: 0.5, anchorY: 0.5 }); self.setOwner = function (owner) { self.owner = owner; if (owner === 1) { unitGraphics.tint = 0x4a90e2; // player blue } else { unitGraphics.tint = 0xe74c3c; // enemy red } }; self.setPath = function (path, target) { self.path = path; self.targetTower = target; self.pathIndex = 0; if (path.length > 0) { self.x = path[0].x; self.y = path[0].y; } }; self.lastWasIntersecting = false; self.update = function () { if (!self.targetTower || self.pathIndex >= self.path.length) { return; } // Check for combat with enemy units var currentIntersecting = false; for (var i = 0; i < units.length; i++) { var otherUnit = units[i]; if (otherUnit !== self && otherUnit.owner !== self.owner) { // Check if units are close enough to fight (within 30 pixels) var combatDx = self.x - otherUnit.x; var combatDy = self.y - otherUnit.y; var combatDist = Math.sqrt(combatDx * combatDx + combatDy * combatDy); if (combatDist < 30) { currentIntersecting = true; // Combat occurs - both units destroy each other if (!self.lastWasIntersecting) { // Flash both units red before destroying LK.effects.flashObject(self, 0xff0000, 200); LK.effects.flashObject(otherUnit, 0xff0000, 200); LK.getSound('combat').play(); // Destroy both units after flash LK.setTimeout(function () { if (self && self.parent) { self.destroy(); var selfIndex = units.indexOf(self); if (selfIndex !== -1) { units.splice(selfIndex, 1); } } if (otherUnit && otherUnit.parent) { otherUnit.destroy(); var otherIndex = units.indexOf(otherUnit); if (otherIndex !== -1) { units.splice(otherIndex, 1); } } }, 200); return; } } } } self.lastWasIntersecting = currentIntersecting; var target = self.path[self.pathIndex]; var dx = target.x - self.x; var dy = target.y - self.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < self.speed) { self.pathIndex++; if (self.pathIndex >= self.path.length && self.targetTower) { // Reached target tower if (self.targetTower.owner === self.owner) { self.targetTower.addUnits(1); } else { self.targetTower.unitCount--; if (self.targetTower.unitCount < 0) { self.targetTower.unitCount = 1; self.targetTower.setOwner(self.owner); LK.getSound('capture').play(); } self.targetTower.countText.setText(Math.floor(Math.abs(self.targetTower.unitCount))); } self.destroy(); units.splice(units.indexOf(self), 1); } } else { self.x += dx / dist * self.speed; self.y += dy / dist * self.speed; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a1a }); /**** * Game Code ****/ var towers = []; var units = []; var currentPath = null; var selectedTower = null; var isDragging = false; var currentLevel = storage.currentLevel || 0; var aiStartTime = null; // Track when AI should start (null = not started yet) var selectionRing = null; // Visual highlight for selected tower var targetTower = null; // Currently highlighted target tower during drag // Level configurations - 10 levels with progressive difficulty var levels = [{ // Level 1 - Tutorial towers: [{ x: 300, y: 1366, owner: 1, units: 30 }, { x: 1024, y: 800, owner: 0, units: 10 }, { x: 1748, y: 1366, owner: 2, units: 20 }] }, { // Level 2 - Basic Strategy towers: [{ x: 300, y: 400, owner: 1, units: 35 }, { x: 1024, y: 1366, owner: 0, units: 15 }, { x: 1748, y: 400, owner: 2, units: 25 }, { x: 1748, y: 2332, owner: 2, units: 25 }] }, { // Level 3 - Multi-Front towers: [{ x: 300, y: 1366, owner: 1, units: 45 }, { x: 700, y: 800, owner: 0, units: 15 }, { x: 1348, y: 800, owner: 0, units: 15 }, { x: 700, y: 1932, owner: 0, units: 15 }, { x: 1348, y: 1932, owner: 0, units: 15 }, { x: 1748, y: 1366, owner: 2, units: 35 }] }, { // Level 4 - Defensive Challenge towers: [{ x: 300, y: 1366, owner: 1, units: 50 }, { x: 600, y: 600, owner: 0, units: 20 }, { x: 1024, y: 400, owner: 2, units: 40 }, { x: 1448, y: 600, owner: 0, units: 20 }, { x: 1748, y: 1366, owner: 2, units: 40 }, { x: 1024, y: 2100, owner: 2, units: 40 }] }, { // Level 5 - Resource Management towers: [{ x: 200, y: 800, owner: 1, units: 55 }, { x: 200, y: 1932, owner: 1, units: 55 }, { x: 700, y: 1366, owner: 0, units: 25 }, { x: 1348, y: 1366, owner: 0, units: 25 }, { x: 1748, y: 600, owner: 2, units: 45 }, { x: 1748, y: 1366, owner: 2, units: 45 }, { x: 1748, y: 2132, owner: 2, units: 45 }] }, { // Level 6 - Territory Control towers: [{ x: 300, y: 400, owner: 1, units: 60 }, { x: 300, y: 2332, owner: 1, units: 60 }, { x: 600, y: 800, owner: 0, units: 30 }, { x: 1024, y: 1366, owner: 0, units: 30 }, { x: 1448, y: 1932, owner: 0, units: 30 }, { x: 1748, y: 800, owner: 2, units: 50 }, { x: 1748, y: 1500, owner: 2, units: 50 }, { x: 1748, y: 2200, owner: 2, units: 50 }] }, { // Level 7 - Advanced Tactics towers: [{ x: 200, y: 1366, owner: 1, units: 65 }, { x: 500, y: 600, owner: 0, units: 35 }, { x: 500, y: 1366, owner: 0, units: 35 }, { x: 500, y: 2132, owner: 0, units: 35 }, { x: 1024, y: 400, owner: 0, units: 35 }, { x: 1024, y: 2332, owner: 0, units: 35 }, { x: 1548, y: 600, owner: 0, units: 35 }, { x: 1548, y: 1366, owner: 0, units: 35 }, { x: 1548, y: 2132, owner: 0, units: 35 }, { x: 1848, y: 1366, owner: 2, units: 55 }] }, { // Level 8 - Siege Warfare towers: [{ x: 300, y: 600, owner: 1, units: 70 }, { x: 300, y: 1366, owner: 1, units: 70 }, { x: 300, y: 2132, owner: 1, units: 70 }, { x: 800, y: 800, owner: 0, units: 40 }, { x: 800, y: 1932, owner: 0, units: 40 }, { x: 1248, y: 800, owner: 0, units: 40 }, { x: 1248, y: 1932, owner: 0, units: 40 }, { x: 1650, y: 400, owner: 2, units: 60 }, { x: 1650, y: 1366, owner: 2, units: 60 }, { x: 1650, y: 2332, owner: 2, units: 60 }] }, { // Level 9 - Final Challenge towers: [{ x: 200, y: 800, owner: 1, units: 75 }, { x: 200, y: 1932, owner: 1, units: 75 }, { x: 600, y: 400, owner: 0, units: 45 }, { x: 600, y: 1366, owner: 0, units: 45 }, { x: 600, y: 2332, owner: 0, units: 45 }, { x: 1024, y: 600, owner: 0, units: 45 }, { x: 1024, y: 2132, owner: 0, units: 45 }, { x: 1448, y: 400, owner: 0, units: 45 }, { x: 1448, y: 1366, owner: 0, units: 45 }, { x: 1448, y: 2333, owner: 0, units: 45 }, { x: 1748, y: 600, owner: 2, units: 65 }, { x: 1748, y: 1366, owner: 2, units: 65 }, { x: 1748, y: 2132, owner: 2, units: 65 }] }, { // Level 10 - Master's Trial towers: [{ x: 150, y: 1366, owner: 1, units: 80 }, { x: 400, y: 600, owner: 0, units: 50 }, { x: 400, y: 1100, owner: 0, units: 50 }, { x: 400, y: 1632, owner: 0, units: 50 }, { x: 400, y: 2132, owner: 0, units: 50 }, { x: 800, y: 400, owner: 0, units: 50 }, { x: 800, y: 800, owner: 0, units: 50 }, { x: 800, y: 1932, owner: 0, units: 50 }, { x: 800, y: 2333, owner: 0, units: 50 }, { x: 1248, y: 400, owner: 0, units: 50 }, { x: 1248, y: 800, owner: 0, units: 50 }, { x: 1248, y: 1932, owner: 0, units: 50 }, { x: 1248, y: 2333, owner: 0, units: 50 }, { x: 1648, y: 600, owner: 0, units: 50 }, { x: 1648, y: 1100, owner: 0, units: 50 }, { x: 1648, y: 1632, owner: 0, units: 50 }, { x: 1648, y: 2132, owner: 0, units: 50 }, { x: 1898, y: 1366, owner: 2, units: 70 }] }]; // UI Elements var levelText = new Text2('Level ' + (currentLevel + 1), { size: 80, fill: 0xFFFFFF }); levelText.anchor.set(0.5, 0); LK.gui.top.addChild(levelText); function loadLevel(levelIndex) { // Clear existing game objects for (var i = 0; i < towers.length; i++) { towers[i].destroy(); } for (var i = 0; i < units.length; i++) { units[i].destroy(); } towers = []; units = []; if (currentPath) { currentPath.destroy(); currentPath = null; } // Reset game state variables selectedTower = null; isDragging = false; removeSelectionRing(); stopTargetBlink(); // Load new level var levelData = levels[levelIndex % levels.length]; for (var i = 0; i < levelData.towers.length; i++) { var towerData = levelData.towers[i]; var tower = new Tower(); tower.x = towerData.x; tower.y = towerData.y; tower.setOwner(towerData.owner); tower.addUnits(towerData.units); towers.push(tower); game.addChild(tower); } levelText.setText('Level ' + (levelIndex + 1)); // Set AI to start after 5 seconds (5000ms) aiStartTime = LK.ticks + 5 * 60; // 5 seconds at 60 FPS } function createSelectionRing(tower) { if (selectionRing) { selectionRing.destroy(); } selectionRing = LK.getAsset('selectionRing', { anchorX: 0.5, anchorY: 0.5, alpha: 0.6 }); selectionRing.x = tower.x; selectionRing.y = tower.y; game.addChild(selectionRing); // Start rotating animation tween(selectionRing, { rotation: Math.PI * 2 }, { duration: 2000, easing: tween.linear, onFinish: function onFinish() { if (selectionRing && selectionRing.parent) { selectionRing.rotation = 0; tween(selectionRing, { rotation: Math.PI * 2 }, { duration: 2000, easing: tween.linear, onFinish: arguments.callee // Repeat infinitely }); } } }); } function removeSelectionRing() { if (selectionRing) { tween.stop(selectionRing); selectionRing.destroy(); selectionRing = null; } } function createPath(start, end) { var points = []; var steps = 20; for (var i = 0; i <= steps; i++) { points.push({ x: start.x + (end.x - start.x) * (i / steps), y: start.y + (end.y - start.y) * (i / steps) }); } return points; } function startTargetBlink(tower) { if (targetTower && targetTower !== tower) { stopTargetBlink(); } targetTower = tower; // Start blinking animation - alternate between normal and bright colors var originalTint = tower.children[0].tint; // Get the tower graphics tint tween(tower.children[0], { tint: 0xffffff }, { duration: 300, easing: tween.easeInOut, onFinish: function onFinish() { if (targetTower === tower) { tween(tower.children[0], { tint: originalTint }, { duration: 300, easing: tween.easeInOut, onFinish: arguments.callee // Repeat infinitely }); } } }); } function stopTargetBlink() { if (targetTower) { tween.stop(targetTower.children[0], { tint: true }); // Restore original color based on owner var targetColor; if (targetTower.owner === 0) { targetColor = 0x888888; // neutral gray } else if (targetTower.owner === 1) { targetColor = 0x4a90e2; // player blue } else { targetColor = 0xe74c3c; // enemy red } targetTower.children[0].tint = targetColor; targetTower = null; } } function sendUnits(fromTower, toTower, count) { var path = createPath(fromTower, toTower); var unitsToSend = Math.min(count, fromTower.unitCount); for (var i = 0; i < unitsToSend; i++) { var unit = new Unit(); unit.setOwner(fromTower.owner); unit.setPath(path, toTower); units.push(unit); game.addChild(unit); // Stagger unit spawning tween(unit, { x: path[0].x, y: path[0].y }, { duration: i * 50, onFinish: function onFinish() { LK.getSound('deploy').play(); } }); } fromTower.removeUnits(unitsToSend); } function checkWinCondition() { var playerTowers = 0; var enemyTowers = 0; for (var i = 0; i < towers.length; i++) { if (towers[i].owner === 1) playerTowers++; if (towers[i].owner === 2) enemyTowers++; } if (enemyTowers === 0) { // Win condition currentLevel++; storage.currentLevel = currentLevel; LK.showYouWin(); } else if (playerTowers === 0) { // Lose condition - reset everything to start from beginning currentLevel = 0; storage.currentLevel = 0; LK.showGameOver(); } } // Simple AI function runAI() { // Don't run AI until 5 seconds have passed if (aiStartTime && LK.ticks < aiStartTime) { return; } for (var i = 0; i < towers.length; i++) { var tower = towers[i]; if (tower.owner === 2 && tower.unitCount > 15) { // Find nearest non-enemy tower var nearestTower = null; var nearestDist = Infinity; for (var j = 0; j < towers.length; j++) { if (towers[j].owner !== 2) { var dx = towers[j].x - tower.x; var dy = towers[j].y - tower.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < nearestDist) { nearestDist = dist; nearestTower = towers[j]; } } } if (nearestTower) { sendUnits(tower, nearestTower, Math.floor(tower.unitCount * 0.8)); } } } } game.down = function (x, y, obj) { // Find if we clicked on a player tower for (var i = 0; i < towers.length; i++) { var tower = towers[i]; if (tower.owner === 1 && Math.abs(tower.x - x) < 75 && Math.abs(tower.y - y) < 75) { selectedTower = tower; isDragging = true; createSelectionRing(tower); if (!currentPath) { currentPath = new PathLine(); game.addChild(currentPath); } currentPath.setPath([{ x: tower.x, y: tower.y }]); break; } } }; game.move = function (x, y, obj) { if (isDragging && selectedTower && currentPath) { currentPath.setPath([{ x: selectedTower.x, y: selectedTower.y }, { x: x, y: y }]); // Check if we're hovering over a target tower var hoveringTower = null; for (var i = 0; i < towers.length; i++) { var tower = towers[i]; if (tower !== selectedTower && Math.abs(tower.x - x) < 75 && Math.abs(tower.y - y) < 75) { hoveringTower = tower; break; } } if (hoveringTower && hoveringTower !== targetTower) { startTargetBlink(hoveringTower); } else if (!hoveringTower && targetTower) { stopTargetBlink(); } } }; game.up = function (x, y, obj) { if (isDragging && selectedTower) { // Find target tower var dropTargetTower = null; for (var i = 0; i < towers.length; i++) { var tower = towers[i]; if (tower !== selectedTower && Math.abs(tower.x - x) < 75 && Math.abs(tower.y - y) < 75) { dropTargetTower = tower; break; } } if (dropTargetTower && selectedTower.unitCount > 0) { sendUnits(selectedTower, dropTargetTower, Math.floor(selectedTower.unitCount * 0.8)); } if (currentPath) { currentPath.clear(); } removeSelectionRing(); stopTargetBlink(); } isDragging = false; selectedTower = null; }; game.update = function () { // Update all units for (var i = units.length - 1; i >= 0; i--) { if (!units[i] || !units[i].parent) { units.splice(i, 1); } } // Run AI every 2 seconds if (LK.ticks % 120 === 0) { runAI(); } // Check win/lose conditions if (LK.ticks % 60 === 0) { checkWinCondition(); } }; // Create Reset button var resetButton = new Text2('Reset', { size: 60, fill: 0xFFFFFF }); resetButton.anchor.set(1, 1); // Anchor to bottom right LK.gui.bottomRight.addChild(resetButton); // Reset button functionality resetButton.down = function (x, y, obj) { // Reset all game state currentLevel = 0; storage.currentLevel = 0; // Clear existing game objects for (var i = 0; i < towers.length; i++) { towers[i].destroy(); } for (var i = 0; i < units.length; i++) { units[i].destroy(); } towers = []; units = []; if (currentPath) { currentPath.destroy(); currentPath = null; } // Reset game state variables selectedTower = null; isDragging = false; aiStartTime = null; removeSelectionRing(); stopTargetBlink(); // Load first level loadLevel(currentLevel); }; // Initialize first level loadLevel(currentLevel); // Play background music LK.playMusic('battle'); ;
===================================================================
--- original.js
+++ change.js
@@ -43,94 +43,8 @@
self.points = [];
};
return self;
});
-var PowerUp = Container.expand(function () {
- var self = Container.call(this);
- self.type = 'speed'; // Types: 'speed', 'production', 'strength'
- self.duration = 300; // 5 seconds at 60 FPS
- self.isActive = false;
- self.collected = false;
- var powerupGraphics = self.attachAsset('powerup', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- // Visual pulsing effect
- self.pulseDirection = 1;
- self.pulseSpeed = 0.05;
- self.setType = function (type) {
- self.type = type;
- if (type === 'speed') {
- powerupGraphics.tint = 0x00ff00; // Green for speed
- } else if (type === 'production') {
- powerupGraphics.tint = 0x0088ff; // Blue for production
- } else if (type === 'strength') {
- powerupGraphics.tint = 0xff0088; // Pink for strength
- }
- };
- self.activate = function (tower) {
- if (self.collected) return;
- self.collected = true;
- self.isActive = true;
- LK.getSound('powerup').play();
- // Apply powerup effect based on type
- if (self.type === 'speed') {
- // Double unit movement speed for duration
- tower.speedBoost = 2;
- tower.speedBoostTimer = self.duration;
- } else if (self.type === 'production') {
- // Increase production rate for duration
- tower.productionBoost = 2;
- tower.productionBoostTimer = self.duration;
- } else if (self.type === 'strength') {
- // Add bonus units immediately
- tower.addUnits(20);
- }
- // Visual effect when collected
- tween(powerupGraphics, {
- scaleX: 2,
- scaleY: 2,
- alpha: 0
- }, {
- duration: 300,
- easing: tween.easeOut,
- onFinish: function onFinish() {
- self.destroy();
- }
- });
- };
- self.update = function () {
- if (self.collected) return;
- // Pulsing animation
- powerupGraphics.scaleX += self.pulseSpeed * self.pulseDirection;
- powerupGraphics.scaleY += self.pulseSpeed * self.pulseDirection;
- if (powerupGraphics.scaleX >= 1.3) {
- self.pulseDirection = -1;
- } else if (powerupGraphics.scaleX <= 0.7) {
- self.pulseDirection = 1;
- }
- // Sparkle effects
- if (LK.ticks % 30 === 0) {
- var sparkle = self.attachAsset('sparkle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- sparkle.x = (Math.random() - 0.5) * 60;
- sparkle.y = (Math.random() - 0.5) * 60;
- tween(sparkle, {
- alpha: 0,
- scaleX: 0,
- scaleY: 0
- }, {
- duration: 500,
- onFinish: function onFinish() {
- sparkle.destroy();
- }
- });
- }
- };
- return self;
-});
var Tower = Container.expand(function () {
var self = Container.call(this);
self.owner = 0; // 0 = neutral, 1 = player, 2 = enemy
self.unitCount = 0;
@@ -181,29 +95,13 @@
self.countText.setText(Math.floor(self.unitCount));
return count;
};
self.update = function () {
- // Handle powerup timers
- if (self.speedBoostTimer && self.speedBoostTimer > 0) {
- self.speedBoostTimer--;
- if (self.speedBoostTimer <= 0) {
- self.speedBoost = 1;
- }
- }
- if (self.productionBoostTimer && self.productionBoostTimer > 0) {
- self.productionBoostTimer--;
- if (self.productionBoostTimer <= 0) {
- self.productionBoost = 1;
- }
- }
if (self.owner > 0) {
// Calculate dynamic spawn rate based on unit count
// More units = faster production (lower spawn rate number)
// Base rate is 30, reduced by unit count factor
var dynamicSpawnRate = Math.max(10, self.spawnRate - Math.floor(self.unitCount / 10));
- // Apply production boost if active
- var productionMultiplier = self.productionBoost || 1;
- dynamicSpawnRate = Math.floor(dynamicSpawnRate / productionMultiplier);
if (LK.ticks - self.lastSpawn > dynamicSpawnRate) {
self.addUnits(1);
self.lastSpawn = LK.ticks;
}
@@ -229,21 +127,20 @@
} else {
unitGraphics.tint = 0xe74c3c; // enemy red
}
};
- self.setPath = function (path, target, sourceTower) {
+ self.setPath = function (path, target) {
self.path = path;
self.targetTower = target;
- self.sourceTower = sourceTower;
self.pathIndex = 0;
if (path.length > 0) {
self.x = path[0].x;
self.y = path[0].y;
}
};
self.lastWasIntersecting = false;
self.update = function () {
- if (!self.targetTower && !self.targetPowerup || self.pathIndex >= self.path.length) {
+ if (!self.targetTower || self.pathIndex >= self.path.length) {
return;
}
// Check for combat with enemy units
var currentIntersecting = false;
@@ -284,26 +181,8 @@
}
}
}
self.lastWasIntersecting = currentIntersecting;
- // Handle powerup collection
- if (self.targetPowerup && !self.targetPowerup.collected) {
- var powerupDx = self.x - self.targetPowerup.x;
- var powerupDy = self.y - self.targetPowerup.y;
- var powerupDist = Math.sqrt(powerupDx * powerupDx + powerupDy * powerupDy);
- if (powerupDist < 40) {
- // Collection radius
- self.targetPowerup.activate(self.sourceTower);
- // Set path back to source tower
- if (self.sourceTower) {
- self.path = createPath(self, self.sourceTower);
- self.pathIndex = 0;
- self.targetPowerup = null;
- self.targetTower = self.sourceTower;
- }
- return;
- }
- }
var target = self.path[self.pathIndex];
var dx = target.x - self.x;
var dy = target.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
@@ -325,31 +204,10 @@
self.destroy();
units.splice(units.indexOf(self), 1);
}
} else {
- // Apply speed boost if source tower has it
- var currentSpeed = self.speed;
- if (self.sourceTower && self.sourceTower.speedBoost) {
- currentSpeed *= self.sourceTower.speedBoost;
- }
- self.x += dx / dist * currentSpeed;
- self.y += dy / dist * currentSpeed;
- // Check for powerup collection (for units not specifically targeting powerups)
- if (!self.targetPowerup) {
- for (var p = 0; p < powerups.length; p++) {
- var powerup = powerups[p];
- if (!powerup.collected) {
- var powerupDx = self.x - powerup.x;
- var powerupDy = self.y - powerup.y;
- var powerupDist = Math.sqrt(powerupDx * powerupDx + powerupDy * powerupDy);
- if (powerupDist < 40) {
- // Collection radius
- powerup.activate(self.sourceTower);
- break;
- }
- }
- }
- }
+ self.x += dx / dist * self.speed;
+ self.y += dy / dist * self.speed;
}
};
return self;
});
@@ -365,14 +223,15 @@
* Game Code
****/
var towers = [];
var units = [];
-var powerups = [];
var currentPath = null;
var selectedTower = null;
var isDragging = false;
var currentLevel = storage.currentLevel || 0;
var aiStartTime = null; // Track when AI should start (null = not started yet)
+var selectionRing = null; // Visual highlight for selected tower
+var targetTower = null; // Currently highlighted target tower during drag
// Level configurations - 10 levels with progressive difficulty
var levels = [{
// Level 1 - Tutorial
towers: [{
@@ -843,21 +702,19 @@
}
for (var i = 0; i < units.length; i++) {
units[i].destroy();
}
- for (var i = 0; i < powerups.length; i++) {
- powerups[i].destroy();
- }
towers = [];
units = [];
- powerups = [];
if (currentPath) {
currentPath.destroy();
currentPath = null;
}
// Reset game state variables
selectedTower = null;
isDragging = false;
+ removeSelectionRing();
+ stopTargetBlink();
// Load new level
var levelData = levels[levelIndex % levels.length];
for (var i = 0; i < levelData.towers.length; i++) {
var towerData = levelData.towers[i];
@@ -871,11 +728,48 @@
}
levelText.setText('Level ' + (levelIndex + 1));
// Set AI to start after 5 seconds (5000ms)
aiStartTime = LK.ticks + 5 * 60; // 5 seconds at 60 FPS
- // Spawn initial powerups
- spawnRandomPowerup();
}
+function createSelectionRing(tower) {
+ if (selectionRing) {
+ selectionRing.destroy();
+ }
+ selectionRing = LK.getAsset('selectionRing', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.6
+ });
+ selectionRing.x = tower.x;
+ selectionRing.y = tower.y;
+ game.addChild(selectionRing);
+ // Start rotating animation
+ tween(selectionRing, {
+ rotation: Math.PI * 2
+ }, {
+ duration: 2000,
+ easing: tween.linear,
+ onFinish: function onFinish() {
+ if (selectionRing && selectionRing.parent) {
+ selectionRing.rotation = 0;
+ tween(selectionRing, {
+ rotation: Math.PI * 2
+ }, {
+ duration: 2000,
+ easing: tween.linear,
+ onFinish: arguments.callee // Repeat infinitely
+ });
+ }
+ }
+ });
+}
+function removeSelectionRing() {
+ if (selectionRing) {
+ tween.stop(selectionRing);
+ selectionRing.destroy();
+ selectionRing = null;
+ }
+}
function createPath(start, end) {
var points = [];
var steps = 20;
for (var i = 0; i <= steps; i++) {
@@ -885,44 +779,58 @@
});
}
return points;
}
-function spawnRandomPowerup() {
- var powerup = new PowerUp();
- // Random position avoiding tower locations
- var validPosition = false;
- var attempts = 0;
- var x, y;
- while (!validPosition && attempts < 20) {
- x = 200 + Math.random() * (2048 - 400);
- y = 500 + Math.random() * (2732 - 1000);
- validPosition = true;
- for (var i = 0; i < towers.length; i++) {
- var dx = towers[i].x - x;
- var dy = towers[i].y - y;
- var dist = Math.sqrt(dx * dx + dy * dy);
- if (dist < 200) {
- validPosition = false;
- break;
+function startTargetBlink(tower) {
+ if (targetTower && targetTower !== tower) {
+ stopTargetBlink();
+ }
+ targetTower = tower;
+ // Start blinking animation - alternate between normal and bright colors
+ var originalTint = tower.children[0].tint; // Get the tower graphics tint
+ tween(tower.children[0], {
+ tint: 0xffffff
+ }, {
+ duration: 300,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ if (targetTower === tower) {
+ tween(tower.children[0], {
+ tint: originalTint
+ }, {
+ duration: 300,
+ easing: tween.easeInOut,
+ onFinish: arguments.callee // Repeat infinitely
+ });
}
}
- attempts++;
+ });
+}
+function stopTargetBlink() {
+ if (targetTower) {
+ tween.stop(targetTower.children[0], {
+ tint: true
+ });
+ // Restore original color based on owner
+ var targetColor;
+ if (targetTower.owner === 0) {
+ targetColor = 0x888888; // neutral gray
+ } else if (targetTower.owner === 1) {
+ targetColor = 0x4a90e2; // player blue
+ } else {
+ targetColor = 0xe74c3c; // enemy red
+ }
+ targetTower.children[0].tint = targetColor;
+ targetTower = null;
}
- powerup.x = x;
- powerup.y = y;
- // Random powerup type
- var types = ['speed', 'production', 'strength'];
- powerup.setType(types[Math.floor(Math.random() * types.length)]);
- powerups.push(powerup);
- game.addChild(powerup);
}
function sendUnits(fromTower, toTower, count) {
var path = createPath(fromTower, toTower);
var unitsToSend = Math.min(count, fromTower.unitCount);
for (var i = 0; i < unitsToSend; i++) {
var unit = new Unit();
unit.setOwner(fromTower.owner);
- unit.setPath(path, toTower, fromTower);
+ unit.setPath(path, toTower);
units.push(unit);
game.addChild(unit);
// Stagger unit spawning
tween(unit, {
@@ -936,31 +844,8 @@
});
}
fromTower.removeUnits(unitsToSend);
}
-function sendUnitsToPowerup(fromTower, toPowerup, count) {
- var path = createPath(fromTower, toPowerup);
- var unitsToSend = Math.min(count, fromTower.unitCount);
- for (var i = 0; i < unitsToSend; i++) {
- var unit = new Unit();
- unit.setOwner(fromTower.owner);
- unit.setPath(path, null, fromTower);
- unit.targetPowerup = toPowerup;
- units.push(unit);
- game.addChild(unit);
- // Stagger unit spawning
- tween(unit, {
- x: path[0].x,
- y: path[0].y
- }, {
- duration: i * 50,
- onFinish: function onFinish() {
- LK.getSound('deploy').play();
- }
- });
- }
- fromTower.removeUnits(unitsToSend);
-}
function checkWinCondition() {
var playerTowers = 0;
var enemyTowers = 0;
for (var i = 0; i < towers.length; i++) {
@@ -1014,8 +899,9 @@
var tower = towers[i];
if (tower.owner === 1 && Math.abs(tower.x - x) < 75 && Math.abs(tower.y - y) < 75) {
selectedTower = tower;
isDragging = true;
+ createSelectionRing(tower);
if (!currentPath) {
currentPath = new PathLine();
game.addChild(currentPath);
}
@@ -1035,40 +921,43 @@
}, {
x: x,
y: y
}]);
+ // Check if we're hovering over a target tower
+ var hoveringTower = null;
+ for (var i = 0; i < towers.length; i++) {
+ var tower = towers[i];
+ if (tower !== selectedTower && Math.abs(tower.x - x) < 75 && Math.abs(tower.y - y) < 75) {
+ hoveringTower = tower;
+ break;
+ }
+ }
+ if (hoveringTower && hoveringTower !== targetTower) {
+ startTargetBlink(hoveringTower);
+ } else if (!hoveringTower && targetTower) {
+ stopTargetBlink();
+ }
}
};
game.up = function (x, y, obj) {
if (isDragging && selectedTower) {
// Find target tower
- var targetTower = null;
+ var dropTargetTower = null;
for (var i = 0; i < towers.length; i++) {
var tower = towers[i];
if (tower !== selectedTower && Math.abs(tower.x - x) < 75 && Math.abs(tower.y - y) < 75) {
- targetTower = tower;
+ dropTargetTower = tower;
break;
}
}
- // Find target powerup
- var targetPowerup = null;
- if (!targetTower) {
- for (var i = 0; i < powerups.length; i++) {
- var powerup = powerups[i];
- if (!powerup.collected && Math.abs(powerup.x - x) < 40 && Math.abs(powerup.y - y) < 40) {
- targetPowerup = powerup;
- break;
- }
- }
+ if (dropTargetTower && selectedTower.unitCount > 0) {
+ sendUnits(selectedTower, dropTargetTower, Math.floor(selectedTower.unitCount * 0.8));
}
- if (targetTower && selectedTower.unitCount > 0) {
- sendUnits(selectedTower, targetTower, Math.floor(selectedTower.unitCount * 0.8));
- } else if (targetPowerup && selectedTower.unitCount > 0) {
- sendUnitsToPowerup(selectedTower, targetPowerup, Math.floor(selectedTower.unitCount * 0.2));
- }
if (currentPath) {
currentPath.clear();
}
+ removeSelectionRing();
+ stopTargetBlink();
}
isDragging = false;
selectedTower = null;
};
@@ -1082,19 +971,8 @@
// Run AI every 2 seconds
if (LK.ticks % 120 === 0) {
runAI();
}
- // Spawn new powerups occasionally
- if (LK.ticks % 1800 === 0 && powerups.length < 3) {
- // Every 30 seconds, max 3 powerups
- spawnRandomPowerup();
- }
- // Clean up collected powerups
- for (var i = powerups.length - 1; i >= 0; i--) {
- if (!powerups[i] || !powerups[i].parent) {
- powerups.splice(i, 1);
- }
- }
// Check win/lose conditions
if (LK.ticks % 60 === 0) {
checkWinCondition();
}
@@ -1117,22 +995,20 @@
}
for (var i = 0; i < units.length; i++) {
units[i].destroy();
}
- for (var i = 0; i < powerups.length; i++) {
- powerups[i].destroy();
- }
towers = [];
units = [];
- powerups = [];
if (currentPath) {
currentPath.destroy();
currentPath = null;
}
// Reset game state variables
selectedTower = null;
isDragging = false;
aiStartTime = null;
+ removeSelectionRing();
+ stopTargetBlink();
// Load first level
loadLevel(currentLevel);
};
// Initialize first level
Saldırı kulesi, Gerçekçi, kuş bakışı görünüm, yazısız.. In-Game asset. High contrast. No shadows, 3d olsun.
Saldırı kulesi, Gerçekçi, kuş bakışı görünüm, yazısız.. In-Game asset. High contrast. No shadows, 3d olsun.
Gece çölü arkaplan resmi, Gerçekçi, kuş bakışı görünüm, yazısız. susuz. In-Game asset. High contrast. No shadows, 3d olsun..
Kılıç ve kalkanlı çağı saldırı askeri, Gerçekçi, kuş bakışı görünüm, yazısız.. In-Game asset. High contrast. No shadows, renkli 3d olsun.