Code edit (21 edits merged)
Please save this source code
User prompt
now, in handleHit(), check if newX and newY are out of ring's limits
User prompt
store the following coordinates as ring limits properties in ring class : [300,200], [1800,200], [300,1750], [1800,1750]
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: target is not defined' in or related to this line: 'self.targetX = target.x;' Line Number: 223
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
factorize punch() function by using the deltas method
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
in guard() adjustments, handle also width and height (deltaW and deltaH)
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
in guard(), also add a deltaY to adjustments array
User prompt
add deltaY to the adjustments
User prompt
in guard(), also add a deltaY
Code edit (1 edits merged)
Please save this source code
User prompt
in adjustPosition(), simplify by making direction depend on setGuard also
User prompt
in adjustPosition(), simplify by defining a direction variable that depends on index and setGuard
User prompt
in guard, also Invert deltaR for the second element
User prompt
in gard(), simplify the adjustments as they are symetrical. use an array for elements
User prompt
now in guard(), add adjustments for arms too
User prompt
now refactor the gard() function
/**** 
* Classes
****/ 
/****************************************************************************************** */ 
/************************************* ATHLETE CLASS ************************************** */
/****************************************************************************************** */ 
var Athlete = Container.expand(function (isPlayer) {
	var self = Container.call(this);
	self.isPunching = false; // Indicates if the athlete is currently punching
	self.isPlayer = isPlayer;
	self.body = new Container();
	game.addChild(self.body);
	var punchDistance = 60; // Define punch distance for punching animation
	var attackDistance = 500;
	self.targetX = self.targetX || 1024; // Default target X
	self.targetY = self.targetY || 1366; // Default target Y
	// Left Arm
	self.leftForearm = self.body.attachAsset('forearm', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: -110,
		y: -125,
		width: 80,
		rotation: -Math.PI * 0.2
	});
	self.leftHand = self.body.attachAsset(isPlayer ? 'hand' : 'hand2', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: isPlayer ? -100 : -115,
		y: isPlayer ? -250 : -245,
		width: 90,
		height: 180,
		rotation: isPlayer ? -Math.PI * 0.05 : -Math.PI * 0.17
	});
	self.leftArm = self.body.attachAsset('arm', {
		anchorX: 0.5,
		anchorY: 0,
		x: -120,
		y: -120
	});
	// Right Arm
	self.rightForearm = self.body.attachAsset('forearm', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: 110,
		y: -125,
		scaleX: -1,
		width: 80,
		rotation: Math.PI * 0.2
	});
	self.rightHand = self.body.attachAsset(isPlayer ? 'hand' : 'hand2', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: isPlayer ? 100 : 110,
		y: isPlayer ? -250 : -245,
		scaleX: -1,
		width: 90,
		height: 180,
		rotation: isPlayer ? Math.PI * 0.05 : Math.PI * 0.17
	});
	self.rightArm = self.body.attachAsset('arm', {
		anchorX: 0.5,
		anchorY: 0,
		x: 120,
		y: -120,
		scaleX: -1
	});
	self.torso = self.body.attachAsset('body', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.head = self.body.attachAsset(isPlayer ? 'head' : 'head2', {
		anchorX: 0.5,
		anchorY: 0.5,
		y: -40
	});
	// Player movement speed
	self.speed = 5;
	// Punch function to handle punching action
	self.punch = function (isLeft) {
		log("self.punch: " + isLeft);
		if (self.isPunching) {
			return;
		}
		var arm = isLeft ? self.leftArm : self.rightArm;
		var forearm = isLeft ? self.leftForearm : self.rightForearm;
		var hand = isLeft ? self.leftHand : self.rightHand;
		// Refactored punch animation logic using deltas method
		self.isPunching = true;
		//self.setPosture(idlePosture);
		var deltas = {
			arm: {
				height: punchDistance,
				y: -punchDistance
			},
			forearm: {
				height: punchDistance,
				y: -punchDistance * 1.5,
				rotation: isLeft ? 0.5 : -0.5
			},
			hand: {
				x: 30 * (isLeft ? 1 : -1),
				y: -punchDistance * 2
			},
			head: {
				x: isLeft ? 15 : -15,
				width: -0.05,
				height: 0.05,
				rotation: isLeft ? 0.1 : -0.1
			}
		};
		// Apply deltas for punch animation
		LK.setTimeout(function () {
			applyDeltas(arm, deltas.arm);
			applyDeltas(forearm, deltas.forearm);
			applyDeltas(hand, deltas.hand);
			applyDeltas(self.head, deltas.head);
		}, 100);
		// Reverse deltas to return to original position
		LK.setTimeout(function () {
			applyDeltas(arm, reverseDeltas(deltas.arm));
			applyDeltas(forearm, reverseDeltas(deltas.forearm));
			applyDeltas(hand, reverseDeltas(deltas.hand));
			applyDeltas(self.head, reverseDeltas(deltas.head));
			self.isPunching = false;
		}, 200);
		function applyDeltas(element, deltas) {
			for (var key in deltas) {
				element[key] += deltas[key];
			}
		}
		function reverseDeltas(deltas) {
			var reversed = {};
			for (var key in deltas) {
				reversed[key] = -deltas[key];
			}
			return reversed;
		}
	};
	// Guard function to handle guarding action
	self.guard = function (setGuard) {
		log("self.guard: " + setGuard);
		self.isGuarding = setGuard;
		if (setGuard) {
			self.setPosture(idlePosture);
			self.head.height *= 0.95;
		}
		// 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);
				var directionV = setGuard ? 1 : -1;
				element.x += deltaX * directionH;
				element.y += deltaY * directionV; // Add vertical adjustment
				element.rotation += deltaR * directionH;
				element.width += deltaW * directionV; // Add width adjustment
				element.height += deltaH * directionV; // Add height adjustment
			});
		};
		// Pair elements for symmetrical adjustments
		var elementPairs = [[self.leftHand, self.rightHand], [self.leftForearm, self.rightForearm], [self.leftArm, self.rightArm]];
		// Adjustments for Hands, Forearms and Arms
		var adjustments = [{
			deltaX: 65,
			deltaY: 90,
			deltaW: 15,
			deltaH: 15,
			deltaR: 0.35
		}, {
			deltaX: 30,
			deltaY: 60,
			deltaW: 0,
			deltaH: 0,
			deltaR: 0.2
		}, {
			deltaX: 50,
			deltaY: 10,
			deltaW: 0,
			deltaH: 0,
			deltaR: 0.4
		}];
		adjustments.forEach(function (adj, index) {
			return adjustPosition(elementPairs[index], adj.deltaX, adj.deltaY, adj.deltaW, adj.deltaH, adj.deltaR, setGuard);
		});
		if (!setGuard) {
			self.setPosture(idlePosture);
		}
	};
	// Update player position based on input
	self.update = function () {
		if (isPlaying) {
			// TEMP DEBUG !!
			self.mainMove();
		}
		// Player is idle
		self.miniMove();
		// Update body position and rotation
		self.body.x = self.x;
		self.body.y = self.y;
		// Calculate angle to face the opponent
		var target = self.isPlayer ? opponent : player; // Determine target based on whether self is Player or Opponent
		var angleToOpponent = Math.atan2(target.y - self.y, target.x - self.x) + Math.PI * 0.5;
		self.body.rotation = angleToOpponent;
	};
	self.mainMove = function () {
		if (self.isPlayer) {
			return;
		}
		// AI Move
		var target = player;
		self.targetX = target.x;
		self.targetY = target.y;
		// 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.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.miniMove = function () {
		if (self.isPunching || self.isGuarding) {
			return;
		}
		// Mini head movement with added randomness
		self.head.y = -40 + Math.sin(LK.ticks / 10 + Math.random() * 0.2) * 2;
		// Mini arm and forearm movement with added randomness
		self.leftArm.rotation += Math.sin(LK.ticks / 15 + Math.random() * 0.2) * 0.005;
		self.leftForearm.rotation += Math.sin(LK.ticks / 15 + Math.random() * 0.2) * 0.005; // Add forearm movement
		self.leftHand.x += Math.sin(LK.ticks / 15 + Math.random() * 0.2) * 0.5; // Add hand movement
		self.leftHand.rotation += Math.sin(LK.ticks / 15 + Math.random() * 0.2) * 0.005; // Add hand movement
		self.rightArm.rotation -= Math.sin(LK.ticks / 15 + Math.random() * 0.2) * 0.005;
		self.rightForearm.rotation -= Math.sin(LK.ticks / 15 + Math.random() * 0.2) * 0.005; // Add forearm movement
		self.rightHand.x -= Math.sin(LK.ticks / 15 + Math.random() * 0.2) * 0.5; // Add hand movement
		self.rightHand.rotation -= Math.sin(LK.ticks / 15 + Math.random() * 0.2) * 0.005; // Add hand movement
	};
	self.setPosture = function (targetPosture) {
		if (targetPosture == null) {
			return;
		}
		log("self.setPosture: " + targetPosture.name);
		// Torso
		self.torso.x = targetPosture.torso.x;
		self.torso.y = targetPosture.torso.y;
		self.torso.width = targetPosture.torso.w;
		self.torso.height = targetPosture.torso.h;
		self.torso.rotation = targetPosture.torso.r;
		// Head
		self.head.x = targetPosture.head.x;
		self.head.y = targetPosture.head.y;
		self.head.width = targetPosture.head.w;
		self.head.height = targetPosture.head.h;
		self.head.rotation = targetPosture.head.r;
		// Left Arm
		self.leftArm.x = targetPosture.leftArm.x;
		self.leftArm.y = targetPosture.leftArm.y;
		self.leftArm.width = targetPosture.leftArm.w;
		self.leftArm.height = targetPosture.leftArm.h;
		self.leftArm.rotation = targetPosture.leftArm.r;
		// Right Arm
		self.rightArm.x = targetPosture.rightArm.x;
		self.rightArm.y = targetPosture.rightArm.y;
		self.rightArm.width = targetPosture.rightArm.w;
		self.rightArm.height = targetPosture.rightArm.h;
		self.rightArm.rotation = targetPosture.rightArm.r;
		// Left Forearm
		self.leftForearm.x = targetPosture.leftForearm.x;
		self.leftForearm.y = targetPosture.leftForearm.y;
		self.leftForearm.width = targetPosture.leftForearm.w;
		self.leftForearm.height = targetPosture.leftForearm.h;
		self.leftForearm.rotation = targetPosture.leftForearm.r;
		// Right Forearm
		self.rightForearm.x = targetPosture.rightForearm.x;
		self.rightForearm.y = targetPosture.rightForearm.y;
		self.rightForearm.width = targetPosture.rightForearm.w;
		self.rightForearm.height = targetPosture.rightForearm.h;
		self.rightForearm.rotation = targetPosture.rightForearm.r;
		// Left Hand
		self.leftHand.x = targetPosture.leftHand.x;
		self.leftHand.y = targetPosture.leftHand.y;
		self.leftHand.width = targetPosture.leftHand.w;
		self.leftHand.height = targetPosture.leftHand.h;
		self.leftHand.rotation = targetPosture.leftHand.r;
		// Right Hand
		self.rightHand.x = targetPosture.rightHand.x;
		self.rightHand.y = targetPosture.rightHand.y;
		self.rightHand.width = targetPosture.rightHand.w;
		self.rightHand.height = targetPosture.rightHand.h;
		self.rightHand.rotation = targetPosture.rightHand.r;
	};
	self.aiFight = function () {
		if (LK.ticks % 200 == 0) {
			self.punch(Math.random() < 0.5);
		}
	};
});
/****************************************************************************************** */ 
/************************************* GUARD BUTTON CLASS ********************************** */
/****************************************************************************************** */ 
var GuardButton = Container.expand(function () {
	var self = Container.call(this);
	self.buttonAsset = self.attachAsset('guardButton', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0.8
	});
	self.x = 400; // Position button in the bottom center
	self.y = game.height - 350;
	self.down = function (x, y, obj) {
		player.guard(true); // Activate guard state for player
		self.width *= 0.9;
		self.height *= 0.9;
	};
	self.up = function (x, y, obj) {
		player.guard(false);
		self.width = 600;
		self.height = 600;
	};
});
/****************************************************************************************** */ 
/************************************* PUNCH BUTTON CLASS ********************************** */
/****************************************************************************************** */ 
var PunchButton = Container.expand(function () {
	var self = Container.call(this);
	self.buttonAsset = self.attachAsset('punchButton', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0.8
	});
	self.x = game.width - 400; // Position button on the bottom right
	self.y = game.height - 350;
	self.down = function (x, y, obj) {
		// Simulate button press by triggering punch with left arm
		player.punch(Math.random() < 0.5); // Randomly choose left or right arm for punching
		self.width *= 0.9;
		self.height *= 0.9;
	};
	self.up = function (x, y, obj) {
		// Simulate button release by triggering punch with right arm
		self.width = 600;
		self.height = 600;
	};
});
/****************************************************************************************** */ 
/**************************************** RING CLASS ************************************** */
/****************************************************************************************** */ 
var Ring = Container.expand(function () {
	var self = Container.call(this);
	self.ringAsset = self.attachAsset('ring', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.x = 1024; // Center of the screen horizontally
	self.y = 1366 - self.height / 6; // Center of the screen vertically
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000 // Init game with black background
});
/**** 
* Game Code
****/ 
/****************************************************************************************** */ 
/************************************** GLOBAL VARIABLES ********************************** */
/****************************************************************************************** */ 
var isPlaying = false;
var ring;
var punchButton;
var guardButton;
var player;
var opponent;
var touchPosition = null;
var swipeStart = null;
var swipeEnd = null;
var isDebug = true;
/****************************************************************************************** */ 
/************************************** POSTURES ****************************************** */
/****************************************************************************************** */ 
var idlePosture = {
	name: "idlePosture",
	// Left Arm
	leftForearm: {
		x: -110,
		y: -125,
		w: 80,
		h: 120,
		r: -Math.PI * 0.2
	},
	leftHand: {
		x: -110,
		y: -250,
		w: 80,
		h: 180,
		r: -Math.PI * 0.05
	},
	leftArm: {
		x: -120,
		y: -120,
		w: 80,
		h: 150,
		r: 0
	},
	// Right Arm
	rightForearm: {
		x: 110,
		y: -125,
		w: 80,
		h: 120,
		r: Math.PI * 0.2
	},
	rightHand: {
		x: 110,
		y: -250,
		w: 90,
		h: 180,
		r: Math.PI * 0.05
	},
	rightArm: {
		x: 120,
		y: -120,
		w: 80,
		h: 150,
		r: 0
	},
	torso: {
		x: 0,
		y: 0,
		w: 300,
		h: 150,
		r: 0
	},
	head: {
		x: 0,
		y: -40,
		w: 150,
		h: 190,
		r: 0
	}
};
/****************************************************************************************** */ 
/*********************************** UTILITY FUNCTIONS ************************************ */
/****************************************************************************************** */ 
function log() {
	if (isDebug) {
		var _console;
		(_console = console).log.apply(_console, arguments);
	}
}
/****************************************************************************************** */ 
/************************************** INPUT HANDLERS ************************************ */
/****************************************************************************************** */ 
game.down = function (x, y, obj) {
	if (!isPlaying) {
		isPlaying = true;
	}
};
game.move = function (x, y, obj) {};
game.up = function (x, y, obj) {};
/****************************************************************************************** */ 
/************************************ GAME INITIALIZE ************************************* */
/****************************************************************************************** */ 
function gameInitialize() {
	log("Game initialize...");
	// Initialize Ring
	ring = game.addChild(new Ring());
	punchButton = game.addChild(new PunchButton());
	guardButton = game.addChild(new GuardButton());
	// Initialize Player
	player = game.addChild(new Athlete(true));
	player.x = 1024; // Center horizontally
	player.y = game.height * 0.55; // Position towards the bottom
	// Initialize Opponent
	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;
}
/****************************************************************************************** */ 
/************************************* GAME FUNCTIONS ************************************* */
/****************************************************************************************** */ 
function handleHit(attacker, defenser) {
	if (defenser.isGuarding) {
		LK.effects.flashScreen(attacker.isPlayer ? 0xaaaaaa : 0xaa0000, 10); // Flash the whole screen red for 0.5 seconds
		return;
	}
	// Player hit reaction: head goes back, flash screen red
	// Calculate defenser's current direction and move back accordingly
	var defenserDirection = Math.atan2(defenser.y - attacker.y, defenser.x - attacker.x);
	defenser.x += Math.cos(defenserDirection) * 50; // Move defenser back in the x direction of current movement
	defenser.y += Math.sin(defenserDirection) * 50; // Move defenser back in the y direction of current movement
	defenser.head.y -= 20; // Head returns to normal position
	LK.effects.flashScreen(attacker.isPlayer ? 0xFFFFFF : 0xFF0000, 100); // Flash the whole screen red for 0.5 seconds
	LK.setTimeout(function () {
		defenser.head.y += 20; // Head returns to normal position
	}, 500);
}
/****************************************************************************************** */ 
/************************************** 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 (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))) {
		handleHit(opponent, player);
	}
};
gameInitialize(); ===================================================================
--- original.js
+++ change.js
@@ -9,9 +9,10 @@
 	self.isPunching = false; // Indicates if the athlete is currently punching
 	self.isPlayer = isPlayer;
 	self.body = new Container();
 	game.addChild(self.body);
-	var punchDistance = 50; // Define punch distance for punching animation
+	var punchDistance = 60; // Define punch distance for punching animation
+	var attackDistance = 500;
 	self.targetX = self.targetX || 1024; // Default target X
 	self.targetY = self.targetY || 1366; // Default target Y
 	// Left Arm
 	self.leftForearm = self.body.attachAsset('forearm', {
@@ -85,9 +86,9 @@
 		var forearm = isLeft ? self.leftForearm : self.rightForearm;
 		var hand = isLeft ? self.leftHand : self.rightHand;
 		// Refactored punch animation logic using deltas method
 		self.isPunching = true;
-		self.setPosture(idlePosture);
+		//self.setPosture(idlePosture);
 		var deltas = {
 			arm: {
 				height: punchDistance,
 				y: -punchDistance
@@ -121,9 +122,9 @@
 			applyDeltas(forearm, reverseDeltas(deltas.forearm));
 			applyDeltas(hand, reverseDeltas(deltas.hand));
 			applyDeltas(self.head, reverseDeltas(deltas.head));
 			self.isPunching = false;
-		}, 300);
+		}, 200);
 		function applyDeltas(element, deltas) {
 			for (var key in deltas) {
 				element[key] += deltas[key];
 			}
@@ -204,22 +205,17 @@
 	self.mainMove = function () {
 		if (self.isPlayer) {
 			return;
 		}
+		// AI Move
+		var target = player;
 		self.targetX = target.x;
 		self.targetY = target.y;
 		// 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 < 600) {
-			// Define a new target within the ring
-			/*
-							var ringCenterX = 1024; // Center of the ring X
-			var ringCenterY = 1366; // Center of the ring Y
-			var movementRadius = Math.random() * 300 + 100; // Random radius within which the athlete can move
-			var angle = Math.random() * Math.PI * 2; // Generate a random angle for movement direction
-			self.targetX = ringCenterX + Math.cos(angle) * movementRadius;
-			self.targetY = ringCenterY + Math.sin(angle) * movementRadius;
-							*/
+		if (distanceToTarget < attackDistance) {
+			self.isInAttackRange = true;
+			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;
@@ -296,8 +292,13 @@
 		self.rightHand.width = targetPosture.rightHand.w;
 		self.rightHand.height = targetPosture.rightHand.h;
 		self.rightHand.rotation = targetPosture.rightHand.r;
 	};
+	self.aiFight = function () {
+		if (LK.ticks % 200 == 0) {
+			self.punch(Math.random() < 0.5);
+		}
+	};
 });
 /****************************************************************************************** */ 
 /************************************* GUARD BUTTON CLASS ********************************** */
 /****************************************************************************************** */ 
