Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
use the Ring class in gameInitialize
User prompt
create a Class for the ring
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: player is undefined' in or related to this line: 'if ((player.leftHand.intersects(opponent.head) || player.rightHand.intersects(opponent.head)) && player.isPunching) {' Line Number: 293
Code edit (1 edits merged)
Please save this source code
User prompt
only flash on hit when an athlete is Punching
User prompt
restore self.isPunching
User prompt
update self.isPunching
User prompt
add a propoery isPunching to athlete class
Code edit (1 edits merged)
Please save this source code
User prompt
set isPlaying to true on 1st screen tap
Code edit (1 edits merged)
Please save this source code
User prompt
don't update athletes when isPlaying is false
Code edit (2 edits merged)
Please save this source code
User prompt
add a globalVariable isPlaying
Code edit (1 edits merged)
Please save this source code
User prompt
in mainMove(); define a target within the ring then progressively move to the target. when reached choose another target
Code edit (1 edits merged)
Please save this source code
User prompt
in Athlete mainMove, make player randomly move around the ring center
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
in Player mini movements, also move forearms ans hands
User prompt
Add another button in the bottom center : gardButton
===================================================================
--- original.js
+++ change.js
@@ -1,81 +1,12 @@
/****
* Classes
****/
-var GuardButton = Container.expand(function () {
+/****************************************************************************************** */
+/************************************* ATHLETE CLASS ************************************** */
+/****************************************************************************************** */
+var Athlete = Container.expand(function (isHuman) {
var self = Container.call(this);
- var buttonGraphics = self.attachAsset('guardButton', {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.8
- });
- self.x = game.width / 2; // Position button in the bottom center
- self.y = game.height - 220;
- self.down = function (x, y, obj) {
- // Simulate guard button press
- self.alpha = 0.5; // Dim the button to indicate it's pressed
- };
- self.up = function (x, y, obj) {
- // Simulate guard button release
- self.alpha = 0.8; // Return button opacity back to normal
- };
-});
-var Joystick = Container.expand(function () {
- var self = Container.call(this);
- self.base = self.attachAsset('joystickBase', {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.7
- });
- self.knob = self.attachAsset('joystickKnob', {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.9
- });
- self.x = 220; // Position joystick on the bottom left
- self.y = game.height - 220;
- var dragging = false;
- var dragStart = null;
- var maxDistance = self.base.width / 2 - self.knob.width / 2; // Max distance knob can move from center
- self.down = function (x, y, obj) {
- var localPos = self.toLocal(obj.global);
- var dx = localPos.x - self.base.x;
- var dy = localPos.y - self.base.y;
- if (Math.sqrt(dx * dx + dy * dy) <= maxDistance) {
- dragging = true;
- dragStart = {
- x: x,
- y: y
- };
- }
- };
- self.move = function (x, y, obj) {
- if (dragging) {
- var localPos = self.toLocal(obj.global);
- var dx = localPos.x - self.base.x;
- var dy = localPos.y - self.base.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- var angle = Math.atan2(dy, dx);
- if (distance > maxDistance) {
- dx = Math.cos(angle) * maxDistance;
- dy = Math.sin(angle) * maxDistance;
- }
- self.knob.x = dx;
- self.knob.y = dy;
- }
- };
- self.up = function (x, y, obj) {
- if (dragging) {
- self.knob.x = 0;
- self.knob.y = 0;
- dragging = false;
- }
- };
-});
-// Assets initialization is handled automatically by the LK engine.
-// Player class
-var Player = Container.expand(function (isHuman) {
- var self = Container.call(this);
self.isHuman = isHuman;
self.body = new Container();
game.addChild(self.body);
// Define punch distance for punching animation
@@ -116,9 +47,9 @@
});
self.rightHand = self.body.attachAsset('hand', {
anchorX: 0.5,
anchorY: 0.5,
- x: 100,
+ x: 110,
y: -250,
scaleX: -1,
width: 80,
height: 180,
@@ -148,27 +79,11 @@
var forearm = isLeft ? self.leftForearm : self.rightForearm;
var hand = isLeft ? self.leftHand : self.rightHand;
// Punch animation logic
LK.setTimeout(function () {
- /*
arm.height += punchDistance;
arm.y -= punchDistance;
forearm.height += punchDistance;
- forearm.y -= punchDistance * 2; // Move forearm up for punch
- hand.y -= punchDistance * 2; // Move hand up for punch
- */
- /*
- self.leftArm.height += punchDistance;
- self.leftArm.y -= punchDistance;
- self.leftForearm.height += punchDistance;
- self.leftForearm.y -= punchDistance * 1.5; // Move forearm up for punch
- self.leftForearm.rotation = -Math.PI * 0.1; //-Math.PI * 0.2
- self.leftHand.x += 5; // Move hand up for punch
- self.leftHand.y -= punchDistance * 2; // Move hand up for punch
- */
- arm.height += punchDistance;
- arm.y -= punchDistance;
- forearm.height += punchDistance;
forearm.y -= punchDistance * 1.5; // Move forearm up for punch
forearm.rotation *= 0.5; //= -Math.PI * 0.1; //-Math.PI * 0.2
hand.x += 5; // Move hand up for punch
hand.y -= punchDistance * 2; // Move hand up for punch
@@ -178,18 +93,11 @@
self.head.height *= 1.05; // Reset head width to simulate head tilt back
self.head.rotation -= isLeft ? -0.1 : 0.1; // Simulate head tilt by narrowing the width
}, 100);
LK.setTimeout(function () {
- /*
arm.height -= punchDistance;
arm.y += punchDistance;
forearm.height -= punchDistance;
- forearm.y += punchDistance * 2; // Reset forearm position
- hand.y += punchDistance * 2; // Reset hand position
- */
- arm.height -= punchDistance;
- arm.y += punchDistance;
- forearm.height -= punchDistance;
forearm.y += punchDistance * 1.5; // Move forearm up for punch
forearm.rotation *= 2; //-Math.PI * 0.2
hand.x -= 5; // Move hand up for punch
hand.y += punchDistance * 2; // Move hand up for punch
@@ -200,55 +108,87 @@
}, 200);
};
// Update player position based on input
self.update = function () {
- // Only move player if it's human controlled via joystick
+ // Only move player if it's human controlled automatically
if (self.isHuman) {
- // Calculate movement based on joystick position
- var joystickDx = joystick.knob.x;
- var joystickDy = joystick.knob.y;
- // Normalize joystick input to determine direction
- var distance = Math.sqrt(joystickDx * joystickDx + joystickDy * joystickDy);
- if (distance > 0) {
- var normalizedDx = joystickDx / distance;
- var normalizedDy = joystickDy / distance;
- // Calculate potential new position
- var newX = self.x + normalizedDx * self.speed;
- var newY = self.y + normalizedDy * self.speed;
- // Determine target based on whether self is human or enemy
- var target = self.isHuman ? enemy : player;
- // Calculate distance to the opponent
- var distanceToOpponent = Math.sqrt(Math.pow(target.x - newX, 2) + Math.pow(target.y - newY, 2));
- // Minimum allowed distance
- var minDistance = 300; // Adjust as needed
- if (distanceToOpponent > minDistance) {
- self.x = newX;
- self.y = newY;
- }
- }
+ self.mainMove();
}
// Player is idle
- // 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 / 10 + Math.random() * 0.2) * 0.005; // Add forearm movement
- self.leftHand.x += Math.sin(LK.ticks / 5 + Math.random() * 0.02); // Add hand movement
- self.rightArm.rotation -= Math.sin(LK.ticks / 15 + Math.random() * 0.2) * 0.005;
- self.rightForearm.rotation -= Math.sin(LK.ticks / 10 + Math.random() * 0.2) * 0.005; // Add forearm movement
- self.rightHand.x -= Math.sin(LK.ticks / 5 + Math.random() * 0.02); // Add hand movement
+ 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.isHuman ? enemy : player; // Determine target based on whether self is human or enemy
var angleToOpponent = Math.atan2(target.y - self.y, target.x - self.x) + Math.PI * 0.5;
self.body.rotation = angleToOpponent;
};
+ self.mainMove = function () {
+ // Calculate movement based on random position
+ var dx = Math.random();
+ var dy = Math.random();
+ // Normalize to determine direction
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 0) {
+ var normalizedDx = dx / distance;
+ var normalizedDy = dy / distance;
+ // Calculate potential new position
+ var newX = self.x + normalizedDx * self.speed;
+ var newY = self.y + normalizedDy * self.speed;
+ // Determine target based on whether self is human or enemy
+ var target = self.isHuman ? enemy : player;
+ // Calculate distance to the opponent
+ var distanceToOpponent = Math.sqrt(Math.pow(target.x - newX, 2) + Math.pow(target.y - newY, 2));
+ // Minimum allowed distance
+ var minDistance = 300; // Adjust as needed
+ if (distanceToOpponent > minDistance) {
+ self.x = newX;
+ self.y = newY;
+ }
+ }
+ };
+ self.miniMove = function () {
+ // 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
+ };
});
+/****************************************************************************************** */
+/************************************* 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 = game.width / 2; // Position button in the bottom center
+ self.y = game.height - 220;
+ self.down = function (x, y, obj) {
+ // Simulate guard button press
+ self.alpha = 0.5; // Dim the button to indicate it's pressed
+ };
+ self.up = function (x, y, obj) {
+ // Simulate guard button release
+ self.alpha = 0.8; // Return button opacity back to normal
+ };
+});
+/****************************************************************************************** */
+/************************************* PUNCH BUTTON CLASS ********************************** */
+/****************************************************************************************** */
var PunchButton = Container.expand(function () {
var self = Container.call(this);
- var buttonGraphics = self.attachAsset('punchButton', {
+ self.buttonAsset = self.attachAsset('punchButton', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8
});
@@ -277,47 +217,37 @@
/****
* Game Code
****/
// Initialize ring in the game scene
+// TODO : Move to a class
var ring = game.addChild(LK.getAsset('ring', {
x: 1024,
- // Center horizontally
y: 1366,
- // Center vertically
anchorX: 0.5,
anchorY: 0.5
}));
-var joystick = game.addChild(new Joystick());
var punchButton = game.addChild(new PunchButton());
-var guardButton = game.addChild(new GuardButton()); // Add guardButton next to punchButton
-var dragNode = null;
+var guardButton = game.addChild(new GuardButton());
// Initialize player
-var player = game.addChild(new Player(true));
+var player = game.addChild(new Athlete(true));
player.x = 1024; // Center horizontally
player.y = 2000; // Position towards the bottom
// Initialize a single fixed enemy
-var enemy = game.addChild(new Player());
+var enemy = game.addChild(new Athlete());
enemy.x = 1024; // Center horizontally
enemy.y = 1066; // Center vertically in the middle of the ring
enemy.rotation = Math.PI * 0.5;
// Update the single fixed enemy
enemy.update();
var touchPosition = null;
var swipeStart = null;
var swipeEnd = null;
-game.down = function (x, y, obj) {
- // Removed swipe start logic for joystick implementation
-};
-game.move = function (x, y, obj) {
- // Removed swipe tracking logic for joystick implementation
-};
-game.up = function (x, y, obj) {
- // Removed swipe end logic and player movement calculation for joystick implementation
-};
+game.down = function (x, y, obj) {};
+game.move = function (x, y, obj) {};
+game.up = function (x, y, obj) {};
// Game update function
game.update = function () {
// This section has been removed to prevent redundant player movement handling.
- // Spawn enemies
// Check for collision between player's hand and enemy's head
if (player.leftHand.intersects(enemy.head) || player.rightHand.intersects(enemy.head)) {
// Player hit reaction: head goes back, flash screen red
// Calculate enemy's current direction and move back accordingly
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..