User prompt
As los botones más grandes y ponlos en la esquina contraria
User prompt
As que el jugador tenga botones para moverse
User prompt
As que en la pelea contra el boos el jugador tenga que esquiva cañones que le van disparando a el jugador pero lo cañones también le disparan al boos y le sacan 100 de vida al boos y al jugador le sacan 10 de vida ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
As que el free for allá te de 2 puntos
User prompt
As que cuando llegue el momento de pelear contra el boos la opción de todos contra todos y 1 vs 1 desaparezcan y que el jugador este obligado a pelear contra el boos
User prompt
As que cada que recolectes los puntos que tengas que recolectar para pasar a la siguiente clase tengas que matar a un jefe final que tendrá mejores armas y mucha más salud. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
As que el juego no se guarde más
User prompt
As que el jugador pueda bloquear ataques
User prompt
As que los bots cuando estén muy lastimado puedan correr a una esquina y curarse y que el jugador también pueda y as que los bots se puedan rendir cuando tenga poca vida pero solo ay un 20% de probabilidad de que se rinda y el jugador también se pueda rendir ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Medieval Beatdown
Initial prompt
As un juego donde tengas que pelear pará subir de clases en cada clase tendrás mejores armas el juego estará basado en la era medieval abra Dos tipos de modos modo 1 vs 1 y modo todos contra todos en el modo 1 vs 1 estará el jugador peleando contra un bot y en el modo todos contra todos estara el jugador y 3 bots peleando mutuamente el juego se llamará medieval beatles (en la clase uno el jugador y los bots solo tendrán sus manos pará pelear ose a puño limpio y en la clase 2 ya tendrán armas)(abran 5 clases mientras más alta sea la clase mejor arma tendrá el jugador y los bots)
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Fighter = Container.expand(function (isPlayer, classLevel) {
var self = Container.call(this);
self.isPlayer = isPlayer || false;
self.classLevel = classLevel || 1;
self.maxHealth = 100;
self.health = self.maxHealth;
self.moveSpeed = 3;
self.aiTimer = 0;
self.lastAttackTime = 0;
// Create fighter graphics
var assetName = self.isPlayer ? 'player_class' + self.classLevel : 'ai_class' + self.classLevel;
var fighterGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
// Create weapon based on class
var weaponTypes = ['fist', 'sword', 'axe', 'mace', 'halberd'];
var damages = [10, 15, 20, 25, 30];
var ranges = [50, 70, 60, 55, 90];
self.weapon = self.addChild(new Weapon(weaponTypes[self.classLevel - 1], damages[self.classLevel - 1], ranges[self.classLevel - 1]));
self.weapon.x = 40;
// Create health bar
self.healthBarBg = self.attachAsset('health_bar_bg', {
anchorX: 0.5,
anchorY: 0.5,
y: -80
});
self.healthBarFill = self.attachAsset('health_bar_fill', {
anchorX: 0,
anchorY: 0.5,
x: -100,
y: -80
});
self.takeDamage = function (damage) {
self.health -= damage;
if (self.health < 0) self.health = 0;
// Update health bar
var healthPercent = self.health / self.maxHealth;
self.healthBarFill.width = 200 * healthPercent;
// Flash red when taking damage
LK.effects.flashObject(fighterGraphics, 0xff0000, 300);
return self.health <= 0;
};
self.isDead = function () {
return self.health <= 0;
};
self.attackTarget = function (target) {
if (!target || target.isDead()) return false;
var distance = Math.sqrt(Math.pow(target.x - self.x, 2) + Math.pow(target.y - self.y, 2));
if (distance <= self.weapon.range && self.weapon.attack()) {
var isDead = target.takeDamage(self.weapon.damage);
// Play sound
if (self.weapon.weaponType === 'fist') {
LK.getSound('punch').play();
} else {
LK.getSound('sword_hit').play();
}
return isDead;
}
return false;
};
self.moveTowards = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
self.x += dx / distance * self.moveSpeed;
self.y += dy / distance * self.moveSpeed;
}
};
self.aiUpdate = function (targets) {
if (self.isDead()) return;
self.aiTimer++;
// Find nearest living target
var nearestTarget = null;
var nearestDistance = Infinity;
for (var i = 0; i < targets.length; i++) {
if (targets[i] !== self && !targets[i].isDead()) {
var distance = Math.sqrt(Math.pow(targets[i].x - self.x, 2) + Math.pow(targets[i].y - self.y, 2));
if (distance < nearestDistance) {
nearestDistance = distance;
nearestTarget = targets[i];
}
}
}
if (nearestTarget) {
// Move towards target if too far
if (nearestDistance > self.weapon.range * 0.8) {
self.moveTowards(nearestTarget.x, nearestTarget.y);
}
// Attack if in range and cooldown is ready
if (nearestDistance <= self.weapon.range && self.aiTimer % 45 === 0) {
self.attackTarget(nearestTarget);
}
}
};
self.update = function () {
// Keep within game bounds
if (self.x < 100) self.x = 100;
if (self.x > 1948) self.x = 1948;
if (self.y < 200) self.y = 200;
if (self.y > 2532) self.y = 2532;
};
return self;
});
var MenuButton = Container.expand(function (text, onClick) {
var self = Container.call(this);
var buttonBg = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(text, {
size: 40,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
tween(buttonBg, {
scaleX: 0.95,
scaleY: 0.95
}, {
duration: 100
});
if (onClick) onClick();
};
self.up = function (x, y, obj) {
tween(buttonBg, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
};
return self;
});
var Weapon = Container.expand(function (weaponType, damage, range) {
var self = Container.call(this);
self.weaponType = weaponType || 'fist';
self.damage = damage || 10;
self.range = range || 50;
self.cooldown = 0;
var weaponGraphics = self.attachAsset(self.weaponType, {
anchorX: 0.5,
anchorY: 0.5
});
self.canAttack = function () {
return self.cooldown <= 0;
};
self.attack = function () {
if (self.canAttack()) {
self.cooldown = 30; // 30 frames cooldown
tween(weaponGraphics, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 100
});
tween(weaponGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
return true;
}
return false;
};
self.update = function () {
if (self.cooldown > 0) {
self.cooldown--;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Sounds
// UI elements
// Weapon assets
// Player and AI character assets for different classes
// Game state
var gameState = 'menu'; // 'menu', 'battle', 'victory', 'defeat'
var battleMode = 'duel'; // 'duel' or 'freeforall'
var playerClass = storage.playerClass || 1;
var playerWins = storage.playerWins || 0;
// UI elements
var titleText = new Text2('Medieval Beatdown', {
size: 80,
fill: 0xECF0F1
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 400;
game.addChild(titleText);
var classText = new Text2('Class ' + playerClass + ' Fighter', {
size: 50,
fill: 0xF39C12
});
classText.anchor.set(0.5, 0.5);
classText.x = 1024;
classText.y = 500;
game.addChild(classText);
var winsText = new Text2('Wins: ' + playerWins, {
size: 40,
fill: 0x95A5A6
});
winsText.anchor.set(0.5, 0.5);
winsText.x = 1024;
winsText.y = 550;
game.addChild(winsText);
var duelButton = game.addChild(new MenuButton('1v1 Duel', function () {
startBattle('duel');
}));
duelButton.x = 1024;
duelButton.y = 700;
var freeForAllButton = game.addChild(new MenuButton('Free For All', function () {
startBattle('freeforall');
}));
freeForAllButton.x = 1024;
freeForAllButton.y = 820;
// Battle variables
var fighters = [];
var player = null;
var dragTarget = null;
var battleTimer = 0;
// Battle result text
var resultText = new Text2('', {
size: 60,
fill: 0xFFFFFF
});
resultText.anchor.set(0.5, 0.5);
resultText.x = 1024;
resultText.y = 1366;
resultText.visible = false;
game.addChild(resultText);
var continueButton = game.addChild(new MenuButton('Continue', function () {
returnToMenu();
}));
continueButton.x = 1024;
continueButton.y = 1500;
continueButton.visible = false;
function startBattle(mode) {
gameState = 'battle';
battleMode = mode;
battleTimer = 0;
// Hide menu elements
titleText.visible = false;
classText.visible = false;
winsText.visible = false;
duelButton.visible = false;
freeForAllButton.visible = false;
resultText.visible = false;
continueButton.visible = false;
// Clear previous fighters
for (var i = 0; i < fighters.length; i++) {
fighters[i].destroy();
}
fighters = [];
// Create player
player = game.addChild(new Fighter(true, playerClass));
player.x = 300;
player.y = 1366;
fighters.push(player);
// Create AI opponents
if (mode === 'duel') {
var enemy = game.addChild(new Fighter(false, playerClass));
enemy.x = 1700;
enemy.y = 1366;
fighters.push(enemy);
} else {
// Free for all - 3 AI opponents
for (var i = 0; i < 3; i++) {
var enemy = game.addChild(new Fighter(false, playerClass));
enemy.x = 1200 + i * 200;
enemy.y = 800 + i * 200;
fighters.push(enemy);
}
}
}
function checkBattleEnd() {
var aliveFighters = [];
var playerAlive = false;
for (var i = 0; i < fighters.length; i++) {
if (!fighters[i].isDead()) {
aliveFighters.push(fighters[i]);
if (fighters[i].isPlayer) {
playerAlive = true;
}
}
}
if (aliveFighters.length <= 1) {
if (playerAlive) {
// Player wins
playerWins++;
storage.playerWins = playerWins;
// Check for class advancement
var winsNeeded = playerClass * 3; // Need 3, 6, 9, 12, 15 wins for each class
if (playerWins >= winsNeeded && playerClass < 5) {
playerClass++;
storage.playerClass = playerClass;
resultText.setText('Victory! Advanced to Class ' + playerClass + '!');
} else {
resultText.setText('Victory! Wins: ' + playerWins);
}
LK.getSound('victory').play();
} else {
// Player loses
resultText.setText('Defeat! Try again!');
LK.getSound('defeat').play();
}
gameState = 'battleEnd';
resultText.visible = true;
continueButton.visible = true;
LK.setTimeout(function () {
// Auto return to menu after 5 seconds
if (gameState === 'battleEnd') {
returnToMenu();
}
}, 5000);
}
}
function returnToMenu() {
gameState = 'menu';
// Update UI text
classText.setText('Class ' + playerClass + ' Fighter');
winsText.setText('Wins: ' + playerWins);
// Show menu elements
titleText.visible = true;
classText.visible = true;
winsText.visible = true;
duelButton.visible = true;
freeForAllButton.visible = true;
resultText.visible = false;
continueButton.visible = false;
// Clear fighters
for (var i = 0; i < fighters.length; i++) {
fighters[i].destroy();
}
fighters = [];
player = null;
dragTarget = null;
}
// Touch controls
game.down = function (x, y, obj) {
if (gameState === 'battle' && player && !player.isDead()) {
dragTarget = player;
// Check for attack - if touching near an enemy, attack instead of move
var attackRange = player.weapon.range + 50;
for (var i = 0; i < fighters.length; i++) {
var fighter = fighters[i];
if (fighter !== player && !fighter.isDead()) {
var distance = Math.sqrt(Math.pow(fighter.x - x, 2) + Math.pow(fighter.y - y, 2));
if (distance <= attackRange) {
player.attackTarget(fighter);
dragTarget = null;
return;
}
}
}
}
};
game.move = function (x, y, obj) {
if (gameState === 'battle' && dragTarget && !dragTarget.isDead()) {
dragTarget.moveTowards(x, y);
}
};
game.up = function (x, y, obj) {
dragTarget = null;
};
game.update = function () {
if (gameState === 'battle') {
battleTimer++;
// Update all fighters
for (var i = 0; i < fighters.length; i++) {
var fighter = fighters[i];
if (!fighter.isDead()) {
if (!fighter.isPlayer) {
fighter.aiUpdate(fighters);
}
}
}
// Check for battle end
checkBattleEnd();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,404 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var Fighter = Container.expand(function (isPlayer, classLevel) {
+ var self = Container.call(this);
+ self.isPlayer = isPlayer || false;
+ self.classLevel = classLevel || 1;
+ self.maxHealth = 100;
+ self.health = self.maxHealth;
+ self.moveSpeed = 3;
+ self.aiTimer = 0;
+ self.lastAttackTime = 0;
+ // Create fighter graphics
+ var assetName = self.isPlayer ? 'player_class' + self.classLevel : 'ai_class' + self.classLevel;
+ var fighterGraphics = self.attachAsset(assetName, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Create weapon based on class
+ var weaponTypes = ['fist', 'sword', 'axe', 'mace', 'halberd'];
+ var damages = [10, 15, 20, 25, 30];
+ var ranges = [50, 70, 60, 55, 90];
+ self.weapon = self.addChild(new Weapon(weaponTypes[self.classLevel - 1], damages[self.classLevel - 1], ranges[self.classLevel - 1]));
+ self.weapon.x = 40;
+ // Create health bar
+ self.healthBarBg = self.attachAsset('health_bar_bg', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ y: -80
+ });
+ self.healthBarFill = self.attachAsset('health_bar_fill', {
+ anchorX: 0,
+ anchorY: 0.5,
+ x: -100,
+ y: -80
+ });
+ self.takeDamage = function (damage) {
+ self.health -= damage;
+ if (self.health < 0) self.health = 0;
+ // Update health bar
+ var healthPercent = self.health / self.maxHealth;
+ self.healthBarFill.width = 200 * healthPercent;
+ // Flash red when taking damage
+ LK.effects.flashObject(fighterGraphics, 0xff0000, 300);
+ return self.health <= 0;
+ };
+ self.isDead = function () {
+ return self.health <= 0;
+ };
+ self.attackTarget = function (target) {
+ if (!target || target.isDead()) return false;
+ var distance = Math.sqrt(Math.pow(target.x - self.x, 2) + Math.pow(target.y - self.y, 2));
+ if (distance <= self.weapon.range && self.weapon.attack()) {
+ var isDead = target.takeDamage(self.weapon.damage);
+ // Play sound
+ if (self.weapon.weaponType === 'fist') {
+ LK.getSound('punch').play();
+ } else {
+ LK.getSound('sword_hit').play();
+ }
+ return isDead;
+ }
+ return false;
+ };
+ self.moveTowards = function (targetX, targetY) {
+ var dx = targetX - self.x;
+ var dy = targetY - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 5) {
+ self.x += dx / distance * self.moveSpeed;
+ self.y += dy / distance * self.moveSpeed;
+ }
+ };
+ self.aiUpdate = function (targets) {
+ if (self.isDead()) return;
+ self.aiTimer++;
+ // Find nearest living target
+ var nearestTarget = null;
+ var nearestDistance = Infinity;
+ for (var i = 0; i < targets.length; i++) {
+ if (targets[i] !== self && !targets[i].isDead()) {
+ var distance = Math.sqrt(Math.pow(targets[i].x - self.x, 2) + Math.pow(targets[i].y - self.y, 2));
+ if (distance < nearestDistance) {
+ nearestDistance = distance;
+ nearestTarget = targets[i];
+ }
+ }
+ }
+ if (nearestTarget) {
+ // Move towards target if too far
+ if (nearestDistance > self.weapon.range * 0.8) {
+ self.moveTowards(nearestTarget.x, nearestTarget.y);
+ }
+ // Attack if in range and cooldown is ready
+ if (nearestDistance <= self.weapon.range && self.aiTimer % 45 === 0) {
+ self.attackTarget(nearestTarget);
+ }
+ }
+ };
+ self.update = function () {
+ // Keep within game bounds
+ if (self.x < 100) self.x = 100;
+ if (self.x > 1948) self.x = 1948;
+ if (self.y < 200) self.y = 200;
+ if (self.y > 2532) self.y = 2532;
+ };
+ return self;
+});
+var MenuButton = Container.expand(function (text, onClick) {
+ var self = Container.call(this);
+ var buttonBg = self.attachAsset('button', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var buttonText = new Text2(text, {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ self.down = function (x, y, obj) {
+ tween(buttonBg, {
+ scaleX: 0.95,
+ scaleY: 0.95
+ }, {
+ duration: 100
+ });
+ if (onClick) onClick();
+ };
+ self.up = function (x, y, obj) {
+ tween(buttonBg, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 100
+ });
+ };
+ return self;
+});
+var Weapon = Container.expand(function (weaponType, damage, range) {
+ var self = Container.call(this);
+ self.weaponType = weaponType || 'fist';
+ self.damage = damage || 10;
+ self.range = range || 50;
+ self.cooldown = 0;
+ var weaponGraphics = self.attachAsset(self.weaponType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.canAttack = function () {
+ return self.cooldown <= 0;
+ };
+ self.attack = function () {
+ if (self.canAttack()) {
+ self.cooldown = 30; // 30 frames cooldown
+ tween(weaponGraphics, {
+ scaleX: 1.5,
+ scaleY: 1.5
+ }, {
+ duration: 100
+ });
+ tween(weaponGraphics, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 100
+ });
+ return true;
+ }
+ return false;
+ };
+ self.update = function () {
+ if (self.cooldown > 0) {
+ self.cooldown--;
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2c3e50
+});
+
+/****
+* Game Code
+****/
+// Sounds
+// UI elements
+// Weapon assets
+// Player and AI character assets for different classes
+// Game state
+var gameState = 'menu'; // 'menu', 'battle', 'victory', 'defeat'
+var battleMode = 'duel'; // 'duel' or 'freeforall'
+var playerClass = storage.playerClass || 1;
+var playerWins = storage.playerWins || 0;
+// UI elements
+var titleText = new Text2('Medieval Beatdown', {
+ size: 80,
+ fill: 0xECF0F1
+});
+titleText.anchor.set(0.5, 0.5);
+titleText.x = 1024;
+titleText.y = 400;
+game.addChild(titleText);
+var classText = new Text2('Class ' + playerClass + ' Fighter', {
+ size: 50,
+ fill: 0xF39C12
+});
+classText.anchor.set(0.5, 0.5);
+classText.x = 1024;
+classText.y = 500;
+game.addChild(classText);
+var winsText = new Text2('Wins: ' + playerWins, {
+ size: 40,
+ fill: 0x95A5A6
+});
+winsText.anchor.set(0.5, 0.5);
+winsText.x = 1024;
+winsText.y = 550;
+game.addChild(winsText);
+var duelButton = game.addChild(new MenuButton('1v1 Duel', function () {
+ startBattle('duel');
+}));
+duelButton.x = 1024;
+duelButton.y = 700;
+var freeForAllButton = game.addChild(new MenuButton('Free For All', function () {
+ startBattle('freeforall');
+}));
+freeForAllButton.x = 1024;
+freeForAllButton.y = 820;
+// Battle variables
+var fighters = [];
+var player = null;
+var dragTarget = null;
+var battleTimer = 0;
+// Battle result text
+var resultText = new Text2('', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+resultText.anchor.set(0.5, 0.5);
+resultText.x = 1024;
+resultText.y = 1366;
+resultText.visible = false;
+game.addChild(resultText);
+var continueButton = game.addChild(new MenuButton('Continue', function () {
+ returnToMenu();
+}));
+continueButton.x = 1024;
+continueButton.y = 1500;
+continueButton.visible = false;
+function startBattle(mode) {
+ gameState = 'battle';
+ battleMode = mode;
+ battleTimer = 0;
+ // Hide menu elements
+ titleText.visible = false;
+ classText.visible = false;
+ winsText.visible = false;
+ duelButton.visible = false;
+ freeForAllButton.visible = false;
+ resultText.visible = false;
+ continueButton.visible = false;
+ // Clear previous fighters
+ for (var i = 0; i < fighters.length; i++) {
+ fighters[i].destroy();
+ }
+ fighters = [];
+ // Create player
+ player = game.addChild(new Fighter(true, playerClass));
+ player.x = 300;
+ player.y = 1366;
+ fighters.push(player);
+ // Create AI opponents
+ if (mode === 'duel') {
+ var enemy = game.addChild(new Fighter(false, playerClass));
+ enemy.x = 1700;
+ enemy.y = 1366;
+ fighters.push(enemy);
+ } else {
+ // Free for all - 3 AI opponents
+ for (var i = 0; i < 3; i++) {
+ var enemy = game.addChild(new Fighter(false, playerClass));
+ enemy.x = 1200 + i * 200;
+ enemy.y = 800 + i * 200;
+ fighters.push(enemy);
+ }
+ }
+}
+function checkBattleEnd() {
+ var aliveFighters = [];
+ var playerAlive = false;
+ for (var i = 0; i < fighters.length; i++) {
+ if (!fighters[i].isDead()) {
+ aliveFighters.push(fighters[i]);
+ if (fighters[i].isPlayer) {
+ playerAlive = true;
+ }
+ }
+ }
+ if (aliveFighters.length <= 1) {
+ if (playerAlive) {
+ // Player wins
+ playerWins++;
+ storage.playerWins = playerWins;
+ // Check for class advancement
+ var winsNeeded = playerClass * 3; // Need 3, 6, 9, 12, 15 wins for each class
+ if (playerWins >= winsNeeded && playerClass < 5) {
+ playerClass++;
+ storage.playerClass = playerClass;
+ resultText.setText('Victory! Advanced to Class ' + playerClass + '!');
+ } else {
+ resultText.setText('Victory! Wins: ' + playerWins);
+ }
+ LK.getSound('victory').play();
+ } else {
+ // Player loses
+ resultText.setText('Defeat! Try again!');
+ LK.getSound('defeat').play();
+ }
+ gameState = 'battleEnd';
+ resultText.visible = true;
+ continueButton.visible = true;
+ LK.setTimeout(function () {
+ // Auto return to menu after 5 seconds
+ if (gameState === 'battleEnd') {
+ returnToMenu();
+ }
+ }, 5000);
+ }
+}
+function returnToMenu() {
+ gameState = 'menu';
+ // Update UI text
+ classText.setText('Class ' + playerClass + ' Fighter');
+ winsText.setText('Wins: ' + playerWins);
+ // Show menu elements
+ titleText.visible = true;
+ classText.visible = true;
+ winsText.visible = true;
+ duelButton.visible = true;
+ freeForAllButton.visible = true;
+ resultText.visible = false;
+ continueButton.visible = false;
+ // Clear fighters
+ for (var i = 0; i < fighters.length; i++) {
+ fighters[i].destroy();
+ }
+ fighters = [];
+ player = null;
+ dragTarget = null;
+}
+// Touch controls
+game.down = function (x, y, obj) {
+ if (gameState === 'battle' && player && !player.isDead()) {
+ dragTarget = player;
+ // Check for attack - if touching near an enemy, attack instead of move
+ var attackRange = player.weapon.range + 50;
+ for (var i = 0; i < fighters.length; i++) {
+ var fighter = fighters[i];
+ if (fighter !== player && !fighter.isDead()) {
+ var distance = Math.sqrt(Math.pow(fighter.x - x, 2) + Math.pow(fighter.y - y, 2));
+ if (distance <= attackRange) {
+ player.attackTarget(fighter);
+ dragTarget = null;
+ return;
+ }
+ }
+ }
+ }
+};
+game.move = function (x, y, obj) {
+ if (gameState === 'battle' && dragTarget && !dragTarget.isDead()) {
+ dragTarget.moveTowards(x, y);
+ }
+};
+game.up = function (x, y, obj) {
+ dragTarget = null;
+};
+game.update = function () {
+ if (gameState === 'battle') {
+ battleTimer++;
+ // Update all fighters
+ for (var i = 0; i < fighters.length; i++) {
+ var fighter = fighters[i];
+ if (!fighter.isDead()) {
+ if (!fighter.isPlayer) {
+ fighter.aiUpdate(fighters);
+ }
+ }
+ }
+ // Check for battle end
+ checkBattleEnd();
+ }
+};
\ No newline at end of file