User prompt
haz que cuando el p1 preciona 2 vezes click salte y el cpu salte y espera 10 segundos ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
haz que cuando el p1 osea sub-zero clkique el cklick derecho agha un movimiento especial congelar al opponente y esperar 30 segundos.Para el cpu es el spear y el cpu tambien tiene que esperar 30 segundos para recargar el movimiento especial ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
haz que cuando dice fatality el p1 cambie a imagen "playerfatality" y el de cpu "opponetfatality"
User prompt
haz que cuando se muestra fatality la imagen de p1 y cpu cambie a otra imagen
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'tween(self, {' Line Number: 94
User prompt
haz que cuando el cpu se quede sin vida el p1 tiene 5 segundos para hacer una fatalidad ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
haz que el fondo sea un mapa
User prompt
haz que cada vez que el enemigo golpea o el p1 golpea al cpu le sale sangre
User prompt
haz que el Cpu tambien se mueva
User prompt
haz que cada golpe es -5
User prompt
haz que el p1 se puedea controlar con mouse
User prompt
haz que el p1 es sub-zero y el CPU es scorpion
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toGlobal')' in or related to this line: 'var gameCoords = game.toLocal(obj.parent.toGlobal({' Line Number: 350
Code edit (1 edits merged)
Please save this source code
User prompt
Mortal Kombat Trilogy
Initial prompt
quiero crear un juego 2D que se trata de Mortal Kombat Trilogy
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
currentCharacter: "scorpion",
unlockedCharacters: ["scorpion", "subzero"],
tournament_level: 1
});
/****
* Classes
****/
var EnergyBar = Container.expand(function () {
var self = Container.call(this);
var bgBar = self.attachAsset('energyBarBg', {
anchorX: 0.5,
anchorY: 0.5
});
var fillBar = self.attachAsset('energyBarFill', {
anchorX: 0.0,
anchorY: 0.5
});
fillBar.x = -150;
self.maxEnergy = 100;
self.currentEnergy = 0;
self.updateEnergy = function (energy) {
self.currentEnergy = Math.max(0, Math.min(energy, self.maxEnergy));
var fillWidth = self.currentEnergy / self.maxEnergy * 300;
fillBar.width = fillWidth;
};
self.regenEnergy = function (amount) {
self.updateEnergy(self.currentEnergy + amount);
};
self.consumeEnergy = function (amount) {
self.updateEnergy(self.currentEnergy - amount);
};
self.updateEnergy(0);
return self;
});
var Fighter = Container.expand(function () {
var self = Container.call(this);
var fighterGraphics = self.attachAsset('playerBase', {
anchorX: 0.5,
anchorY: 1.0
});
self.character = 'scorpion';
self.health = 100;
self.maxHealth = 100;
self.energy = 0;
self.maxEnergy = 100;
self.isAttacking = false;
self.attackCooldown = 0;
self.direction = 1;
self.isHit = false;
self.hitCooldown = 0;
self.comboCount = 0;
self.comboTimer = 0;
self.lastAttackTime = 0;
self.attackType = null;
self.setCharacter = function (charName) {
self.character = charName;
};
self.punch = function () {
if (self.isAttacking || self.attackCooldown > 0) return false;
self.isAttacking = true;
self.attackCooldown = 15;
self.attackType = 'punch';
self.comboCount += 1;
self.comboTimer = 30;
LK.getSound('punch').play();
LK.effects.flashObject(self, 0xffffff, 100);
return true;
};
self.kick = function () {
if (self.isAttacking || self.attackCooldown > 0) return false;
self.isAttacking = true;
self.attackCooldown = 20;
self.attackType = 'kick';
self.comboCount += 1;
self.comboTimer = 30;
LK.getSound('kick').play();
LK.effects.flashObject(self, 0xffffff, 100);
return true;
};
self.special = function () {
if (self.isAttacking || self.attackCooldown > 0 || self.energy < 40) return false;
self.energy -= 40;
self.isAttacking = true;
self.attackCooldown = 40;
self.attackType = 'special';
self.comboCount = 0;
LK.getSound('special').play();
LK.effects.flashObject(self, 0xffff00, 200);
return true;
};
self.takeDamage = function (damage) {
if (self.isHit) return;
var actualDamage = damage * (1 + self.comboCount * 0.1);
self.health -= actualDamage;
self.isHit = true;
self.hitCooldown = 10;
LK.getSound('hit').play();
LK.effects.flashObject(self, 0xff0000, 150);
return Math.max(0, self.health);
};
self.heal = function (amount) {
self.health = Math.min(self.health + amount, self.maxHealth);
};
self.gainEnergy = function (amount) {
self.energy = Math.min(self.energy + amount, self.maxEnergy);
};
self.update = function () {
if (self.attackCooldown > 0) {
self.attackCooldown -= 1;
}
if (self.attackCooldown <= 0) {
self.isAttacking = false;
}
if (self.hitCooldown > 0) {
self.hitCooldown -= 1;
}
if (self.hitCooldown <= 0) {
self.isHit = false;
}
if (self.comboTimer > 0) {
self.comboTimer -= 1;
} else {
self.comboCount = 0;
}
self.energy = Math.min(self.energy + 0.5, self.maxEnergy);
};
return self;
});
var HealthBar = Container.expand(function () {
var self = Container.call(this);
var bgBar = self.attachAsset('healthBarBg', {
anchorX: 0.5,
anchorY: 0.5
});
var fillBar = self.attachAsset('healthBarFill', {
anchorX: 0.0,
anchorY: 0.5
});
fillBar.x = -150;
self.maxHealth = 100;
self.currentHealth = 100;
self.updateHealth = function (health) {
self.currentHealth = Math.max(0, Math.min(health, self.maxHealth));
var fillWidth = self.currentHealth / self.maxHealth * 300;
fillBar.width = fillWidth;
if (self.currentHealth <= self.maxHealth * 0.3) {
fillBar.tint = 0xff0000;
} else if (self.currentHealth <= self.maxHealth * 0.6) {
fillBar.tint = 0xffff00;
} else {
fillBar.tint = 0x00ff00;
}
};
self.updateHealth(100);
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
var player = game.addChild(new Fighter());
player.x = 512;
player.y = 1800;
player.direction = 1;
var opponent = game.addChild(new Fighter());
opponent.x = 1536;
opponent.y = 1800;
opponent.direction = -1;
opponent.setCharacter('subzero');
var oppGraphics = opponent.children[0];
oppGraphics.tint = 0x0066ff;
var playerHealthBar = game.addChild(new HealthBar());
playerHealthBar.x = 200;
playerHealthBar.y = 100;
var opponentHealthBar = game.addChild(new HealthBar());
opponentHealthBar.x = 1848;
opponentHealthBar.y = 100;
var playerEnergyBar = game.addChild(new EnergyBar());
playerEnergyBar.x = 200;
playerEnergyBar.y = 180;
var opponentEnergyBar = game.addChild(new EnergyBar());
opponentEnergyBar.x = 1848;
opponentEnergyBar.y = 180;
var roundText = new Text2('ROUND 1', {
size: 120,
fill: '#ff0000'
});
roundText.anchor.set(0.5, 0.5);
roundText.x = 1024;
roundText.y = 400;
LK.gui.center.addChild(roundText);
var comboText = new Text2('', {
size: 60,
fill: '#ffff00'
});
comboText.anchor.set(0.5, 0);
comboText.x = 1024;
comboText.y = 600;
LK.gui.center.addChild(comboText);
var gameState = 'playing';
var roundStartTime = LK.ticks;
var roundDuration = 600;
var battleLog = [];
function getPlayerAttackHitbox() {
var hitbox = {
x: player.x + 100 * player.direction,
y: player.y - 150,
width: player.attackType === 'kick' ? 100 : 80,
height: player.attackType === 'kick' ? 80 : 60
};
return hitbox;
}
function getOpponentAttackHitbox() {
var hitbox = {
x: opponent.x + 100 * opponent.direction,
y: opponent.y - 150,
width: opponent.attackType === 'kick' ? 100 : 80,
height: opponent.attackType === 'kick' ? 80 : 60
};
return hitbox;
}
function checkHitboxCollision(attacker, attackerHitbox, defender) {
var distance = Math.abs(attacker.x - defender.x);
var maxDistance = attackerHitbox.width + 75;
if (distance <= maxDistance && attacker.isAttacking && !defender.isHit) {
var damage = attacker.attackType === 'punch' ? 10 : attacker.attackType === 'kick' ? 15 : 25;
return damage;
}
return 0;
}
var aiAttackCounter = 0;
var aiPattern = [10, 30, 50, 70, 35, 15];
var aiPatternIndex = 0;
function updateAI() {
if (opponent.health <= 0 || gameState !== 'playing') return;
aiAttackCounter += 1;
if (aiAttackCounter >= aiPattern[aiPatternIndex]) {
aiAttackCounter = 0;
aiPatternIndex = (aiPatternIndex + 1) % aiPattern.length;
var random = Math.random();
if (opponent.energy >= 40 && random < 0.2) {
opponent.special();
} else if (random < 0.5) {
opponent.punch();
} else {
opponent.kick();
}
}
}
var playerTouchZones = {
punch: {
x: 200,
y: 2400,
w: 400,
h: 300
},
kick: {
x: 650,
y: 2400,
w: 400,
h: 300
},
special: {
x: 1100,
y: 2400,
w: 400,
h: 300
}
};
function handlePlayerAttack(x, y) {
for (var zone in playerTouchZones) {
var z = playerTouchZones[zone];
if (x >= z.x && x <= z.x + z.w && y >= z.y && y <= z.y + z.h) {
if (zone === 'punch') {
player.punch();
} else if (zone === 'kick') {
player.kick();
} else if (zone === 'special') {
player.special();
}
return true;
}
}
return false;
}
var playerAttackZones = [{
label: 'PUNCH',
zone: playerTouchZones.punch
}, {
label: 'KICK',
zone: playerTouchZones.kick
}, {
label: 'SPECIAL',
zone: playerTouchZones.special
}];
for (var i = 0; i < playerAttackZones.length; i++) {
var zone = playerAttackZones[i];
var zoneText = new Text2(zone.label, {
size: 40,
fill: '#ffffff'
});
zoneText.anchor.set(0.5, 0.5);
zoneText.x = zone.zone.x + zone.zone.w / 2;
zoneText.y = zone.zone.y + zone.zone.h / 2;
LK.gui.bottom.addChild(zoneText);
}
game.down = function (x, y, obj) {
handlePlayerAttack(x, y);
};
game.update = function () {
if (gameState !== 'playing') return;
player.update();
opponent.update();
updateAI();
var playerHitbox = getPlayerAttackHitbox();
var playerDamage = checkHitboxCollision(player, playerHitbox, opponent);
if (playerDamage > 0) {
opponent.takeDamage(playerDamage);
}
var opponentHitbox = getOpponentAttackHitbox();
var opponentDamage = checkHitboxCollision(opponent, opponentHitbox, player);
if (opponentDamage > 0) {
player.takeDamage(opponentDamage);
}
playerHealthBar.updateHealth(player.health);
opponentHealthBar.updateHealth(opponent.health);
playerEnergyBar.updateEnergy(player.energy);
opponentEnergyBar.updateEnergy(opponent.energy);
if (player.comboCount > 0) {
comboText.setText('COMBO x' + player.comboCount);
} else {
comboText.setText('');
}
if (player.health <= 0) {
gameState = 'gameOver';
LK.effects.flashScreen(0xff0000, 500);
LK.setTimeout(function () {
LK.getSound('victory').play();
LK.showGameOver();
}, 500);
}
if (opponent.health <= 0) {
gameState = 'victory';
LK.effects.flashScreen(0x00ff00, 500);
LK.getSound('fatality').play();
LK.setTimeout(function () {
storage.tournament_level += 1;
LK.setScore(LK.getScore() + 50);
LK.showYouWin();
}, 1000);
}
var elapsedRounds = Math.floor((LK.ticks - roundStartTime) / roundDuration);
roundText.setText('ROUND ' + (elapsedRounds + 1));
}; ===================================================================
--- original.js
+++ change.js
@@ -317,13 +317,9 @@
zoneText.y = zone.zone.y + zone.zone.h / 2;
LK.gui.bottom.addChild(zoneText);
}
game.down = function (x, y, obj) {
- var gameCoords = game.toLocal(obj.parent.toGlobal({
- x: x,
- y: y
- }));
- handlePlayerAttack(gameCoords.x, gameCoords.y);
+ handlePlayerAttack(x, y);
};
game.update = function () {
if (gameState !== 'playing') return;
player.update();