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
@@ -14,12 +14,15 @@
self.isTouched = false;
self.energy = 100;
self.guardLevel = 100;
self.health = 100;
+ self.retreat = false;
self.basePunchEnergy = 2; // Punch cost in energy
self.currentPunchEnergy = 2; // Punch cost in energy
self.punchCount = 0; // Initialize punch count
self.lastPunchTime = 0; // Timestamp of the last punch
+ self.lastHitTime = 0; // Timestamp of the last hit
+ self.immunityDelayMs = 0; // Timestamp of the last hit
self.body = new Container();
game.addChild(self.body);
var punchDistance = 60; // Define punch distance for punching animation
var attackDistance = 500;
@@ -236,25 +239,27 @@
self.setPosture(idlePosture);
}
};
self.handleHitImpact = function (attacker) {
- self.health = Math.max(0, self.health - attacker.punchCount * (self.isGuarding ? 0.01 : 0.5));
- if (self.isPlayer) {
- //playerHealthBar.updateHealth(self.health);
+ if (Date.now() - self.lastHitTime < self.immunityDelayMs) {
+ return false;
}
+ self.lastHitTime = Date.now();
+ self.health = Math.max(0, self.health - attacker.punchCount * (self.isGuarding ? 0.01 : 0.5));
(self.isPlayer ? playerHealthBar : opponentHealthBar).updateHealth(self.health);
if (self.health <= 0) {
// KO, call game over
LK.showGameOver();
}
+ return true;
};
// Update player position based on input
self.update = function () {
if (isPlaying) {
self[self.isPlayer ? 'mainPlayerMove' : 'mainAiMove']();
}
if (LK.ticks % 60 == 0) {
- log("TICK !!!!!!!!!!!!!!!!!!!!!");
+ log("===================== TICK =====================");
if (self.isGuarding) {
log("self.isGuarding : self.guardLevel=" + self.guardLevel);
self.guardLevel = Math.max(0, self.guardLevel - 4);
if (self.guardLevel <= 0) {
@@ -280,21 +285,42 @@
var angleToOpponent = Math.atan2(target.y - self.y, target.x - self.x) + Math.PI * 0.5;
self.body.rotation = angleToOpponent;
};
self.mainPlayerMove = function () {
- var target = opponent;
+ //var target = self.thinkAboutTarget();
+ self.mainAiMove();
};
+ self.thinkAboutTarget = function () {
+ // If Guard level < 25% or Energy < 25% retreat to closest ring corner
+ if (self.guardLevel < 25 || self.energy < 25) {
+ self.retreat = true;
+ if (self.x < 1024) {
+ self.targetX = ring.leftCorner;
+ } else {
+ self.targetX = ring.rightCorner;
+ }
+ if (self.y < 1024) {
+ self.targetY = ring.topCorner;
+ } else {
+ self.targetY = ring.bottomCorner;
+ }
+ } else {
+ self.retreat = false;
+ var target = self.isPlayer ? opponent : player;
+ self.targetX = target.x;
+ self.targetY = target.y;
+ }
+ };
self.mainAiMove = function () {
- // AI Move
- var target = player;
- self.targetX = target.x;
- self.targetY = target.y;
+ 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) {
self.isInAttackRange = true;
//self.guard(false);
- self.aiFight();
+ 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;
@@ -303,18 +329,24 @@
//self.guard(true);
}
};
self.aiFight = function () {
- if (LK.ticks % 33 == 0 && !self.isPunching && !self.isFighting) {
- self.punch(Math.random() < 0.5);
- // Punch during 2sec
- LK.setTimeout(function () {
- self.isFighting = true;
- // Stop durring 2 sec
+ if (self.retreat) {
+ if (self.guardLevel > 25) {
+ self.guard(true);
+ }
+ } else {
+ if (LK.ticks % 33 == 0 && !self.isPunching && !self.isFighting) {
+ self.punch(Math.random() < 0.5);
+ // Punch during 2sec
LK.setTimeout(function () {
- self.isFighting = false;
+ self.isFighting = true;
+ // Stop durring 2 sec
+ LK.setTimeout(function () {
+ self.isFighting = false;
+ }, 4000 - 2000 * Math.random());
}, 4000 - 2000 * Math.random());
- }, 4000 - 2000 * Math.random());
+ }
}
};
self.miniMove = function () {
if (self.isPunching || self.isGuarding || self.isHit) {
@@ -517,8 +549,12 @@
self.leftBorder = 300;
self.rightBorder = 1800;
self.topBorder = 200;
self.bottomBorder = 1750;
+ self.leftCorner = 600;
+ self.rightCorner = 1500;
+ self.topCorner = 500;
+ self.bottomCorner = 1500;
self.ringAsset = self.attachAsset('ring', {
anchorX: 0.5,
anchorY: 0.5
});
@@ -677,10 +713,10 @@
anchorX: 0.5,
anchorY: 0.5
});
game.addChild(debugMarker);
- debugMarker.x = 1550;
- debugMarker.y = 1550;
+ debugMarker.x = 1800;
+ debugMarker.y = 1750;
}
}
/****************************************************************************************** */
/************************************* GAME FUNCTIONS ************************************* */
@@ -709,10 +745,10 @@
attacker.x += Math.cos(attackerDirection) * backDelta;
attacker.y += Math.sin(attackerDirection) * backDelta;
*/
}
- defender.handleHitImpact(attacker);
- var flashColor = defender.isGuarding ? 0xcccccc : 0xFF0000;
+ var impacted = defender.handleHitImpact(attacker);
+ var flashColor = defender.isGuarding || !impacted ? 0xcccccc : 0xFF0000;
if (defender.isGuarding) {
LK.effects.flashObject(defender.leftHand, flashColor, 100); // Flash the defender
LK.effects.flashObject(defender.rightHand, flashColor, 100); // Flash the defender
} else {
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..