@@ -483,24 +484,49 @@
 	opponent.y = game.height * 0.2; // Center vertically in the middle of the ring
 	opponent.rotation = Math.PI * 0.5;
 }
 /****************************************************************************************** */ 
+/************************************* GAME FUNCTIONS ************************************* */
+/****************************************************************************************** */ 
+function handleHit(attacker, defenser) {
+	if (defenser.isGuarding) {
+		LK.effects.flashScreen(attacker.isPlayer ? 0xaaaaaa : 0xaa0000, 10); // Flash the whole screen red for 0.5 seconds
+		return;
+	}
+	// Player hit reaction: head goes back, flash screen red
+	// Calculate defenser's current direction and move back accordingly
+	var defenserDirection = Math.atan2(defenser.y - attacker.y, defenser.x - attacker.x);
+	defenser.x += Math.cos(defenserDirection) * 50; // Move defenser back in the x direction of current movement
+	defenser.y += Math.sin(defenserDirection) * 50; // Move defenser back in the y direction of current movement
+	defenser.head.y -= 20; // Head returns to normal position
+	LK.effects.flashScreen(attacker.isPlayer ? 0xFFFFFF : 0xFF0000, 100); // Flash the whole screen red for 0.5 seconds
+	LK.setTimeout(function () {
+		defenser.head.y += 20; // Head returns to normal position
+	}, 500);
+}
+/****************************************************************************************** */ 
 /************************************** 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 (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
+		opponent.head.y += 20; // Head returns to normal position
 		}, 500);
+		*/
 	}
