User prompt
implement player been hit : head should go back, flash the whole screen red
User prompt
implement player been hit
Code edit (13 edits merged)
Please save this source code
User prompt
Simulate punch button press and release
User prompt
Simulate punch button press and release
User prompt
no, you should do both : reduce when pressed and restore when up
User prompt
but restore the button w & h when released :)
User prompt
when punch button is pressed, reduce its w & h to simulate press
Code edit (1 edits merged)
Please save this source code
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
/**** * Classes ****/ 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 var punchDistance = 50; // 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, x: -120, y: -120 }); // 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, x: 120, y: -120, 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 += 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 // Add head movement to mimic boxer's dodge and hit reaction self.head.x += isLeft ? 15 : -15; // Move head opposite to punching arm for dodge self.head.width *= 0.95; // Simulate head tilt by narrowing the width for dodge self.head.height *= 1.05; // Increase head height to simulate dodge self.head.rotation -= isLeft ? -0.1 : 0.1; // Tilt head for dodge // Implement hit reaction LK.setTimeout(function () { self.head.x += isLeft ? -30 : 30; // Move head back to simulate hit reaction LK.effects.flashScreen(0xff0000, 500); // Flash the whole screen red for 500ms }, 100); }, 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 self.head.x += isLeft ? -15 : 15; // Move head opposite to punching arm self.head.width /= 0.95; // Reset head width to simulate head tilt back 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 }, 200); }; // Update player position based on input self.update = function () { // 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; // 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; } } } // 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 movement with added randomness self.leftArm.rotation += Math.sin(LK.ticks / 15 + Math.random() * 0.2) * 0.005; self.rightArm.rotation -= Math.sin(LK.ticks / 15 + Math.random() * 0.2) * 0.005; // 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; }; }); var PunchButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('punchButton', { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 }); self.x = game.width - 220; // Position button on the bottom right self.y = game.height - 220; self.down = function (x, y, obj) { // Simulate button press by triggering punch with left arm player.punch(Math.random() < 0.5); // Randomly choose left or right arm for punching self.width *= 0.9; self.height *= 0.9; }; self.up = function (x, y, obj) { // Simulate button release by triggering punch with right arm self.width /= 0.9; self.height /= 0.9; }; }); /**** * 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 joystick = game.addChild(new Joystick()); var punchButton = game.addChild(new PunchButton()); var dragNode = null; // Initialize 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()); 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 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 };
===================================================================
--- original.js
+++ change.js
@@ -153,13 +153,18 @@
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
- // Add head movement to mimic boxer's dodge
- self.head.x += isLeft ? 15 : -15; // Move head opposite to punching arm
- self.head.width *= 0.95; // Simulate head tilt by narrowing the width
- 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
+ // Add head movement to mimic boxer's dodge and hit reaction
+ self.head.x += isLeft ? 15 : -15; // Move head opposite to punching arm for dodge
+ self.head.width *= 0.95; // Simulate head tilt by narrowing the width for dodge
+ self.head.height *= 1.05; // Increase head height to simulate dodge
+ self.head.rotation -= isLeft ? -0.1 : 0.1; // Tilt head for dodge
+ // Implement hit reaction
+ LK.setTimeout(function () {
+ self.head.x += isLeft ? -30 : 30; // Move head back to simulate hit reaction
+ LK.effects.flashScreen(0xff0000, 500); // Flash the whole screen red for 500ms
+ }, 100);
}, 100);
LK.setTimeout(function () {
/*
arm.height -= punchDistance;
@@ -178,20 +183,8 @@
self.head.x += isLeft ? -15 : 15; // Move head opposite to punching arm
self.head.width /= 0.95; // Reset head width to simulate head tilt back
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
- // Implement player been hit reaction
- LK.setTimeout(function () {
- if (!self.isHuman) {
- // Check if the player is not human to apply hit reaction
- self.body.tint = 0xff0000; // Change color to red to indicate hit
- self.head.tint = 0xff0000; // Change head color to red to indicate hit
- LK.setTimeout(function () {
- self.body.tint = 0xFFFFFF; // Reset color after hit
- self.head.tint = 0xFFFFFF; // Reset head color after hit
- }, 200); // Reset color after 200ms
- }
- }, 100); // Trigger hit reaction after 100ms
}, 200);
};
// Update player position based on input
self.update = function () {
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..