User prompt
add a control joystick at the bottom left
Code edit (16 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: punchDistance is not defined' in or related to this line: 'self.leftArm.height += punchDistance;' Line Number: 119
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
log player.width when down
Code edit (3 edits merged)
Please save this source code
User prompt
set also swipeStart in 'down' event
Code edit (1 edits merged)
Please save this source code
User prompt
in punch(), move arm, forearm and hand vertically
User prompt
call Player punch() when a simple tap is made, when x is on the left half pass true
Code edit (1 edits merged)
Please save this source code
User prompt
add a function punch() to player class that takes a boolean 'isLeft'
User prompt
No, change all that : don't use a moveInterval, set change player X and Y speeds when swiping, and in player.update, update the position and progressively reduce the speed
Code edit (3 edits merged)
Please save this source code
User prompt
use a speed that decreases to make a fluid move
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: setInterval is not a function' in or related to this line: 'var moveInterval = setInterval(function () {' Line Number: 157
User prompt
Ok, make the move progressive
Code edit (3 edits merged)
Please save this source code
User prompt
Change the control system : A Swipe gives the direction of the move
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
Please fix the bug: 'TypeError: self is undefined' in or related to this line: 'self.leftHand = self.body.attachAsset('hand', {' Line Number: 148
===================================================================
--- original.js
+++ change.js
@@ -73,8 +73,9 @@
self.update = function () {
// Movement logic will be handled in the game's update function
self.body.x = self.x;
self.body.y = self.y;
+ self.body.rotation = self.rotation;
};
});
/****
@@ -98,39 +99,53 @@
}));
var dragNode = null;
// Initialize player
var player = game.addChild(new Player());
-player.body.x = 1024; // Center horizontally
-player.body.y = 2000; // Position towards the bottom
+player.x = 1024; // Center horizontally
+player.y = 2000; // Position towards the bottom
// Initialize a single fixed enemy
var enemy = game.addChild(new Player());
-enemy.body.x = 1024; // Center horizontally
-enemy.body.y = 1066; // Center vertically in the middle of the ring
-enemy.body.rotation = Math.PI;
+enemy.x = 1024; // Center horizontally
+enemy.y = 1066; // Center vertically in the middle of the ring
+enemy.rotation = Math.PI;
// Update the single fixed enemy
enemy.update();
var touchPosition = null;
+var swipeStart = null;
+var swipeEnd = null;
game.down = function (x, y, obj) {
- // Set drag node to player for dragging only.
- dragNode = player;
+ var game_position = game.toLocal(obj.global);
+ swipeStart = {
+ x: game_position.x,
+ y: game_position.y
+ };
};
game.move = function (x, y, obj) {
- if (dragNode) {
+ if (swipeStart) {
var game_position = game.toLocal(obj.global);
- // Calculate the distance to move the player towards the touch position gradually
- var targetX = dragNode.x + (game_position.x - dragNode.x) * 0.1; // Calculate target X with 10% movement towards touch
- var targetY = dragNode.y + (game_position.y - dragNode.y) * 0.1; // Calculate target Y with 10% movement towards touch
- // Constrain player within the ring boundaries
- var ringLeftEdge = ring.x - ring.width / 2 + dragNode.width / 2;
- var ringRightEdge = ring.x + ring.width / 2 - dragNode.width / 2;
- var ringTopEdge = ring.y - ring.height / 2 + dragNode.height / 2;
- var ringBottomEdge = ring.y + ring.height / 2 - dragNode.height / 2;
- dragNode.x = Math.max(ringLeftEdge, Math.min(ringRightEdge, targetX));
- dragNode.y = Math.max(ringTopEdge, Math.min(ringBottomEdge, targetY));
+ swipeEnd = {
+ x: game_position.x,
+ y: game_position.y
+ };
}
};
game.up = function (x, y, obj) {
- dragNode = null;
+ if (swipeStart && swipeEnd) {
+ var dx = swipeEnd.x - swipeStart.x;
+ var dy = swipeEnd.y - swipeStart.y;
+ var direction = Math.atan2(dy, dx);
+ player.x += Math.cos(direction) * player.speed;
+ player.y += Math.sin(direction) * player.speed;
+ // Constrain player within the ring boundaries
+ var ringLeftEdge = ring.x - ring.width / 2 + player.width / 2;
+ var ringRightEdge = ring.x + ring.width / 2 - player.width / 2;
+ var ringTopEdge = ring.y - ring.height / 2 + player.height / 2;
+ var ringBottomEdge = ring.y + ring.height / 2 - player.height / 2;
+ player.x = Math.max(ringLeftEdge, Math.min(ringRightEdge, player.x));
+ player.y = Math.max(ringTopEdge, Math.min(ringBottomEdge, player.y));
+ }
+ swipeStart = null;
+ swipeEnd = null;
};
// Game update function
game.update = function () {
// This section has been removed to prevent redundant player movement handling.
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..