/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var DefensiveUnit = Container.expand(function (unitType) {
var self = Container.call(this);
var unitGraphics = self.attachAsset(unitType, {
anchorX: 0.5,
anchorY: 0.5
});
if (unitType === 'archer') {
self.damage = 15;
self.range = 180;
self.attackSpeed = 60; // frames between attacks
self.cost = 10;
} else if (unitType === 'spearman') {
self.damage = 25;
self.range = 100;
self.attackSpeed = 45;
self.cost = 15;
} else if (unitType === 'cavalry') {
self.damage = 35;
self.range = 120;
self.attackSpeed = 30;
self.cost = 25;
}
self.unitType = unitType;
self.attackTimer = 0;
self.target = null;
self.update = function () {
self.attackTimer--;
if (self.attackTimer <= 0) {
self.findTarget();
if (self.target && self.isInRange(self.target)) {
self.attack();
self.attackTimer = self.attackSpeed;
}
}
};
self.findTarget = function () {
var closestDistance = self.range;
self.target = null;
for (var i = 0; i < enemies.length; i++) {
var enemy = enemies[i];
var distance = Math.sqrt(Math.pow(enemy.x - self.x, 2) + Math.pow(enemy.y - self.y, 2));
if (distance < closestDistance) {
closestDistance = distance;
self.target = enemy;
}
}
};
self.isInRange = function (target) {
var distance = Math.sqrt(Math.pow(target.x - self.x, 2) + Math.pow(target.y - self.y, 2));
return distance <= self.range;
};
self.attack = function () {
if (self.target) {
var projectile = new Projectile(self.unitType, self.x, self.y, self.target, self.damage);
projectiles.push(projectile);
game.addChild(projectile);
LK.getSound('attack').play();
}
};
return self;
});
var Enemy = Container.expand(function (enemyType) {
var self = Container.call(this);
var enemyGraphics = self.attachAsset(enemyType, {
anchorX: 0.5,
anchorY: 0.5
});
if (enemyType === 'enemy') {
self.health = 30;
self.maxHealth = 30;
self.speed = 1;
self.damage = 10;
self.coinValue = 2;
} else if (enemyType === 'strongEnemy') {
self.health = 60;
self.maxHealth = 60;
self.speed = 0.8;
self.damage = 20;
self.coinValue = 5;
}
self.enemyType = enemyType;
self.update = function () {
// Move toward fortress
var dx = fortress.x - self.x;
var dy = fortress.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 75) {
// Not at fortress yet
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
} else {
// Attack fortress
fortress.takeDamage(self.damage);
self.markForDestroy = true;
}
};
self.takeDamage = function (damage) {
self.health -= damage;
LK.effects.flashObject(self, 0xFFFFFF, 200);
if (self.health <= 0) {
coins += self.coinValue;
enemiesKilled++;
self.markForDestroy = true;
}
};
return self;
});
var Fortress = Container.expand(function () {
var self = Container.call(this);
var fortressGraphics = self.attachAsset('fortress', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.maxHealth = 100;
self.takeDamage = function (damage) {
self.health -= damage;
LK.effects.flashObject(self, 0xFF0000, 300);
if (self.health <= 0) {
gameOver = true;
}
};
return self;
});
var Projectile = Container.expand(function (unitType, startX, startY, target, damage) {
var self = Container.call(this);
var assetType = unitType === 'archer' ? 'arrow' : 'spear';
var projectileGraphics = self.attachAsset(assetType, {
anchorX: 0.5,
anchorY: 0.5
});
self.x = startX;
self.y = startY;
self.target = target;
self.damage = damage;
self.speed = 8;
// Calculate direction to target
var dx = target.x - startX;
var dy = target.y - startY;
var distance = Math.sqrt(dx * dx + dy * dy);
self.dirX = dx / distance;
self.dirY = dy / distance;
// Set rotation to face target
projectileGraphics.rotation = Math.atan2(dy, dx);
self.update = function () {
self.x += self.dirX * self.speed;
self.y += self.dirY * self.speed;
// Check if hit target
if (self.target && Math.sqrt(Math.pow(self.target.x - self.x, 2) + Math.pow(self.target.y - self.y, 2)) < 25) {
self.target.takeDamage(self.damage);
self.markForDestroy = true;
}
// Remove if off screen
if (self.x < -50 || self.x > 2098 || self.y < -50 || self.y > 2782) {
self.markForDestroy = true;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xF4A460 // Sandy brown desert background
});
/****
* Game Code
****/
// Game variables
var fortress;
var defensiveUnits = [];
var enemies = [];
var projectiles = [];
var coins = 50;
var currentWave = 1;
var enemiesInWave = 5;
var enemiesSpawned = 0;
var waveDelay = 180; // 3 seconds at 60fps
var spawnDelay = 60; // 1 second between enemy spawns
var gameOver = false;
var enemiesKilled = 0;
var selectedUnitType = 'archer';
// Initialize fortress at center
fortress = new Fortress();
fortress.x = 1024;
fortress.y = 1366;
game.addChild(fortress);
// UI Elements
var coinsText = new Text2('Coins: ' + coins, {
size: 40,
fill: 0xFFD700
});
coinsText.anchor.set(0, 0);
coinsText.x = 120;
coinsText.y = 50;
LK.gui.topLeft.addChild(coinsText);
var waveText = new Text2('Wave: ' + currentWave, {
size: 40,
fill: 0xFFFFFF
});
waveText.anchor.set(0.5, 0);
waveText.x = 0;
waveText.y = 50;
LK.gui.top.addChild(waveText);
var healthText = new Text2('Fortress: ' + fortress.health + '/' + fortress.maxHealth, {
size: 40,
fill: 0xFF0000
});
healthText.anchor.set(1, 0);
healthText.x = -20;
healthText.y = 50;
LK.gui.topRight.addChild(healthText);
// Unit selection buttons
var archerButton = new Text2('Archer (10)', {
size: 35,
fill: 0x228B22
});
archerButton.anchor.set(0.5, 1);
archerButton.x = -200;
archerButton.y = -50;
LK.gui.bottom.addChild(archerButton);
var spearmanButton = new Text2('Spearman (15)', {
size: 35,
fill: 0x4169E1
});
spearmanButton.anchor.set(0.5, 1);
spearmanButton.x = 0;
spearmanButton.y = -50;
LK.gui.bottom.addChild(spearmanButton);
var cavalryButton = new Text2('Cavalry (25)', {
size: 35,
fill: 0x800080
});
cavalryButton.anchor.set(0.5, 1);
cavalryButton.x = 200;
cavalryButton.y = -50;
LK.gui.bottom.addChild(cavalryButton);
// Button press handlers
archerButton.down = function () {
selectedUnitType = 'archer';
updateButtonColors();
};
spearmanButton.down = function () {
selectedUnitType = 'spearman';
updateButtonColors();
};
cavalryButton.down = function () {
selectedUnitType = 'cavalry';
updateButtonColors();
};
function updateButtonColors() {
archerButton.style.fill = selectedUnitType === 'archer' ? "#00FF00" : "#228B22";
spearmanButton.style.fill = selectedUnitType === 'spearman' ? "#00FF00" : "#4169E1";
cavalryButton.style.fill = selectedUnitType === 'cavalry' ? "#00FF00" : "#800080";
}
updateButtonColors();
// Game input
game.down = function (x, y, obj) {
if (gameOver) return;
var unitCost = selectedUnitType === 'archer' ? 10 : selectedUnitType === 'spearman' ? 15 : 25;
if (coins >= unitCost) {
var newUnit = new DefensiveUnit(selectedUnitType);
newUnit.x = x;
newUnit.y = y;
defensiveUnits.push(newUnit);
game.addChild(newUnit);
coins -= unitCost;
LK.getSound('deploy').play();
}
};
// Spawn enemies
function spawnEnemy() {
var enemyType = currentWave > 3 && Math.random() < 0.3 ? 'strongEnemy' : 'enemy';
var enemy = new Enemy(enemyType);
// Spawn from random edge
var side = Math.floor(Math.random() * 4);
if (side === 0) {
// Top
enemy.x = Math.random() * 2048;
enemy.y = -50;
} else if (side === 1) {
// Right
enemy.x = 2098;
enemy.y = Math.random() * 2732;
} else if (side === 2) {
// Bottom
enemy.x = Math.random() * 2048;
enemy.y = 2782;
} else {
// Left
enemy.x = -50;
enemy.y = Math.random() * 2732;
}
enemies.push(enemy);
game.addChild(enemy);
}
// Start background music
LK.playMusic('background');
// Main game update
game.update = function () {
if (gameOver) {
LK.showGameOver();
return;
}
// Update UI
coinsText.setText('Coins: ' + coins);
waveText.setText('Wave: ' + currentWave);
healthText.setText('Fortress: ' + fortress.health + '/' + fortress.maxHealth);
LK.setScore(enemiesKilled);
// Spawn enemies for current wave
if (enemiesSpawned < enemiesInWave && LK.ticks % spawnDelay === 0) {
spawnEnemy();
enemiesSpawned++;
}
// Check if wave is complete
if (enemiesSpawned >= enemiesInWave && enemies.length === 0) {
if (waveDelay > 0) {
waveDelay--;
} else {
// Start next wave
currentWave++;
enemiesInWave = Math.min(5 + currentWave * 2, 20);
enemiesSpawned = 0;
waveDelay = 180;
spawnDelay = Math.max(30, 60 - currentWave * 2);
}
}
// Update defensive units
for (var i = 0; i < defensiveUnits.length; i++) {
defensiveUnits[i].update();
}
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
enemy.update();
if (enemy.markForDestroy) {
enemy.destroy();
enemies.splice(i, 1);
}
}
// Update projectiles
for (var i = projectiles.length - 1; i >= 0; i--) {
var projectile = projectiles[i];
projectile.update();
if (projectile.markForDestroy) {
projectile.destroy();
projectiles.splice(i, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,361 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var DefensiveUnit = Container.expand(function (unitType) {
+ var self = Container.call(this);
+ var unitGraphics = self.attachAsset(unitType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ if (unitType === 'archer') {
+ self.damage = 15;
+ self.range = 180;
+ self.attackSpeed = 60; // frames between attacks
+ self.cost = 10;
+ } else if (unitType === 'spearman') {
+ self.damage = 25;
+ self.range = 100;
+ self.attackSpeed = 45;
+ self.cost = 15;
+ } else if (unitType === 'cavalry') {
+ self.damage = 35;
+ self.range = 120;
+ self.attackSpeed = 30;
+ self.cost = 25;
+ }
+ self.unitType = unitType;
+ self.attackTimer = 0;
+ self.target = null;
+ self.update = function () {
+ self.attackTimer--;
+ if (self.attackTimer <= 0) {
+ self.findTarget();
+ if (self.target && self.isInRange(self.target)) {
+ self.attack();
+ self.attackTimer = self.attackSpeed;
+ }
+ }
+ };
+ self.findTarget = function () {
+ var closestDistance = self.range;
+ self.target = null;
+ for (var i = 0; i < enemies.length; i++) {
+ var enemy = enemies[i];
+ var distance = Math.sqrt(Math.pow(enemy.x - self.x, 2) + Math.pow(enemy.y - self.y, 2));
+ if (distance < closestDistance) {
+ closestDistance = distance;
+ self.target = enemy;
+ }
+ }
+ };
+ self.isInRange = function (target) {
+ var distance = Math.sqrt(Math.pow(target.x - self.x, 2) + Math.pow(target.y - self.y, 2));
+ return distance <= self.range;
+ };
+ self.attack = function () {
+ if (self.target) {
+ var projectile = new Projectile(self.unitType, self.x, self.y, self.target, self.damage);
+ projectiles.push(projectile);
+ game.addChild(projectile);
+ LK.getSound('attack').play();
+ }
+ };
+ return self;
+});
+var Enemy = Container.expand(function (enemyType) {
+ var self = Container.call(this);
+ var enemyGraphics = self.attachAsset(enemyType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ if (enemyType === 'enemy') {
+ self.health = 30;
+ self.maxHealth = 30;
+ self.speed = 1;
+ self.damage = 10;
+ self.coinValue = 2;
+ } else if (enemyType === 'strongEnemy') {
+ self.health = 60;
+ self.maxHealth = 60;
+ self.speed = 0.8;
+ self.damage = 20;
+ self.coinValue = 5;
+ }
+ self.enemyType = enemyType;
+ self.update = function () {
+ // Move toward fortress
+ var dx = fortress.x - self.x;
+ var dy = fortress.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 75) {
+ // Not at fortress yet
+ self.x += dx / distance * self.speed;
+ self.y += dy / distance * self.speed;
+ } else {
+ // Attack fortress
+ fortress.takeDamage(self.damage);
+ self.markForDestroy = true;
+ }
+ };
+ self.takeDamage = function (damage) {
+ self.health -= damage;
+ LK.effects.flashObject(self, 0xFFFFFF, 200);
+ if (self.health <= 0) {
+ coins += self.coinValue;
+ enemiesKilled++;
+ self.markForDestroy = true;
+ }
+ };
+ return self;
+});
+var Fortress = Container.expand(function () {
+ var self = Container.call(this);
+ var fortressGraphics = self.attachAsset('fortress', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.health = 100;
+ self.maxHealth = 100;
+ self.takeDamage = function (damage) {
+ self.health -= damage;
+ LK.effects.flashObject(self, 0xFF0000, 300);
+ if (self.health <= 0) {
+ gameOver = true;
+ }
+ };
+ return self;
+});
+var Projectile = Container.expand(function (unitType, startX, startY, target, damage) {
+ var self = Container.call(this);
+ var assetType = unitType === 'archer' ? 'arrow' : 'spear';
+ var projectileGraphics = self.attachAsset(assetType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.x = startX;
+ self.y = startY;
+ self.target = target;
+ self.damage = damage;
+ self.speed = 8;
+ // Calculate direction to target
+ var dx = target.x - startX;
+ var dy = target.y - startY;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ self.dirX = dx / distance;
+ self.dirY = dy / distance;
+ // Set rotation to face target
+ projectileGraphics.rotation = Math.atan2(dy, dx);
+ self.update = function () {
+ self.x += self.dirX * self.speed;
+ self.y += self.dirY * self.speed;
+ // Check if hit target
+ if (self.target && Math.sqrt(Math.pow(self.target.x - self.x, 2) + Math.pow(self.target.y - self.y, 2)) < 25) {
+ self.target.takeDamage(self.damage);
+ self.markForDestroy = true;
+ }
+ // Remove if off screen
+ if (self.x < -50 || self.x > 2098 || self.y < -50 || self.y > 2782) {
+ self.markForDestroy = true;
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xF4A460 // Sandy brown desert background
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var fortress;
+var defensiveUnits = [];
+var enemies = [];
+var projectiles = [];
+var coins = 50;
+var currentWave = 1;
+var enemiesInWave = 5;
+var enemiesSpawned = 0;
+var waveDelay = 180; // 3 seconds at 60fps
+var spawnDelay = 60; // 1 second between enemy spawns
+var gameOver = false;
+var enemiesKilled = 0;
+var selectedUnitType = 'archer';
+// Initialize fortress at center
+fortress = new Fortress();
+fortress.x = 1024;
+fortress.y = 1366;
+game.addChild(fortress);
+// UI Elements
+var coinsText = new Text2('Coins: ' + coins, {
+ size: 40,
+ fill: 0xFFD700
+});
+coinsText.anchor.set(0, 0);
+coinsText.x = 120;
+coinsText.y = 50;
+LK.gui.topLeft.addChild(coinsText);
+var waveText = new Text2('Wave: ' + currentWave, {
+ size: 40,
+ fill: 0xFFFFFF
+});
+waveText.anchor.set(0.5, 0);
+waveText.x = 0;
+waveText.y = 50;
+LK.gui.top.addChild(waveText);
+var healthText = new Text2('Fortress: ' + fortress.health + '/' + fortress.maxHealth, {
+ size: 40,
+ fill: 0xFF0000
+});
+healthText.anchor.set(1, 0);
+healthText.x = -20;
+healthText.y = 50;
+LK.gui.topRight.addChild(healthText);
+// Unit selection buttons
+var archerButton = new Text2('Archer (10)', {
+ size: 35,
+ fill: 0x228B22
+});
+archerButton.anchor.set(0.5, 1);
+archerButton.x = -200;
+archerButton.y = -50;
+LK.gui.bottom.addChild(archerButton);
+var spearmanButton = new Text2('Spearman (15)', {
+ size: 35,
+ fill: 0x4169E1
+});
+spearmanButton.anchor.set(0.5, 1);
+spearmanButton.x = 0;
+spearmanButton.y = -50;
+LK.gui.bottom.addChild(spearmanButton);
+var cavalryButton = new Text2('Cavalry (25)', {
+ size: 35,
+ fill: 0x800080
+});
+cavalryButton.anchor.set(0.5, 1);
+cavalryButton.x = 200;
+cavalryButton.y = -50;
+LK.gui.bottom.addChild(cavalryButton);
+// Button press handlers
+archerButton.down = function () {
+ selectedUnitType = 'archer';
+ updateButtonColors();
+};
+spearmanButton.down = function () {
+ selectedUnitType = 'spearman';
+ updateButtonColors();
+};
+cavalryButton.down = function () {
+ selectedUnitType = 'cavalry';
+ updateButtonColors();
+};
+function updateButtonColors() {
+ archerButton.style.fill = selectedUnitType === 'archer' ? "#00FF00" : "#228B22";
+ spearmanButton.style.fill = selectedUnitType === 'spearman' ? "#00FF00" : "#4169E1";
+ cavalryButton.style.fill = selectedUnitType === 'cavalry' ? "#00FF00" : "#800080";
+}
+updateButtonColors();
+// Game input
+game.down = function (x, y, obj) {
+ if (gameOver) return;
+ var unitCost = selectedUnitType === 'archer' ? 10 : selectedUnitType === 'spearman' ? 15 : 25;
+ if (coins >= unitCost) {
+ var newUnit = new DefensiveUnit(selectedUnitType);
+ newUnit.x = x;
+ newUnit.y = y;
+ defensiveUnits.push(newUnit);
+ game.addChild(newUnit);
+ coins -= unitCost;
+ LK.getSound('deploy').play();
+ }
+};
+// Spawn enemies
+function spawnEnemy() {
+ var enemyType = currentWave > 3 && Math.random() < 0.3 ? 'strongEnemy' : 'enemy';
+ var enemy = new Enemy(enemyType);
+ // Spawn from random edge
+ var side = Math.floor(Math.random() * 4);
+ if (side === 0) {
+ // Top
+ enemy.x = Math.random() * 2048;
+ enemy.y = -50;
+ } else if (side === 1) {
+ // Right
+ enemy.x = 2098;
+ enemy.y = Math.random() * 2732;
+ } else if (side === 2) {
+ // Bottom
+ enemy.x = Math.random() * 2048;
+ enemy.y = 2782;
+ } else {
+ // Left
+ enemy.x = -50;
+ enemy.y = Math.random() * 2732;
+ }
+ enemies.push(enemy);
+ game.addChild(enemy);
+}
+// Start background music
+LK.playMusic('background');
+// Main game update
+game.update = function () {
+ if (gameOver) {
+ LK.showGameOver();
+ return;
+ }
+ // Update UI
+ coinsText.setText('Coins: ' + coins);
+ waveText.setText('Wave: ' + currentWave);
+ healthText.setText('Fortress: ' + fortress.health + '/' + fortress.maxHealth);
+ LK.setScore(enemiesKilled);
+ // Spawn enemies for current wave
+ if (enemiesSpawned < enemiesInWave && LK.ticks % spawnDelay === 0) {
+ spawnEnemy();
+ enemiesSpawned++;
+ }
+ // Check if wave is complete
+ if (enemiesSpawned >= enemiesInWave && enemies.length === 0) {
+ if (waveDelay > 0) {
+ waveDelay--;
+ } else {
+ // Start next wave
+ currentWave++;
+ enemiesInWave = Math.min(5 + currentWave * 2, 20);
+ enemiesSpawned = 0;
+ waveDelay = 180;
+ spawnDelay = Math.max(30, 60 - currentWave * 2);
+ }
+ }
+ // Update defensive units
+ for (var i = 0; i < defensiveUnits.length; i++) {
+ defensiveUnits[i].update();
+ }
+ // Update enemies
+ for (var i = enemies.length - 1; i >= 0; i--) {
+ var enemy = enemies[i];
+ enemy.update();
+ if (enemy.markForDestroy) {
+ enemy.destroy();
+ enemies.splice(i, 1);
+ }
+ }
+ // Update projectiles
+ for (var i = projectiles.length - 1; i >= 0; i--) {
+ var projectile = projectiles[i];
+ projectile.update();
+ if (projectile.markForDestroy) {
+ projectile.destroy();
+ projectiles.splice(i, 1);
+ }
+ }
+};
\ No newline at end of file
Una lanza para el guerrero. In-Game asset. 2d. High contrast. No shadows
Flecha. In-Game asset. 2d. High contrast. No shadows
Trollface. In-Game asset. 2d. High contrast. No shadows
Personaje aterrador. In-Game asset. 2d. High contrast. No shadows
Ogro. In-Game asset. 2d. High contrast. No shadows
Ogro músculoso y gigante. In-Game asset. 2d. High contrast. No shadows
Lucky block. In-Game asset. 2d. High contrast. No shadows
Torres gemelas. In-Game asset. 2d. High contrast. No shadows
Avión de color gris sin ruedas 8 bit. In-Game asset. 2d. High contrast. No shadows
Explosión efecto. In-Game asset. 2d. High contrast. No shadows
Cuadrado con signo de !. In-Game asset. 2d. High contrast. No shadows
Imagien bde un jefe terrorífico humanoide de color negro. In-Game asset. 2d. High contrast. No shadows