+	if (opponent.isPunching && (opponent.leftHand.intersects(player.torso) || opponent.rightHand.intersects(player.torso))) {
+		handleHit(opponent, player);
+	}
 };
 gameInitialize();
\ No newline at end of file
:quality(85)/https://cdn.frvr.ai/662a0f47d12deffd20bdefde.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/662a1185d12deffd20bdf011.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/662a1f6bd12deffd20bdf048.png%3F3) 
 clear
:quality(85)/https://cdn.frvr.ai/662aa70bd12deffd20bdf20b.png%3F3) 
 basic light gray convex round button with a red boxing glove icon. UI
:quality(85)/https://cdn.frvr.ai/662bd20a2a3743913629ff56.png%3F3) 
 Un gant de boxe bleu vu de dessus. video game
:quality(85)/https://cdn.frvr.ai/662be3d9fb7ae1a097893247.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/662bed78fb7ae1a0978932c7.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/662dd603fb7ae1a09789347b.png%3F3) 
 basic light round convex gray button with a raised blue shield icon.. UI
:quality(85)/https://cdn.frvr.ai/662dda89fb7ae1a0978934be.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/662e09944b4b64dc0512b734.png%3F3) 
 un Γ©clair. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/662e11a64b4b64dc0512b782.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/662e7e202a374391362a04ba.png%3F3) 
 remove
:quality(85)/https://cdn.frvr.ai/662e82832a374391362a051d.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/662fe0c0fb7ae1a0978937e3.png%3F3) 
 a basic white heart.. game icon
:quality(85)/https://cdn.frvr.ai/66307fe34b4b64dc0512b9c0.png%3F3) 
 A boxer has lost the match..
:quality(85)/https://cdn.frvr.ai/663082474b4b64dc0512ba04.png%3F3) 
 man boxer with red gloves is KO on the ring..