Code edit (12 edits merged)
Please save this source code
User prompt
in handleHitImpact when KO call game over
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
add a new class HealthBar
Code edit (1 edits merged)
Please save this source code
User prompt
in punch function, increase self.currentPunchEnergy when punchCount is high, restore it to self.basePunchEnergy when its low
Code edit (2 edits merged)
Please save this source code
User prompt
in punch, count the number of punches per second
Code edit (18 edits merged)
Please save this source code
User prompt
when Athlete punched, reduce his energy by 2
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self.bg is undefined' in or related to this line: 'self.fill = self.attachAsset('energyBarFill', {' Line Number: 355
Code edit (3 edits merged)
Please save this source code
User prompt
in EnergyBar class, add a energyBarBackground asset
Code edit (7 edits merged)
Please save this source code
User prompt
in EnergyBar class, add a lightning icon above
Code edit (1 edits merged)
Please save this source code
User prompt
in gameInitialize, Add the energy bar on the left
Code edit (1 edits merged)
Please save this source code
User prompt
add a class energyBar to handle energy level. use the asset energyBar and another asset energyBarFill
User prompt
add a vertical energyBAr on the right
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -104,18 +104,15 @@
if (timeDiff <= 1000) {
self.punchCount++;
} else {
self.punchCount = 1;
+ self.currentPunchEnergy = self.basePunchEnergy;
}
// Update last punch time
self.lastPunchTime = currentTime;
// Adjust currentPunchEnergy based on punchCount
- if (self.punchCount > 5) {
- self.currentPunchEnergy = self.basePunchEnergy * 2; // Increase energy cost when punch count is high
- } else {
- self.currentPunchEnergy = self.basePunchEnergy; // Restore to base energy cost when punch count is low
- }
- self.energy -= self.currentPunchEnergy;
+ self.currentPunchEnergy = self.basePunchEnergy * self.punchCount;
+ self.energy = Math.max(0, self.energy - self.currentPunchEnergy);
log("self.punchCount => " + self.punchCount, "self.currentPunchEnergy => " + self.currentPunchEnergy);
if (self.isPlayer) {
playerEnergyBar.updateEnergy(self.energy);
}
@@ -185,8 +182,12 @@
log("self.guard: " + setGuard);
if (self.isGuarding === setGuard) {
return;
}
+ self.energy = 100;
+ if (self.isPlayer) {
+ playerEnergyBar.updateEnergy(self.energy);
+ }
self.isGuarding = setGuard;
if (setGuard) {
self.setPosture(idlePosture);
self.head.height *= 0.95;
@@ -389,9 +390,9 @@
});
// Update the energy bar display
self.updateEnergy = function (energy) {
self.currentEnergy = energy;
- var fillSize = (self.maxEnergy - self.currentEnergy) / self.maxEnergy * (self.energyGradiant.height + 6);
+ var fillSize = Math.max(0, self.maxEnergy - self.currentEnergy) / self.maxEnergy * (self.energyGradiant.height + 6);
self.fill.height = fillSize;
};
});
/****************************************************************************************** */
@@ -417,8 +418,35 @@
self.height = 600;
};
});
/****************************************************************************************** */
+/************************************* HEALTH BAR CLASS *********************************** */
+/****************************************************************************************** */
+var HealthBar = Container.expand(function (maxHealth) {
+ var self = Container.call(this);
+ self.maxHealth = maxHealth;
+ self.currentHealth = maxHealth;
+ // Frame of the health bar
+ self.frame = self.attachAsset('healthBarFrame', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Fill of the health bar
+ self.fill = self.attachAsset('healthBar', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: 0,
+ width: self.frame.width - 64 // Padding for the health bar fill
+ });
+ // Update the health bar display
+ self.updateHealth = function (health) {
+ self.currentHealth = health;
+ var fillWidth = Math.max(0, self.currentHealth) / self.maxHealth * (self.frame.width - 64);
+ self.fill.width = fillWidth;
+ };
+});
+/****************************************************************************************** */
/************************************* PUNCH BUTTON CLASS ********************************** */
/****************************************************************************************** */
var PunchButton = Container.expand(function () {
var self = Container.call(this);
@@ -586,9 +614,9 @@
opponent.rotation = Math.PI * 0.5;
// Add the energy bar on the left
// Initialize Energy Bar for Player
playerEnergyBar = game.addChild(new EnergyBar(100));
- playerEnergyBar.x = game.width - 50; // Position energy bar on the left side
+ playerEnergyBar.x = game.width - 75; // Position energy bar on the left side
playerEnergyBar.y = game.height * 0.4; // Position towards the top
if (isDebug) {
// Debug Marker
debugMarker = LK.getAsset('debugMarker', {
clear
basic light gray convex round button with a red boxing glove icon. UI
Un gant de boxe bleu vu de dessus. video game
basic light round convex gray button with a raised blue shield icon.. UI
un éclair. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
remove
a basic white heart.. game icon
A boxer has lost the match..
man boxer with red gloves is KO on the ring..