Code edit (13 edits merged)
Please save this source code
User prompt
in self.punch(), fix the setTimeout scopes problem
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: fasle is not defined' in or related to this line: 'if (fasle && isPlaying) {' Line Number: 211
Code edit (1 edits merged)
Please save this source code
Code edit (16 edits merged)
Please save this source code
User prompt
in handleHit, fix Head & torso back movement timout scope problem with
Code edit (3 edits merged)
Please save this source code
User prompt
in handleHit, when !defenser.isGuarding, flash the defenser in red
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
in handleHit, if defenser isn't withinLimits, move the attacker back
User prompt
in handleHit, use the ring border properties to check if within borders
User prompt
in Ring class, replace the limits array, by properties : leftBorder, rightBorder, topBorder and bottomBorder
Code edit (21 edits merged)
Please save this source code
User prompt
now, in handleHit(), check if newX and newY are out of ring's limits
User prompt
store the following coordinates as ring limits properties in ring class : [300,200], [1800,200], [300,1750], [1800,1750]
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: target is not defined' in or related to this line: 'self.targetX = target.x;' Line Number: 223
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
factorize punch() function by using the deltas method
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -293,9 +293,9 @@
self.rightHand.height = targetPosture.rightHand.h;
self.rightHand.rotation = targetPosture.rightHand.r;
};
self.aiFight = function () {
- if (LK.ticks % 200 == 0) {
+ if (LK.ticks % 222 == 0) {
self.punch(Math.random() < 0.5);
}
};
});
@@ -350,8 +350,21 @@
/**************************************** RING CLASS ************************************** */
/****************************************************************************************** */
var Ring = Container.expand(function () {
var self = Container.call(this);
+ self.limits = [{
+ x: 300,
+ y: 200
+ }, {
+ x: 1800,
+ y: 200
+ }, {
+ x: 300,
+ y: 1750
+ }, {
+ x: 1800,
+ y: 1750
+ }];
self.ringAsset = self.attachAsset('ring', {
anchorX: 0.5,
anchorY: 0.5
});
@@ -381,8 +394,9 @@
var touchPosition = null;
var swipeStart = null;
var swipeEnd = null;
var isDebug = true;
+var debugMarker;
/****************************************************************************************** */
/************************************** POSTURES ****************************************** */
/****************************************************************************************** */
var idlePosture = {
@@ -482,26 +496,41 @@
opponent = game.addChild(new Athlete());
opponent.x = 1024; // Center horizontally
opponent.y = game.height * 0.2; // Center vertically in the middle of the ring
opponent.rotation = Math.PI * 0.5;
+ if (isDebug) {
+ // Debug Marker
+ debugMarker = LK.getAsset('debugMarker', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ game.addChild(debugMarker);
+ debugMarker.x = 1800;
+ debugMarker.y = 1750;
+ }
}
/****************************************************************************************** */
/************************************* GAME FUNCTIONS ************************************* */
/****************************************************************************************** */
function handleHit(attacker, defenser) {
- if (defenser.isGuarding) {
- LK.effects.flashScreen(attacker.isPlayer ? 0xaaaaaa : 0xaa0000, 10); // Flash the whole screen red for 0.5 seconds
- return;
- }
+ var backDelta = defenser.isGuarding ? 5 : 50;
+ var backHeadDelta = defenser.isGuarding ? 2 : 20;
// Player hit reaction: head goes back, flash screen red
// Calculate defenser's current direction and move back accordingly
var defenserDirection = Math.atan2(defenser.y - attacker.y, defenser.x - attacker.x);
- defenser.x += Math.cos(defenserDirection) * 50; // Move defenser back in the x direction of current movement
- defenser.y += Math.sin(defenserDirection) * 50; // Move defenser back in the y direction of current movement
- defenser.head.y -= 20; // Head returns to normal position
- LK.effects.flashScreen(attacker.isPlayer ? 0xFFFFFF : 0xFF0000, 100); // Flash the whole screen red for 0.5 seconds
+ // Move defenser back
+ var newX = defenser.x + Math.cos(defenserDirection) * backDelta;
+ var newY = defenser.y + Math.sin(defenserDirection) * backDelta;
+ // TODO : Check if in ring's ropes
+ defenser.x = newX; // Move defenser back in the x direction of current movement
+ defenser.y = newY; // Move defenser back in the y direction of current movement
+ if (!defenser.isGuarding) {
+ LK.effects.flashScreen(attacker.isPlayer ? 0xFFFFFF : 0xFF0000, 100); // Flash the whole screen
+ }
+ // Head back movement
+ defenser.head.y -= backHeadDelta; // Head returns to normal position
LK.setTimeout(function () {
- defenser.head.y += 20; // Head returns to normal position
+ defenser.head.y += backHeadDelta; // Head returns to normal position
}, 500);
}
/****************************************************************************************** */
/************************************** MAIN GAME LOOP ************************************ */
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..