Code edit (2 edits merged)
Please save this source code
User prompt
when punching, also change the width of the head to simulate the tilt
Code edit (2 edits merged)
Please save this source code
User prompt
when punching, move of the head like boxers do
User prompt
prevent players to be too close
User prompt
add a bit of randomness to the mini movements
Code edit (1 edits merged)
Please save this source code
User prompt
when idmle, animate the players with mini movements of head and arms
User prompt
when punching, randomly choose left or right arm
Code edit (5 edits merged)
Please save this source code
User prompt
in player update, also compute the angleToOpponent for the enemy
Code edit (3 edits merged)
Please save this source code
User prompt
when player moves, update its rotatoin to always face the opponent
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
add a new button at bottom right for punch
Code edit (5 edits merged)
Please save this source code
User prompt
only move the human player with joystick
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: base is not defined' in or related to this line: 'var dx = localPos.x - base.x;' Line Number: 34
User prompt
Please fix the bug: 'ReferenceError: base is not defined' in or related to this line: 'var maxDistance = base.width / 2; // Max distance knob can move from center' Line Number: 31
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: joystick.knob is undefined' in or related to this line: 'var joystickDx = joystick.knob.x;' Line Number: 188
User prompt
make the player move using the joystick
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -4,16 +4,18 @@
var Joystick = Container.expand(function () {
var self = Container.call(this);
self.base = self.attachAsset('joystickBase', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.5,
+ alpha: 0.75
});
self.knob = self.attachAsset('joystickKnob', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.5,
+ alpha: 0.75
});
- self.x = 200; // Position joystick on the bottom left
- self.y = game.height - 200;
+ 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; // Max distance knob can move from center
self.down = function (x, y, obj) {
@@ -52,10 +54,11 @@
};
});
// Assets initialization is handled automatically by the LK engine.
// Player class
-var Player = Container.expand(function () {
+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
var punchDistance = 50;
@@ -170,23 +173,26 @@
}, 200);
};
// Update player position based on input
self.update = function () {
- // 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;
- self.x += normalizedDx * self.speed;
- self.y += normalizedDy * self.speed;
+ // Only move player if it's human controlled via joystick
+ 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;
+ self.x += normalizedDx * self.speed;
+ self.y += normalizedDy * self.speed;
+ }
+ // Update body position and rotation
+ self.body.x = self.x;
+ self.body.y = self.y;
+ self.body.rotation = self.rotation;
}
- // Update body position and rotation
- self.body.x = self.x;
- self.body.y = self.y;
- self.body.rotation = self.rotation;
};
});
/****
@@ -216,9 +222,9 @@
anchorY: 0.5
}));
var dragNode = null;
// Initialize player
-var player = game.addChild(new Player());
+var player = game.addChild(new Player(true));
player.x = 1024; // Center horizontally
player.y = 2000; // Position towards the bottom
// Initialize a single fixed enemy
var enemy = game.addChild(new Player());
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..