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
User prompt
instruction knob.intersects(localPos) isn't normal, the knob should follow the user move until the base limit
User prompt
fix the joystick
User prompt
Please fix the bug: 'TypeError: knob.hitTest is not a function' in or related to this line: 'if (knob.hitTest(localPos)) {' Line Number: 34
User prompt
replace swipe system by the joystick system
User prompt
Please fix the bug: 'TypeError: knob.containsPoint is not a function' in or related to this line: 'if (knob.containsPoint(localPos)) {' Line Number: 34
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
/****
* Classes
****/
// Assets initialization is handled automatically by the LK engine.
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
self.body = new Container();
game.addChild(self.body);
// 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('hand', {
anchorX: 0.5,
anchorY: 0.5,
x: -110,
y: -250,
width: 80,
height: 180,
rotation: -Math.PI * 0.05
});
self.leftArm = self.body.attachAsset('arm', {
anchorX: 0.5,
anchorY: 0.5,
x: -120,
y: -60
});
// 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('hand', {
anchorX: 0.5,
anchorY: 0.5,
x: 100,
y: -250,
scaleX: -1,
width: 80,
height: 180,
rotation: Math.PI * 0.05
});
self.rightArm = self.body.attachAsset('arm', {
anchorX: 0.5,
anchorY: 0.5,
x: 120,
y: -60,
scaleX: -1
});
self.torso = self.body.attachAsset('body', {
anchorX: 0.5,
anchorY: 0.5
});
self.head = self.body.attachAsset('head', {
anchorX: 0.5,
anchorY: 0.5,
y: -40
});
// Player movement speed
self.speed = 10;
// Punch function to handle punching action
self.punch = function (isLeft) {
var arm = isLeft ? self.leftArm : self.rightArm;
var forearm = isLeft ? self.leftForearm : self.rightForearm;
var hand = isLeft ? self.leftHand : self.rightHand;
// Punch animation logic
LK.setTimeout(function () {
arm.height += 20;
forearm.y -= 20; // Move forearm up for punch
hand.y -= 40; // Move hand up for punch
}, 100);
LK.setTimeout(function () {
arm.height -= 20;
forearm.y += 20; // Reset forearm position
hand.y += 40; // Reset hand position
}, 200);
};
// Update player position based on input
self.update = function () {
// Movement logic will be handled in the game's update function
// Update player position based on speed and reduce speed progressively
self.x += self.speedX;
self.y += self.speedY;
// Apply deceleration to speed
self.speedX *= 0.95;
self.speedY *= 0.95;
// Update body position and rotation
self.body.x = self.x;
self.body.y = self.y;
self.body.rotation = self.rotation;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize ring in the game scene
var ring = game.addChild(LK.getAsset('ring', {
x: 1024,
// Center horizontally
y: 1366,
// Center vertically
anchorX: 0.5,
anchorY: 0.5
}));
var dragNode = null;
// Initialize player
var player = game.addChild(new Player());
player.x = 1024; // Center horizontally
player.y = 2000; // Position towards the bottom
// Initialize a single fixed enemy
var enemy = game.addChild(new Player());
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) {
var game_position = game.toLocal(obj.global);
// Determine if tap is on the left or right half of the screen
var isLeft = game_position.x < game.width / 2;
player.punch(isLeft);
};
game.move = function (x, y, obj) {
if (swipeStart) {
var game_position = game.toLocal(obj.global);
swipeEnd = {
x: game_position.x,
y: game_position.y
};
}
};
game.up = function (x, y, obj) {
if (swipeStart && swipeEnd) {
var dx = swipeEnd.x - swipeStart.x;
var dy = swipeEnd.y - swipeStart.y;
var direction = Math.atan2(dy, dx);
var targetX = player.x + Math.cos(direction) * player.speed;
var targetY = 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;
targetX = Math.max(ringLeftEdge, Math.min(ringRightEdge, targetX));
targetY = Math.max(ringTopEdge, Math.min(ringBottomEdge, targetY));
// Set player X and Y speeds based on swipe direction
player.speedX = Math.cos(direction) * player.speed;
player.speedY = Math.sin(direction) * player.speed;
}
swipeStart = null;
swipeEnd = null;
};
// Game update function
game.update = function () {
// This section has been removed to prevent redundant player movement handling.
// Spawn enemies
// Check for collision with player
// Removed game over trigger to prevent ending the game on player collision with enemy
};
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..