Code edit (14 edits merged)
Please save this source code
User prompt
in thinkAboutTarget, when going to the other take into account attackDistance self.targetX = other.x; self.targetY = other.y;
User prompt
in mainAIMove, Implement acceleration and deceleration in the AI's movement. The AI could start moving slowly, gradually increase its speed as it moves away from its starting point, and then slow down as it approaches the target. This would add a more natural feel to the movement. Don't alter the other logic, only the movement
User prompt
Please fix the bug: 'TypeError: Math.rancomd is not a function' in or related to this line: 'if (Math.rancomd() < 0.5) {' Line Number: 367
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -97,9 +97,9 @@
self.punch = function (isLeft) {
if (!self.isPlayer) {
log("AI PUNCH : isLeft=" + isLeft);
}
- if (self.isPunching) {
+ if (self.isPunching || self.isGuarding || !self.isPlayer && self.retreat) {
return;
}
if (self.energy <= 0) {
return;
@@ -118,8 +118,11 @@
self.lastPunchTime = currentTime;
// Adjust currentPunchEnergy based on punchCount
self.currentPunchEnergy = self.basePunchEnergy * self.punchCount;
self.energy = Math.max(0, self.energy - self.currentPunchEnergy);
+ if (!self.isPlayer && self.energy <= 0) {
+ log("AI NO MORE ENERGY !!!");
+ }
//log("self.punchCount => " + self.punchCount, "self.currentPunchEnergy => " + self.currentPunchEnergy);
if (self.isPlayer) {
playerEnergyBar.updateEnergy(self.energy);
}
@@ -194,9 +197,9 @@
self.guard = function (setGuard) {
if (!self.isPlayer) {
log("AI GUARD : setGuard=" + setGuard);
}
- if (!self.isGuarding && !setGuard) {
+ if (!self.isGuarding && !setGuard || self.isGuarding && setGuard) {
return;
}
if (setGuard && self.guardLevel <= 0) {
self.setPosture(idlePosture);
@@ -275,8 +278,11 @@
if (self.isGuarding) {
//log("self.isGuarding : self.guardLevel=" + self.guardLevel);
self.guardLevel = Math.max(0, self.guardLevel - 4);
if (self.guardLevel <= 0) {
+ if (!self.isPlayer) {
+ log("AI NO MORE GUARD !!!");
+ }
self.guard(false);
}
self.energy = Math.min(100, self.energy + 2);
} else {
@@ -303,10 +309,13 @@
self.mainAiMove();
};
self.thinkAboutTarget = function () {
// If Guard level < 25% or Energy < 25% retreat to closest ring corner
- if (self.guardLevel < 25 || self.energy < 25) {
+ if (self.energy < 15) {
self.retreat = true;
+ if (!self.isPlayer) {
+ log("AI RETREAT !!!");
+ }
if (self.x < 1024) {
self.targetX = ring.leftCorner;
} else {
self.targetX = ring.rightCorner;
@@ -326,26 +335,27 @@
self.mainAiMove = function () {
var target = self.thinkAboutTarget();
// Check if athlete has reached the target
var distanceToTarget = Math.sqrt(Math.pow(self.targetX - self.x, 2) + Math.pow(self.targetY - self.y, 2));
- if (distanceToTarget < attackDistance) {
+ if (!self.retreat && distanceToTarget < attackDistance) {
self.isInAttackRange = true;
//self.guard(false);
if (!self.isPlayer) {
self.aiFight();
}
} else {
- // Progressively move to the target
- var moveX = (self.targetX - self.x) / distanceToTarget * self.speed;
- var moveY = (self.targetY - self.y) / distanceToTarget * self.speed;
- self.x += moveX;
- self.y += moveY;
- //self.guard(true);
+ if (distanceToTarget > 10) {
+ // Progressively move to the target
+ var moveX = (self.targetX - self.x) / distanceToTarget * self.speed;
+ var moveY = (self.targetY - self.y) / distanceToTarget * self.speed;
+ self.x += moveX;
+ self.y += moveY;
+ }
}
};
self.aiFight = function () {
if (self.retreat) {
- if (self.guardLevel > 25) {
+ if (!self.isGuarding && self.guardLevel > 0) {
self.guard(true);
}
} else {
if (LK.ticks % 33 == 0 && !self.isPunching && !self.isFighting) {
@@ -748,9 +758,9 @@
var newX = defender.x + Math.cos(defenderDirection) * backDelta;
var newY = defender.y + Math.sin(defenderDirection) * backDelta;
// Check if newX and newY are within ring's borders
var withinLimits = newX >= ring.leftBorder && newX <= ring.rightBorder && newY >= ring.topBorder && newY <= ring.bottomBorder;
- log("Is in ring ?", withinLimits);
+ //log("Is in ring ?", withinLimits);
if (withinLimits) {
defender.x = newX; // Move defender back in the x direction of current movement
defender.y = newY; // Move defender back in the y direction of current movement
} else {
@@ -784,17 +794,17 @@
members = [defender.head, defender.torso];
}
// Apply movement to all members in the array
members.forEach(function (member) {
- member.x += Math.cos(defenderDirection) * backDelta;
- member.y += Math.sin(defenderDirection) * backDelta;
+ member.x += Math.cos(defenderDirection) * backHeadDelta;
+ member.y += Math.sin(defenderDirection) * backHeadDelta;
});
- (function (defender, defenderDirection, backDelta, members) {
+ (function (defender, defenderDirection, backHeadDelta, members) {
LK.setTimeout(function () {
// Head returns to normal position
members.forEach(function (member) {
- member.x -= Math.cos(defenderDirection) * backDelta;
- member.y -= Math.sin(defenderDirection) * backDelta;
+ member.x -= Math.cos(defenderDirection) * backHeadDelta;
+ member.y -= Math.sin(defenderDirection) * backHeadDelta;
});
/*
defender.head.x -= 2.5 * Math.cos(defenderDirection) * backHeadDelta;
defender.head.y -= 2.5 * Math.sin(defenderDirection) * backHeadDelta;
@@ -805,33 +815,24 @@
if (!defender.isGuarding && !defender.isPunching) {
defender.setPosture(idlePosture);
}
}, 500);
- })(defender, defenderDirection, backDelta, members);
+ })(defender, defenderDirection, backHeadDelta, members);
}
/****************************************************************************************** */
/************************************** MAIN GAME LOOP ************************************ */
/****************************************************************************************** */
// Game update function
game.update = function () {
// This section has been removed to prevent redundant player movement handling.
// Check for collision between player's hand and opponent's head
+ if (Date.now() - opponent.lastHitTime < opponent.immunityDelayMs || Date.now() - player.lastHitTime < player.immunityDelayMs) {
+ return;
+ }
if (player.isPunching && (player.leftHand.intersects(opponent.torso) || player.rightHand.intersects(opponent.torso))) {
handleHit(player, opponent);
- /*
- // Player hit reaction: head goes back, flash screen red
- // Calculate opponent's current direction and move back accordingly
- var opponentDirection = Math.atan2(opponent.y - player.y, opponent.x - player.x);
- opponent.x += Math.cos(opponentDirection) * 50; // Move opponent back in the x direction of current movement
- opponent.y += Math.sin(opponentDirection) * 50; // Move opponent back in the y direction of current movement
- opponent.head.y -= 20; // Head returns to normal position
- LK.effects.flashScreen(0xFFFFFF, 100); // Flash the whole screen red for 0.5 seconds
- LK.setTimeout(function () {
- opponent.head.y += 20; // Head returns to normal position
- }, 500);
- */
}
- if (opponent.isPunching && (opponent.leftHand.intersects(player.torso) || opponent.rightHand.intersects(player.torso))) {
+ if (opponent.isPunching(opponent.leftHand.intersects(player.torso) || opponent.rightHand.intersects(player.torso))) {
handleHit(opponent, player);
}
};
gameInitialize();
\ No newline at end of file
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..