Code edit (1 edits merged)
Please save this source code
Code edit (13 edits merged)
Please save this source code
User prompt
in self.punch(), fix the setTimeout scopes problem
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: fasle is not defined' in or related to this line: 'if (fasle && isPlaying) {' Line Number: 211
Code edit (1 edits merged)
Please save this source code
Code edit (16 edits merged)
Please save this source code
User prompt
in handleHit, fix Head & torso back movement timout scope problem with
Code edit (3 edits merged)
Please save this source code
User prompt
in handleHit, when !defenser.isGuarding, flash the defenser in red
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
in handleHit, if defenser isn't withinLimits, move the attacker back
User prompt
in handleHit, use the ring border properties to check if within borders
User prompt
in Ring class, replace the limits array, by properties : leftBorder, rightBorder, topBorder and bottomBorder
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
===================================================================
--- 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
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..