User prompt
increase the cooldown of regular attack to 1.2 secx
User prompt
make a health potion and spawn it randomly
User prompt
make a cooldown for 1 sec to reagular attacks
User prompt
every attack deals less damage
User prompt
Please fix the bug: 'MainMenu is not defined' in or related to this line: 'var mainMenu = new MainMenu();' Line Number: 33
User prompt
Please fix the bug: 'MainMenu is not defined' in or related to this line: 'var mainMenu = new MainMenu();' Line Number: 33
User prompt
make a main menu for the game
User prompt
reduce it to 1.2 secs
User prompt
make the immobility time 1.5 secs
User prompt
if a fighter is hit with a speacial attack he cant move for 1 second
User prompt
Place the counter above the special attack button that shows how much time is left until the next special attack.
User prompt
make buttons bigger
User prompt
ıncrease the cooldown to 6 secs
User prompt
make a cooldown for 3 seconds for the speccial attack
User prompt
significantly reduce the range of regular attacks
User prompt
reduce the range of regular attacks
User prompt
make the knockback of special attack a lot more
User prompt
remove the number healthbars
User prompt
make the knockback a little stronger
User prompt
add a knockback when a fighter is hit
User prompt
move it down more
User prompt
again
User prompt
move the ground txture down
User prompt
make a throwable class
User prompt
make the player cant hold the jump button
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// --- MainMenu class ---
// Minimal main menu UI with a start button
var MainMenu = Container.expand(function () {
var self = Container.call(this);
// Background overlay
var bg = LK.getAsset('healthbar_bg', {
anchorX: 0.5,
anchorY: 0.5,
width: 2048,
height: 2732,
color: 0x222244
});
bg.alpha = 0.85;
self.addChild(bg);
// Title text
var title = new Text2("Fighter Arena", {
size: 180,
fill: "#fff"
});
title.anchor.set(0.5, 0.5);
title.x = 2048 / 2;
title.y = 700;
self.addChild(title);
// Start button
var startBtn = LK.getAsset('btn_atk', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 1500,
scaleX: 2.2,
scaleY: 2.2
});
self.addChild(startBtn);
// Start text
var startText = new Text2("START", {
size: 90,
fill: "#fff"
});
startText.anchor.set(0.5, 0.5);
startText.x = 2048 / 2;
startText.y = 1500;
self.addChild(startText);
// Start button event
startBtn.down = function () {
if (typeof self.onStart === "function") {
self.onStart();
}
if (self.destroy) self.destroy();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// --- Main menu setup ---
var mainMenu = new MainMenu();
game.addChild(mainMenu);
// Hide all gameplay elements initially
var arena, groundHeight, groundTileWidth, groundY, groundTiles, numGroundTiles, groundTile;
var fighter1, fighter2;
var btnLeft, btnRight, btnAtk, btnJump, btnSpc;
var spcCooldownOverlay, spcCooldownText, spcCooldownCounter;
var leftPressed = false,
rightPressed = false,
atkPressed = false,
jumpPressed = false,
spcPressed = false;
var attacks = [];
var round, maxRounds, wins1, wins2, roundTime, roundTimer, timerText;
// Function to start the game (called from main menu)
function startGame() {
// Remove main menu
if (mainMenu && mainMenu.destroy) mainMenu.destroy();
// --- Arena setup ---
arena = new Arena();
arena.x = 0;
arena.y = 0;
game.addChild(arena);
// --- Fixed ground platform (visual) ---
groundHeight = 60;
groundTileWidth = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
}).width;
groundY = arena.groundY - 100;
groundTiles = [];
numGroundTiles = Math.ceil(2048 / groundTileWidth);
for (var i = 0; i < numGroundTiles; i++) {
groundTile = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: i * groundTileWidth,
y: groundY
});
game.addChild(groundTile);
groundTiles.push(groundTile);
}
// --- Fighters ---
fighter1 = new Fighter();
fighter1.lastJumpPressed = false;
fighter2 = new Fighter();
// Place fighters on opposite sides
fighter1.x = 600;
fighter1.y = arena.groundY;
fighter1.setFacing(true);
fighter2.x = 2048 - 600;
fighter2.y = arena.groundY;
fighter2.setFacing(false);
game.addChild(fighter1);
game.addChild(fighter2);
// --- Health bar GUI ---
fighter1.removeChild(fighter1.healthBar);
fighter2.removeChild(fighter2.healthBar);
fighter1.healthBar.x = -550;
fighter1.healthBar.y = 170;
fighter2.healthBar.x = 250;
fighter2.healthBar.y = 170;
LK.gui.top.addChild(fighter1.healthBar);
LK.gui.top.addChild(fighter2.healthBar);
// --- Round and timer ---
round = 1;
maxRounds = 3;
wins1 = 0;
wins2 = 0;
roundTime = 60 * 30;
roundTimer = roundTime;
timerText = new Text2('30', {
size: 80,
fill: "#fff"
});
timerText.anchor.set(0.5, 0);
LK.gui.top.addChild(timerText);
// --- Touch controls (mobile-friendly) ---
leftPressed = false;
rightPressed = false;
atkPressed = false;
jumpPressed = false;
spcPressed = false;
// Special attack cooldown overlay for button
spcCooldownOverlay = LK.getAsset('healthbar_bg', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 180,
color: 0x000000
});
spcCooldownOverlay.alpha = 0.5;
spcCooldownOverlay.visible = false;
spcCooldownOverlay.x = 2048 - 350;
spcCooldownOverlay.y = 2450;
game.addChild(spcCooldownOverlay);
spcCooldownText = new Text2('3', {
size: 90,
fill: "#fff"
});
spcCooldownText.anchor.set(0.5, 0.5);
spcCooldownText.x = 2048 - 350;
spcCooldownText.y = 2450;
spcCooldownText.visible = false;
game.addChild(spcCooldownText);
// Special attack cooldown counter above the special attack button
spcCooldownCounter = new Text2('', {
size: 60,
fill: "#fff"
});
spcCooldownCounter.anchor.set(0.5, 1.0);
spcCooldownCounter.x = 2048 - 350;
spcCooldownCounter.y = 2450 - 120;
spcCooldownCounter.visible = false;
game.addChild(spcCooldownCounter);
// Control buttons
btnLeft = LK.getAsset('btn_left', {
anchorX: 0.5,
anchorY: 0.5,
x: 200,
y: 2600,
scaleX: 1.8,
scaleY: 1.8
});
btnRight = LK.getAsset('btn_right', {
anchorX: 0.5,
anchorY: 0.5,
x: 500,
y: 2600,
scaleX: 1.8,
scaleY: 1.8
});
btnAtk = LK.getAsset('btn_atk', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 - 500,
y: 2600,
scaleX: 1.8,
scaleY: 1.8
});
btnJump = LK.getAsset('btn_jump', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 - 200,
y: 2600,
scaleX: 1.8,
scaleY: 1.8
});
btnSpc = LK.getAsset('btn_spc', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 - 350,
y: 2450,
scaleX: 1.8,
scaleY: 1.8
});
game.addChild(btnLeft);
game.addChild(btnRight);
game.addChild(btnAtk);
game.addChild(btnJump);
game.addChild(btnSpc);
// Button event helpers
btnLeft.down = function () {
leftPressed = true;
};
btnLeft.up = function () {
leftPressed = false;
};
btnRight.down = function () {
rightPressed = true;
};
btnRight.up = function () {
rightPressed = false;
};
btnAtk.down = function () {
atkPressed = true;
};
btnAtk.up = function () {
atkPressed = false;
};
btnJump.down = function () {
jumpPressed = true;
};
btnJump.up = function () {
jumpPressed = false;
};
btnSpc.down = function () {
spcPressed = true;
};
btnSpc.up = function () {
spcPressed = false;
};
// --- Attacks array ---
attacks = [];
}
// Set up main menu start callback
mainMenu.onStart = startGame;
// --- Game update loop ---
game.update = function () {
// If main menu is visible, do not run game logic
if (mainMenu && mainMenu.parent) {
return;
}
// --- Timer ---
if (roundTimer > 0) {
roundTimer--;
timerText.setText(Math.ceil(roundTimer / 60));
}
// --- Ground is fixed, no update needed ---
// --- Player 1 controls (left side) ---
if (!fighter1.immobile) {
if (leftPressed) {
fighter1.x = Math.max(120, fighter1.x - fighter1.moveSpeed);
fighter1.setFacing(false);
}
if (rightPressed) {
fighter1.x = Math.min(2048 - 120, fighter1.x + fighter1.moveSpeed);
fighter1.setFacing(true);
}
// Only trigger jump on the frame the button is pressed (rising edge)
if (jumpPressed && !fighter1.lastJumpPressed) {
fighter1.jump();
}
if (atkPressed) {
fighter1.attack();
}
if (spcPressed) {
if (fighter1.isSpecialReady) {
fighter1.special();
}
}
}
fighter1.lastJumpPressed = jumpPressed;
// --- Special attack cooldown overlay update ---
if (!fighter1.isSpecialReady) {
spcCooldownOverlay.visible = true;
spcCooldownText.visible = true;
var secondsLeft = Math.ceil(fighter1.specialTimer / 60);
spcCooldownText.setText(secondsLeft);
// Show and update the counter above the special button
spcCooldownCounter.visible = true;
spcCooldownCounter.setText(secondsLeft + "s");
} else {
spcCooldownOverlay.visible = false;
spcCooldownText.visible = false;
spcCooldownCounter.visible = false;
}
// --- AI for fighter2 (simple: move toward player, attack if close) ---
if (!fighter2.immobile) {
var dx = fighter1.x - fighter2.x;
if (Math.abs(dx) > 180) {
if (dx < 0) {
fighter2.x -= fighter2.moveSpeed * 0.7;
fighter2.setFacing(false);
} else {
fighter2.x += fighter2.moveSpeed * 0.7;
fighter2.setFacing(true);
}
} else if (!fighter2.isAttacking && Math.random() < 0.04) {
fighter2.attack();
}
if (!fighter2.isJumping && Math.random() < 0.01) {
fighter2.jump();
}
if (fighter2.isSpecialReady && Math.random() < 0.008) {
fighter2.special();
}
}
// --- Update fighters ---
fighter1.update();
fighter2.update();
// --- Update attacks ---
for (var i = attacks.length - 1; i >= 0; i--) {
var atk = attacks[i];
atk.update();
// Remove if destroyed
if (atk.destroyed) {
attacks.splice(i, 1);
continue;
}
// Set owner if not set
if (!atk.owner) {
atk.setOwner(atk.isSpecial ? atk.x < 2048 / 2 ? fighter1 : fighter2 : fighter1);
}
// Check collision
var target = atk.owner === fighter1 ? fighter2 : fighter1;
if (atk.intersects(target) && !atk.hit) {
// Knockback direction: +1 if attacker is facing right, -1 if left
var knockbackDir = atk.owner && atk.owner.isFacingRight ? 1 : -1;
// Knockback strength: special attacks knock back a LOT more (much stronger effect)
var knockbackStrength = atk.isSpecial ? 120 : 32;
target.takeDamage(atk.damage, knockbackDir, knockbackStrength);
atk.hit = true;
atk.destroy();
// Flash on hit
LK.effects.flashObject(target, 0xff0000, 200);
// Show a visible attack effect at the hit location, rotated to match the attack direction
var hitEffect = LK.getAsset(atk.isSpecial ? 'special_attack' : 'attack', {
anchorX: 0.5,
anchorY: 0.5,
x: target.x,
y: target.y - 200
});
// Rotate the effect to match the direction the attacker is facing
if (atk.owner && atk.owner.isFacingRight === false) {
hitEffect.rotation = Math.PI; // Face left
} else {
hitEffect.rotation = 0; // Face right (default)
}
game.addChild(hitEffect);
// Animate the effect: scale up and fade out, then destroy
hitEffect.scaleX = hitEffect.scaleY = 1.2;
hitEffect.alpha = 1;
tween(hitEffect, {
scaleX: 2.0,
scaleY: 2.0,
alpha: 0
}, {
duration: 350,
onFinish: function onFinish() {
if (hitEffect && hitEffect.destroy) hitEffect.destroy();
}
});
}
}
// --- Health bar updates ---
// Removed number healthbars update
// --- Win/lose/round logic ---
var roundOver = false;
var winner = null;
if (fighter1.health <= 0) {
wins2++;
roundOver = true;
winner = 2;
} else if (fighter2.health <= 0) {
wins1++;
roundOver = true;
winner = 1;
} else if (roundTimer <= 0) {
if (fighter1.health > fighter2.health) {
wins1++;
winner = 1;
} else if (fighter2.health > fighter1.health) {
wins2++;
winner = 2;
} else {
// Draw, no one gets a win
}
roundOver = true;
}
if (roundOver) {
if (wins1 >= 2) {
LK.showYouWin();
return;
} else if (wins2 >= 2) {
LK.showGameOver();
return;
}
// Next round
round++;
roundTimer = roundTime;
fighter1.health = fighter1.maxHealth;
fighter2.health = fighter2.maxHealth;
fighter1.updateHealthBar();
fighter2.updateHealthBar();
fighter1.x = 600;
fighter2.x = 2048 - 600;
fighter1.setFacing(true);
fighter2.setFacing(false);
// Remove all attacks
for (var j = attacks.length - 1; j >= 0; j--) {
if (attacks[j].destroy) attacks[j].destroy();
}
attacks = [];
}
}; ===================================================================
--- original.js
+++ change.js
@@ -18,26 +18,24 @@
height: 2732,
color: 0x222244
});
bg.alpha = 0.85;
- bg.x = 2048 / 2;
- bg.y = 2732 / 2;
self.addChild(bg);
// Title text
var title = new Text2("Fighter Arena", {
size: 180,
fill: "#fff"
});
title.anchor.set(0.5, 0.5);
title.x = 2048 / 2;
- title.y = 900;
+ title.y = 700;
self.addChild(title);
// Start button
var startBtn = LK.getAsset('btn_atk', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
- y: 1600,
+ y: 1500,
scaleX: 2.2,
scaleY: 2.2
});
self.addChild(startBtn);
@@ -47,13 +45,11 @@
fill: "#fff"
});
startText.anchor.set(0.5, 0.5);
startText.x = 2048 / 2;
- startText.y = 1600;
+ startText.y = 1500;
self.addChild(startText);
- // Callback for start
- self.onStart = null;
- // Button event
+ // Start button event
startBtn.down = function () {
if (typeof self.onStart === "function") {
self.onStart();
}