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 Blood = Container.expand(function () {
var self = Container.call(this);
var bloodDrop = self.attachAsset('specialEffect', {
anchorX: 0.5,
anchorY: 0.5
});
bloodDrop.tint = 0xff0000;
self.lifetime = 30;
self.velocityX = (Math.random() - 0.5) * 8;
self.velocityY = Math.random() * -6 - 2;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.lifetime -= 1;
self.alpha = self.lifetime / 30;
if (self.lifetime <= 0) {
self.destroy();
}
};
return self;
});
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 Fatality = Container.expand(function () {
var self = Container.call(this);
var fatalityText = new Text2('FATALITY', {
size: 200,
fill: '#ff0000'
});
fatalityText.anchor.set(0.5, 0.5);
fatalityText.x = 1024;
fatalityText.y = 1366;
self.addChild(fatalityText);
self.scale.x = 0;
self.scale.y = 0;
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.elasticOut
});
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.specialCooldown = 0;
self.isFrozen = false;
self.freezeTimer = 0;
self.isJumping = false;
self.jumpVelocity = 0;
self.jumpCooldown = 0;
self.setCharacter = function (charName) {
self.character = charName;
};
self.jump = function () {
if (self.jumpCooldown > 0) return false;
self.isJumping = true;
self.jumpVelocity = -20;
self.jumpCooldown = 600;
return true;
};
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 || self.specialCooldown > 0) return false;
self.energy -= 40;
self.isAttacking = true;
self.attackCooldown = 40;
self.specialCooldown = 1800;
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);
for (var i = 0; i < 3; i++) {
var bloodEffect = game.addChild(new Blood());
bloodEffect.x = self.x + (Math.random() - 0.5) * 50;
bloodEffect.y = self.y - 100 + (Math.random() - 0.5) * 50;
}
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.freeze = function () {
self.isFrozen = true;
self.freezeTimer = 1800;
self.isAttacking = false;
self.attackCooldown = 0;
LK.effects.flashObject(self, 0x00ccff, 300);
};
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);
if (self.specialCooldown > 0) {
self.specialCooldown -= 1;
}
if (self.isFrozen && self.freezeTimer > 0) {
self.freezeTimer -= 1;
} else if (self.isFrozen) {
self.isFrozen = false;
}
if (self.isJumping) {
self.jumpVelocity += 0.8;
self.y += self.jumpVelocity;
if (self.y >= 1800) {
self.y = 1800;
self.isJumping = false;
self.jumpVelocity = 0;
}
}
if (self.jumpCooldown > 0) {
self.jumpCooldown -= 1;
}
};
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 mapBg = game.addChild(LK.getAsset('mapBackground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
mapBg.alpha = 0.6;
var player = game.addChild(new Fighter());
player.x = 512;
player.y = 1800;
player.direction = 1;
player.setCharacter('subzero');
var playerGraphics = player.children[0];
playerGraphics.tint = 0x0066ff;
var opponent = game.addChild(new Fighter());
opponent.x = 1536;
opponent.y = 1800;
opponent.direction = -1;
opponent.setCharacter('scorpion');
var oppGraphics = opponent.children[0];
oppGraphics.tint = 0xff0000;
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 = [];
var fatalityCountdown = 0;
var fatalityActive = false;
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' ? 5 : attacker.attackType === 'kick' ? 15 : 25;
return damage;
}
return 0;
}
var aiAttackCounter = 0;
var aiPattern = [10, 30, 50, 70, 35, 15];
var aiPatternIndex = 0;
var aiJumpCooldown = 0;
function updateAI() {
if (opponent.health <= 0 || gameState !== 'playing') return;
aiAttackCounter += 1;
if (aiJumpCooldown > 0) {
aiJumpCooldown -= 1;
return;
}
// AI movement logic
var distanceToPlayer = Math.abs(opponent.x - player.x);
var preferredDistance = 400;
var moveSpeed = 3;
var minX = 256;
var maxX = 1792;
if (distanceToPlayer > preferredDistance) {
// Move towards player
if (opponent.x < player.x) {
opponent.x = Math.min(opponent.x + moveSpeed, maxX);
} else {
opponent.x = Math.max(opponent.x - moveSpeed, minX);
}
} else if (distanceToPlayer < preferredDistance - 100) {
// Move away from player
if (opponent.x < player.x) {
opponent.x = Math.max(opponent.x - moveSpeed, minX);
} else {
opponent.x = Math.min(opponent.x + moveSpeed, maxX);
}
}
if (aiAttackCounter >= aiPattern[aiPatternIndex]) {
aiAttackCounter = 0;
aiPatternIndex = (aiPatternIndex + 1) % aiPattern.length;
var random = Math.random();
if (opponent.energy >= 40 && opponent.specialCooldown <= 0 && random < 0.25) {
opponent.special();
player.freeze();
} else if (random < 0.5) {
opponent.punch();
} else {
opponent.kick();
}
}
}
var playerClickCount = 0;
var lastClickTime = 0;
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.move = function (x, y, obj) {
// Mouse/touch movement controls player horizontal position
// Constrain player movement between left and right boundaries
var minX = 256;
var maxX = 1792;
player.x = Math.max(minX, Math.min(x, maxX));
}; //{1Z-a}
game.down = function (x, y, obj) {
if (fatalityActive && gameState === 'fatalityMode') {
// Perform fatality
var fatalityDisplay = game.addChild(new Fatality());
LK.getSound('fatality').play();
gameState = 'victory';
fatalityCountdown = 0;
fatalityActive = false;
LK.setTimeout(function () {
storage.tournament_level += 1;
LK.setScore(LK.getScore() + 50);
LK.showYouWin();
}, 1500);
return;
}
// Check for double click jump
var currentTime = LK.ticks;
if (currentTime - lastClickTime < 15) {
playerClickCount += 1;
} else {
playerClickCount = 1;
}
lastClickTime = currentTime;
if (playerClickCount >= 2) {
player.jump();
opponent.jump();
playerClickCount = 0;
return;
}
// Determine attack based on horizontal screen position
var screenWidth = 2048;
var thirdWidth = screenWidth / 3;
if (x < thirdWidth) {
// Left third: punch
player.punch();
} else if (x < 2 * thirdWidth) {
// Middle third: kick
player.kick();
} else {
// Right third: special freeze
if (player.special()) {
opponent.freeze();
}
}
};
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.isFrozen) {
opponent.takeDamage(playerDamage);
}
var opponentHitbox = getOpponentAttackHitbox();
var opponentDamage = checkHitboxCollision(opponent, opponentHitbox, player);
if (opponentDamage > 0 && !player.isFrozen) {
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 === 'playing') {
gameState = 'fatalityMode';
fatalityActive = true;
fatalityCountdown = 300;
LK.effects.flashScreen(0x00ff00, 500);
// Change fighter images to fatality poses
player.removeChild(playerGraphics);
playerGraphics = player.attachAsset('playerFatality', {
anchorX: 0.5,
anchorY: 1.0
});
playerGraphics.tint = 0x0066ff;
opponent.removeChild(oppGraphics);
oppGraphics = opponent.attachAsset('opponentFatality', {
anchorX: 0.5,
anchorY: 1.0
});
oppGraphics.tint = 0xff0000;
}
if (fatalityActive && gameState === 'fatalityMode') {
fatalityCountdown -= 1;
if (fatalityCountdown <= 0) {
gameState = 'victory';
LK.getSound('fatality').play();
LK.setTimeout(function () {
storage.tournament_level += 1;
LK.setScore(LK.getScore() + 50);
LK.showYouWin();
}, 1000);
fatalityActive = false;
}
}
var elapsedRounds = Math.floor((LK.ticks - roundStartTime) / roundDuration);
roundText.setText('ROUND ' + (elapsedRounds + 1));
}; ===================================================================
--- original.js
+++ change.js
@@ -102,11 +102,21 @@
self.attackType = null;
self.specialCooldown = 0;
self.isFrozen = false;
self.freezeTimer = 0;
+ self.isJumping = false;
+ self.jumpVelocity = 0;
+ self.jumpCooldown = 0;
self.setCharacter = function (charName) {
self.character = charName;
};
+ self.jump = function () {
+ if (self.jumpCooldown > 0) return false;
+ self.isJumping = true;
+ self.jumpVelocity = -20;
+ self.jumpCooldown = 600;
+ return true;
+ };
self.punch = function () {
if (self.isAttacking || self.attackCooldown > 0) return false;
self.isAttacking = true;
self.attackCooldown = 15;
@@ -194,8 +204,20 @@
self.freezeTimer -= 1;
} else if (self.isFrozen) {
self.isFrozen = false;
}
+ if (self.isJumping) {
+ self.jumpVelocity += 0.8;
+ self.y += self.jumpVelocity;
+ if (self.y >= 1800) {
+ self.y = 1800;
+ self.isJumping = false;
+ self.jumpVelocity = 0;
+ }
+ }
+ if (self.jumpCooldown > 0) {
+ self.jumpCooldown -= 1;
+ }
};
return self;
});
var HealthBar = Container.expand(function () {
@@ -321,11 +343,16 @@
}
var aiAttackCounter = 0;
var aiPattern = [10, 30, 50, 70, 35, 15];
var aiPatternIndex = 0;
+var aiJumpCooldown = 0;
function updateAI() {
if (opponent.health <= 0 || gameState !== 'playing') return;
aiAttackCounter += 1;
+ if (aiJumpCooldown > 0) {
+ aiJumpCooldown -= 1;
+ return;
+ }
// AI movement logic
var distanceToPlayer = Math.abs(opponent.x - player.x);
var preferredDistance = 400;
var moveSpeed = 3;
@@ -359,8 +386,10 @@
opponent.kick();
}
}
}
+var playerClickCount = 0;
+var lastClickTime = 0;
var playerTouchZones = {
punch: {
x: 200,
y: 2400,
@@ -438,8 +467,22 @@
LK.showYouWin();
}, 1500);
return;
}
+ // Check for double click jump
+ var currentTime = LK.ticks;
+ if (currentTime - lastClickTime < 15) {
+ playerClickCount += 1;
+ } else {
+ playerClickCount = 1;
+ }
+ lastClickTime = currentTime;
+ if (playerClickCount >= 2) {
+ player.jump();
+ opponent.jump();
+ playerClickCount = 0;
+ return;
+ }
// Determine attack based on horizontal screen position
var screenWidth = 2048;
var thirdWidth = screenWidth / 3;
if (x < thirdWidth) {