User prompt
make a ui background for the time and number healthbars
User prompt
add an outline for the box healthbars
User prompt
make a 0.3 second colldown for jumping
User prompt
make jumping slower
User prompt
make less gravity
User prompt
make the attack effects the direction figther looking
User prompt
make attack effects visible
User prompt
make If a warrior jumps, he will not take any damage.
User prompt
make the reagular attack deal less damage
User prompt
now move a little bit down
User prompt
now little little bit right
User prompt
now a little bit right
User prompt
little bit more
User prompt
movethe box healthbars a little left
User prompt
movethe box healthbars to a more visible place symetrically
User prompt
move the box healthbars near the number healthbars
User prompt
make the attack effec last longer ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make the explosion effect slower and last longer ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'ReferenceError: tween is not defined' in or related to this line: 'tween.to(self.sprite, {' Line Number: 50 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make the attack effects apper with explosion effect
User prompt
make the attack effect an asset
User prompt
move the both healthbars a little bit closer to the middle
User prompt
move the enemys health bar to the top right of the screenü
User prompt
move the players healthbar to the top left of the screen
User prompt
the ai enemys healthbar on the right side and the player healthbar is on the left side
/**** * Classes ****/ // Arena class: handles the ground and background var Arena = Container.expand(function () { var self = Container.call(this); // Attach background asset self.bg = self.attachAsset('arena_bg', { anchorX: 0.5, anchorY: 1.0, x: 2048 / 2, y: 2732 }); // Ground Y for fighters self.groundY = 2100; return self; }); // Attack class: represents a punch/kick or special move var Attack = Container.expand(function (isSpecial) { var self = Container.call(this); self.isSpecial = isSpecial === true; self.owner = null; self.damage = self.isSpecial ? 35 : 15; self.lifetime = self.isSpecial ? 30 : 12; self.frame = 0; // Attach asset self.sprite = self.attachAsset(self.isSpecial ? 'special_attack' : 'attack', { anchorX: 0.5, anchorY: 0.5 }); // Set color for visual feedback self.sprite.tint = self.isSpecial ? 0x00ffff : 0xffcc00; // Set owner after creation self.setOwner = function (owner) { self.owner = owner; }; // Update per frame self.update = function () { self.frame++; if (self.frame > self.lifetime) { self.destroy(); } }; return self; }); var Fighter = Container.expand(function () { var self = Container.call(this); // Attach fighter asset (placeholder box, can be replaced with unique fighter art) self.sprite = self.attachAsset('fighter', { anchorX: 0.5, anchorY: 1.0 }); // Fighter properties self.maxHealth = 100; self.health = 100; self.isFacingRight = true; self.isJumping = false; self.isAttacking = false; self.isSpecialReady = true; self.specialCooldown = 180; // 3 seconds at 60fps self.specialTimer = 0; self.moveSpeed = 18; self.jumpPower = -60; self.gravity = 6; self.velY = 0; self.groundY = 2100; // Default ground Y, will be set by Arena // Health bar self.healthBar = new Container(); self.healthBarBg = self.healthBar.addChild(LK.getAsset('healthbar_bg', { anchorX: 0, anchorY: 0.5 })); self.healthBarFg = self.healthBar.addChild(LK.getAsset('healthbar_fg', { anchorX: 0, anchorY: 0.5 })); self.healthBar.y = -220; self.addChild(self.healthBar); // Update health bar self.updateHealthBar = function () { // No longer update fighter-attached health bars, update global bars instead if (typeof updateHealthBar1 === "function" && self === fighter1) { updateHealthBar1(); } if (typeof updateHealthBar2 === "function" && self === fighter2) { updateHealthBar2(); } }; // Take damage self.takeDamage = function (amount) { self.health = Math.max(0, self.health - amount); self.updateHealthBar(); }; // Attack self.attack = function () { if (self.isAttacking) return; self.isAttacking = true; var atk = new Attack(self, false); atk.x = self.x + (self.isFacingRight ? 120 : -120); atk.y = self.y - 180; self.parent.addChild(atk); LK.setTimeout(function () { self.isAttacking = false; }, 300); }; // Special move self.special = function () { if (!self.isSpecialReady) return; self.isSpecialReady = false; self.specialTimer = self.specialCooldown; var atk = new Attack(self, true); atk.x = self.x + (self.isFacingRight ? 180 : -180); atk.y = self.y - 180; self.parent.addChild(atk); }; // Jump self.jump = function () { if (self.isJumping) return; self.isJumping = true; self.velY = self.jumpPower; }; // Update per frame self.update = function () { // Special cooldown if (!self.isSpecialReady) { self.specialTimer--; if (self.specialTimer <= 0) { self.isSpecialReady = true; } } // Jump physics if (self.isJumping) { self.y += self.velY; self.velY += self.gravity; if (self.y >= self.groundY) { self.y = self.groundY; self.isJumping = false; self.velY = 0; } } }; // Flip sprite self.setFacing = function (right) { self.isFacingRight = right; self.sprite.scaleX = right ? 1 : -1; }; // Initialize health bar self.updateHealthBar(); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // --- Health bars are now shown at the top of the screen --- // (No need to remove fighter-attached health bars, as global bars are used) // Create global health bar containers var healthBar1 = new Container(); var healthBar2 = new Container(); var healthBar1Bg = healthBar1.addChild(LK.getAsset('healthbar_bg', { anchorX: 0, anchorY: 0.5 })); var healthBar1Fg = healthBar1.addChild(LK.getAsset('healthbar_fg', { anchorX: 0, anchorY: 0.5 })); var healthBar2Bg = healthBar2.addChild(LK.getAsset('healthbar_bg', { anchorX: 1, anchorY: 0.5 })); var healthBar2Fg = healthBar2.addChild(LK.getAsset('healthbar_fg', { anchorX: 1, anchorY: 0.5 })); // Set bar sizes and positions healthBar1Bg.width = 300; healthBar1Fg.width = 300; healthBar2Bg.width = 300; healthBar2Fg.width = 300; // Player health bar (left) healthBar1.x = 120; healthBar1.y = 100; // AI enemy health bar (right) healthBar2.x = 2048 - 120; healthBar2.y = 100; LK.gui.top.addChild(healthBar1); LK.gui.top.addChild(healthBar2); // Update functions for global bars function updateHealthBar1() { if (typeof fighter1 !== "undefined" && fighter1 && typeof fighter1.health !== "undefined" && typeof fighter1.maxHealth !== "undefined") { var ratio = Math.max(0, fighter1.health / fighter1.maxHealth); healthBar1Fg.width = 300 * ratio; } } function updateHealthBar2() { if (typeof fighter2 !== "undefined" && fighter2 && typeof fighter2.health !== "undefined" && typeof fighter2.maxHealth !== "undefined") { var ratio = Math.max(0, fighter2.health / fighter2.maxHealth); healthBar2Fg.width = 300 * ratio; } } // Initial update // Only call after fighters are defined // --- Arena setup --- var arena = new Arena(); arena.x = 0; arena.y = 0; game.addChild(arena); // --- Fixed ground platform (visual) --- var groundHeight = 60; var groundTileWidth = LK.getAsset('ground', { anchorX: 0, anchorY: 0 }).width; var groundY = arena.groundY - 900; // Move ground up by 900px (move it up a bit) var groundTiles = []; var numGroundTiles = Math.ceil(2048 / groundTileWidth); // Only enough to fill the screen for (var i = 0; i < numGroundTiles; i++) { var groundTile = LK.getAsset('ground', { anchorX: 0, anchorY: 0, x: i * groundTileWidth, y: groundY }); game.addChild(groundTile); groundTiles.push(groundTile); } // No infinite scrolling, ground is fixed and does not move // --- Fighters --- var fighter1 = new Fighter(); var 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 bars are now attached above each fighter (see Fighter class for visuals) --- // --- Round and timer --- var round = 1; var maxRounds = 3; var wins1 = 0; var wins2 = 0; var roundTime = 60 * 30; // 30 seconds at 60fps var roundTimer = roundTime; var timerText = new Text2('30', { size: 80, fill: "#fff" }); timerText.anchor.set(0.5, 0); LK.gui.top.addChild(timerText); // --- Touch controls (mobile-friendly) --- var leftPressed = false, rightPressed = false, atkPressed = false, jumpPressed = false, spcPressed = false; // Control buttons (simple rectangles for now) var btnLeft = LK.getAsset('btn_left', { anchorX: 0.5, anchorY: 0.5, x: 200, y: 2600 }); var btnRight = LK.getAsset('btn_right', { anchorX: 0.5, anchorY: 0.5, x: 500, y: 2600 }); var btnAtk = LK.getAsset('btn_atk', { anchorX: 0.5, anchorY: 0.5, x: 2048 - 500, y: 2600 }); var btnJump = LK.getAsset('btn_jump', { anchorX: 0.5, anchorY: 0.5, x: 2048 - 200, y: 2600 }); var btnSpc = LK.getAsset('btn_spc', { anchorX: 0.5, anchorY: 0.5, x: 2048 - 350, y: 2450 }); 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 --- var attacks = []; // --- Game update loop --- game.update = function () { // --- Timer --- if (roundTimer > 0) { roundTimer--; timerText.setText(Math.ceil(roundTimer / 60)); } // --- Ground is fixed, no update needed --- // --- Player 1 controls (left side) --- 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); } if (jumpPressed) { fighter1.jump(); } if (atkPressed) { fighter1.attack(); } if (spcPressed) { fighter1.special(); } // --- AI for fighter2 (simple: move toward player, attack if close) --- 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) { target.takeDamage(atk.damage); atk.hit = true; atk.destroy(); // Flash on hit LK.effects.flashObject(target, 0xff0000, 200); } } // --- Health bar updates --- // (No need to update healthBar1/healthBar2 text, health bars are attached to fighters and updated via updateHealthBar) // --- 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 = []; } };
/****
* Classes
****/
// Arena class: handles the ground and background
var Arena = Container.expand(function () {
var self = Container.call(this);
// Attach background asset
self.bg = self.attachAsset('arena_bg', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
// Ground Y for fighters
self.groundY = 2100;
return self;
});
// Attack class: represents a punch/kick or special move
var Attack = Container.expand(function (isSpecial) {
var self = Container.call(this);
self.isSpecial = isSpecial === true;
self.owner = null;
self.damage = self.isSpecial ? 35 : 15;
self.lifetime = self.isSpecial ? 30 : 12;
self.frame = 0;
// Attach asset
self.sprite = self.attachAsset(self.isSpecial ? 'special_attack' : 'attack', {
anchorX: 0.5,
anchorY: 0.5
});
// Set color for visual feedback
self.sprite.tint = self.isSpecial ? 0x00ffff : 0xffcc00;
// Set owner after creation
self.setOwner = function (owner) {
self.owner = owner;
};
// Update per frame
self.update = function () {
self.frame++;
if (self.frame > self.lifetime) {
self.destroy();
}
};
return self;
});
var Fighter = Container.expand(function () {
var self = Container.call(this);
// Attach fighter asset (placeholder box, can be replaced with unique fighter art)
self.sprite = self.attachAsset('fighter', {
anchorX: 0.5,
anchorY: 1.0
});
// Fighter properties
self.maxHealth = 100;
self.health = 100;
self.isFacingRight = true;
self.isJumping = false;
self.isAttacking = false;
self.isSpecialReady = true;
self.specialCooldown = 180; // 3 seconds at 60fps
self.specialTimer = 0;
self.moveSpeed = 18;
self.jumpPower = -60;
self.gravity = 6;
self.velY = 0;
self.groundY = 2100; // Default ground Y, will be set by Arena
// Health bar
self.healthBar = new Container();
self.healthBarBg = self.healthBar.addChild(LK.getAsset('healthbar_bg', {
anchorX: 0,
anchorY: 0.5
}));
self.healthBarFg = self.healthBar.addChild(LK.getAsset('healthbar_fg', {
anchorX: 0,
anchorY: 0.5
}));
self.healthBar.y = -220;
self.addChild(self.healthBar);
// Update health bar
self.updateHealthBar = function () {
// No longer update fighter-attached health bars, update global bars instead
if (typeof updateHealthBar1 === "function" && self === fighter1) {
updateHealthBar1();
}
if (typeof updateHealthBar2 === "function" && self === fighter2) {
updateHealthBar2();
}
};
// Take damage
self.takeDamage = function (amount) {
self.health = Math.max(0, self.health - amount);
self.updateHealthBar();
};
// Attack
self.attack = function () {
if (self.isAttacking) return;
self.isAttacking = true;
var atk = new Attack(self, false);
atk.x = self.x + (self.isFacingRight ? 120 : -120);
atk.y = self.y - 180;
self.parent.addChild(atk);
LK.setTimeout(function () {
self.isAttacking = false;
}, 300);
};
// Special move
self.special = function () {
if (!self.isSpecialReady) return;
self.isSpecialReady = false;
self.specialTimer = self.specialCooldown;
var atk = new Attack(self, true);
atk.x = self.x + (self.isFacingRight ? 180 : -180);
atk.y = self.y - 180;
self.parent.addChild(atk);
};
// Jump
self.jump = function () {
if (self.isJumping) return;
self.isJumping = true;
self.velY = self.jumpPower;
};
// Update per frame
self.update = function () {
// Special cooldown
if (!self.isSpecialReady) {
self.specialTimer--;
if (self.specialTimer <= 0) {
self.isSpecialReady = true;
}
}
// Jump physics
if (self.isJumping) {
self.y += self.velY;
self.velY += self.gravity;
if (self.y >= self.groundY) {
self.y = self.groundY;
self.isJumping = false;
self.velY = 0;
}
}
};
// Flip sprite
self.setFacing = function (right) {
self.isFacingRight = right;
self.sprite.scaleX = right ? 1 : -1;
};
// Initialize health bar
self.updateHealthBar();
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// --- Health bars are now shown at the top of the screen ---
// (No need to remove fighter-attached health bars, as global bars are used)
// Create global health bar containers
var healthBar1 = new Container();
var healthBar2 = new Container();
var healthBar1Bg = healthBar1.addChild(LK.getAsset('healthbar_bg', {
anchorX: 0,
anchorY: 0.5
}));
var healthBar1Fg = healthBar1.addChild(LK.getAsset('healthbar_fg', {
anchorX: 0,
anchorY: 0.5
}));
var healthBar2Bg = healthBar2.addChild(LK.getAsset('healthbar_bg', {
anchorX: 1,
anchorY: 0.5
}));
var healthBar2Fg = healthBar2.addChild(LK.getAsset('healthbar_fg', {
anchorX: 1,
anchorY: 0.5
}));
// Set bar sizes and positions
healthBar1Bg.width = 300;
healthBar1Fg.width = 300;
healthBar2Bg.width = 300;
healthBar2Fg.width = 300;
// Player health bar (left)
healthBar1.x = 120;
healthBar1.y = 100;
// AI enemy health bar (right)
healthBar2.x = 2048 - 120;
healthBar2.y = 100;
LK.gui.top.addChild(healthBar1);
LK.gui.top.addChild(healthBar2);
// Update functions for global bars
function updateHealthBar1() {
if (typeof fighter1 !== "undefined" && fighter1 && typeof fighter1.health !== "undefined" && typeof fighter1.maxHealth !== "undefined") {
var ratio = Math.max(0, fighter1.health / fighter1.maxHealth);
healthBar1Fg.width = 300 * ratio;
}
}
function updateHealthBar2() {
if (typeof fighter2 !== "undefined" && fighter2 && typeof fighter2.health !== "undefined" && typeof fighter2.maxHealth !== "undefined") {
var ratio = Math.max(0, fighter2.health / fighter2.maxHealth);
healthBar2Fg.width = 300 * ratio;
}
}
// Initial update
// Only call after fighters are defined
// --- Arena setup ---
var arena = new Arena();
arena.x = 0;
arena.y = 0;
game.addChild(arena);
// --- Fixed ground platform (visual) ---
var groundHeight = 60;
var groundTileWidth = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
}).width;
var groundY = arena.groundY - 900; // Move ground up by 900px (move it up a bit)
var groundTiles = [];
var numGroundTiles = Math.ceil(2048 / groundTileWidth); // Only enough to fill the screen
for (var i = 0; i < numGroundTiles; i++) {
var groundTile = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: i * groundTileWidth,
y: groundY
});
game.addChild(groundTile);
groundTiles.push(groundTile);
}
// No infinite scrolling, ground is fixed and does not move
// --- Fighters ---
var fighter1 = new Fighter();
var 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 bars are now attached above each fighter (see Fighter class for visuals) ---
// --- Round and timer ---
var round = 1;
var maxRounds = 3;
var wins1 = 0;
var wins2 = 0;
var roundTime = 60 * 30; // 30 seconds at 60fps
var roundTimer = roundTime;
var timerText = new Text2('30', {
size: 80,
fill: "#fff"
});
timerText.anchor.set(0.5, 0);
LK.gui.top.addChild(timerText);
// --- Touch controls (mobile-friendly) ---
var leftPressed = false,
rightPressed = false,
atkPressed = false,
jumpPressed = false,
spcPressed = false;
// Control buttons (simple rectangles for now)
var btnLeft = LK.getAsset('btn_left', {
anchorX: 0.5,
anchorY: 0.5,
x: 200,
y: 2600
});
var btnRight = LK.getAsset('btn_right', {
anchorX: 0.5,
anchorY: 0.5,
x: 500,
y: 2600
});
var btnAtk = LK.getAsset('btn_atk', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 - 500,
y: 2600
});
var btnJump = LK.getAsset('btn_jump', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 - 200,
y: 2600
});
var btnSpc = LK.getAsset('btn_spc', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 - 350,
y: 2450
});
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 ---
var attacks = [];
// --- Game update loop ---
game.update = function () {
// --- Timer ---
if (roundTimer > 0) {
roundTimer--;
timerText.setText(Math.ceil(roundTimer / 60));
}
// --- Ground is fixed, no update needed ---
// --- Player 1 controls (left side) ---
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);
}
if (jumpPressed) {
fighter1.jump();
}
if (atkPressed) {
fighter1.attack();
}
if (spcPressed) {
fighter1.special();
}
// --- AI for fighter2 (simple: move toward player, attack if close) ---
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) {
target.takeDamage(atk.damage);
atk.hit = true;
atk.destroy();
// Flash on hit
LK.effects.flashObject(target, 0xff0000, 200);
}
}
// --- Health bar updates ---
// (No need to update healthBar1/healthBar2 text, health bars are attached to fighters and updated via updateHealthBar)
// --- 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 = [];
}
};