Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self.gard is not a function' in or related to this line: 'self.gard(true);' Line Number: 360
Code edit (9 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self.gard is not a function' in or related to this line: 'self.gard(true);' Line Number: 352
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: target is undefined' in or related to this line: 'self.targetX = target.x;' Line Number: 370
User prompt
in thinkAboutTarget, when self.energy < 15, select a corner far from the other player
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: opponent.isPunching is not a function' in or related to this line: 'if (opponent.isPunching(opponent.leftHand.intersects(player.torso) || opponent.rightHand.intersects(player.torso))) {' Line Number: 860
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
in handleHit, fix the scope problem for members in the settimeout
Code edit (1 edits merged)
Please save this source code
User prompt
in handleHit, also use members array for the restoration of the positions
User prompt
in handleHit, move the members back in the setTimout function
User prompt
in handleHit, use members array to determine which members to move back and forth
Code edit (9 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: guardLevel is not defined' in or related to this line: 'if (guardLevel > 25) {' Line Number: 360
Code edit (1 edits merged)
Please save this source code
Code edit (14 edits merged)
Please save this source code
User prompt
add the opponent health bar at the top of the screen
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -11,8 +11,9 @@
self.isFighting = false;
self.isHit = false;
self.isTouched = false;
self.energy = 100;
+ self.guardLevel = 100;
self.health = 100;
self.basePunchEnergy = 2; // Punch cost in energy
self.currentPunchEnergy = 2; // Punch cost in energy
self.punchCount = 0; // Initialize punch count
@@ -179,20 +180,25 @@
};
// Guard function to handle guarding action
self.guard = function (setGuard) {
log("self.guard: " + setGuard);
- if (self.isGuarding === setGuard) {
+ if (!self.isGuarding && !setGuard) {
return;
}
- self.energy = 100;
+ self.energy = 100; // TEMP DEBUG
if (self.isPlayer) {
playerEnergyBar.updateEnergy(self.energy);
}
- self.isGuarding = setGuard;
- if (setGuard) {
+ if (setGuard && self.guardLevel <= 0) {
self.setPosture(idlePosture);
+ self.isGuarding = false;
+ return;
+ }
+ if (setGuard && !self.isGuarding) {
+ self.setPosture(idlePosture);
self.head.height *= 0.95;
}
+ self.isGuarding = setGuard;
// Simplified adjustments for guarding using symmetrical elements
var adjustPosition = function adjustPosition(elementPair, deltaX, deltaY, deltaW, deltaH, deltaR, setGuard) {
elementPair.forEach(function (element, index) {
var directionH = (index === 0 ? 1 : -1) * (setGuard ? 1 : -1);
@@ -233,9 +239,9 @@
self.setPosture(idlePosture);
}
};
self.handleHitImpact = function (attacker) {
- self.health = Math.max(0, self.health - attacker.punchCount * (self.isGuarding ? 0.125 : 0.5));
+ self.health = Math.max(0, self.health - attacker.punchCount * (self.isGuarding ? 0.01 : 0.5));
if (self.isPlayer) {
playerHealthBar.updateHealth(self.health);
}
if (self.health <= 0) {
@@ -247,8 +253,21 @@
self.update = function () {
if (isPlaying) {
self[self.isPlayer ? 'mainPlayerMove' : 'mainAiMove']();
}
+ if (LK.ticks % 60 == 0) {
+ if (self.isGuarding) {
+ self.guardLevel = Math.max(0, self.guardLevel - 4);
+ if (self.guardLevel <= 0) {
+ self.guard(false);
+ }
+ } else {
+ self.guardLevel = Math.min(100, self.guardLevel + 2);
+ }
+ if (self.isPlayer) {
+ playerGuardBar.updateEnergy(self.guardLevel);
+ }
+ }
// Player is idle
self.miniMove();
// Update body position and rotation
self.body.x = self.x;
@@ -367,9 +386,9 @@
});
/****************************************************************************************** */
/************************************* ENERGY BAR CLASS ********************************** */
/****************************************************************************************** */
-var EnergyBar = Container.expand(function (maxEnergy) {
+var EnergyBar = Container.expand(function (maxEnergy, isGard) {
var self = Container.call(this);
self.maxEnergy = maxEnergy;
self.currentEnergy = maxEnergy;
// Background of the energy bar
@@ -386,14 +405,14 @@
self.fill = self.attachAsset('energyBarFill', {
anchorX: 0.50,
anchorY: 0,
x: 0,
- y: -self.frame.height / 2 + 25,
+ y: -self.frame.height / 2 + 20,
height: 0,
visible: true
});
// Lightning icon above the energy bar
- self.lightningIcon = self.attachAsset('lightning', {
+ self.lightningIcon = self.attachAsset(isGard ? 'shieldIcon' : 'lightning', {
anchorX: 0.5,
anchorY: 1,
x: 0,
y: -self.energyGradiant.height / 2 - 50 // Position above the energy bar
@@ -524,8 +543,9 @@
var touchPosition = null;
var swipeStart = null;
var swipeEnd = null;
var playerEnergyBar = null;
+var playerGuardBar = null;
var playerHealthBar = null;
var isDebug = true;
var debugMarker;
/****************************************************************************************** */
@@ -628,13 +648,17 @@
opponent = game.addChild(new Athlete());
opponent.x = 1024; // Center horizontally
opponent.y = game.height * 0.2; // Center vertically in the middle of the ring
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 - 75; // Position energy bar on the left side
playerEnergyBar.y = game.height * 0.4; // Position towards the top
+ // Initialize Guard Bar for Player
+ playerGuardBar = game.addChild(new EnergyBar(100, true));
+ playerGuardBar.x = 75; // Position energy bar on the left side
+ playerGuardBar.y = game.height * 0.4; // Position towards the top
+ // Initialize Player Health bar
playerHealthBar = game.addChild(new HealthBar(100));
playerHealthBar.x = 1024;
playerHealthBar.y = 1960;
if (isDebug) {
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..