Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
make trunk touch the head
Code edit (3 edits merged)
Please save this source code
User prompt
update the scales to make athelete thiner
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'var handsAndLegsReached = Math.abs(self.rightHand.x - self.targetPosture.rightHand.x) < 1 && Math.abs(self.rightHand.y - self.targetPosture.rightHand.y) < 1 && Math.abs(self.leftHand.x - self.targetPosture.leftHand.x) < 1 && Math.abs(self.leftHand.y - self.targetPosture.leftHand.y) < 1 && Math.abs(self.rightLeg.x - self.targetPosture.rightLeg.x) < 1 && Math.abs(self.rightLeg.y - self.targetPosture.rightLeg.y) < 1 && Math.abs(self.leftLeg.x - self.targetPosture.leftLeg.x) < 1 && Math.abs(self.leftLeg.y - self.targetPosture.leftLeg.y) < 1 && Math.abs(self.head.x - self.targetPosture.head.x) < 1 && Math.abs(self.head.y - self.targetPosture.head.y) < 1 && Math.abs(self.eyes.x - self.targetPosture.eyes.x) < 1 && Math.abs(self.eyes.y - self.targetPosture.eyes.y) < 1 && Math.abs(self.rightFoot.x - self.targetPosture.rightFoot.x) < 1 && Math.abs(self.rightFoot.y - self.targetPosture.rightFoot.y) < 1 && Math.abs(self.leftFoot.x - self.targetPosture.leftFoot.x) < 1 && Math.abs(self.leftFoot.y - self.targetPosture.leftFoot.y) < 1;' Line Number: 113
Code edit (1 edits merged)
Please save this source code
Initial prompt
AthleSticks
===================================================================
--- original.js
+++ change.js
@@ -8,16 +8,138 @@
/************************************* ATHLETE CLASS ************************************** */
/****************************************************************************************** */
var Athlete = Container.expand(function () {
var self = Container.call(this);
- var athleteGraphics = self.attachAsset('athlete', {
- anchorX: 0.5,
- anchorY: 1.0 // Anchor at the bottom center for realistic jumping
- });
self.speedX = 5;
self.jumpSpeed = -15;
self.gravity = 0.5;
self.isOnGround = true;
+ self.currentPosture = ""; // Store the name of the current posture
+ self.isChangingPosture = false; // 0 when idle or moving down, 1 when moving up
+ self.nextPosture = null;
+ // BODY PARTS
+ self.head = self.attachAsset('bodyPart', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.8,
+ scaleY: 1,
+ tint: self.tint
+ });
+ self.eyes = self.attachAsset('eyes', {
+ anchorX: 0.5,
+ anchorY: 0.75,
+ scaleX: 0.8,
+ scaleY: 1,
+ tint: 0xFFFFFF
+ });
+ self.rightArm = self.attachAsset('bodyPart', {
+ anchorX: 0.5,
+ anchorY: 1,
+ scaleX: 0.5,
+ scaleY: 1.5,
+ tint: self.tint
+ });
+ self.rightHand = self.attachAsset('bodyPart', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.75,
+ scaleY: 0.5,
+ tint: self.tint
+ });
+ self.leftArm = self.attachAsset('bodyPart', {
+ anchorX: 0.5,
+ anchorY: 1,
+ scaleX: 0.5,
+ scaleY: 1.5,
+ tint: self.tint
+ });
+ self.leftHand = self.attachAsset('bodyPart', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.75,
+ scaleY: 0.5,
+ tint: self.tint
+ });
+ self.trunk = self.attachAsset('bodyPart', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 1.5,
+ scaleY: 2.0,
+ tint: self.tint
+ });
+ self.rightLeg = self.attachAsset('bodyPart', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.5,
+ scaleY: 2,
+ tint: self.tint
+ });
+ self.rightFoot = self.attachAsset('bodyPart', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.75,
+ scaleY: 0.5,
+ tint: self.tint
+ });
+ self.leftLeg = self.attachAsset('bodyPart', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.5,
+ scaleY: 2,
+ tint: self.tint
+ });
+ self.leftFoot = self.attachAsset('bodyPart', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.75,
+ scaleY: 0.5,
+ tint: self.tint
+ });
+ // FUNCTIONS
+ self.updatePosture = function () {
+ var speed = 0.2; //0.1; // Speed of transition
+ if (!self.targetPosture || !self.targetPosture.rightHand || !self.targetPosture.leftHand || !self.targetPosture.rightLeg || !self.targetPosture.leftLeg || !self.targetPosture.head || !self.targetPosture.eyes || !self.targetPosture.rightFoot || !self.targetPosture.leftFoot) {
+ return;
+ }
+ // Check if the target posture for hands and legs is reached
+ //log("self.targetPosture: " + self.targetPosture.name + " : self.rightHand.x: " + self.rightHand.x, " self.targetPosture.rightHand.x: " + self.targetPosture.rightHand.x);
+ var handsAndLegsReached = Math.abs(self.rightHand.x - self.targetPosture.rightHand.x) < 1 && Math.abs(self.rightHand.y - self.targetPosture.rightHand.y) < 1 && Math.abs(self.leftHand.x - self.targetPosture.leftHand.x) < 1 && Math.abs(self.leftHand.y - self.targetPosture.leftHand.y) < 1 && Math.abs(self.rightLeg.x - self.targetPosture.rightLeg.x) < 1 && Math.abs(self.rightLeg.y - self.targetPosture.rightLeg.y) < 1 && Math.abs(self.leftLeg.x - self.targetPosture.leftLeg.x) < 1 && Math.abs(self.leftLeg.y - self.targetPosture.leftLeg.y) < 1 && Math.abs(self.head.x - self.targetPosture.head.x) < 1 && Math.abs(self.head.y - self.targetPosture.head.y) < 1 && Math.abs(self.eyes.x - self.targetPosture.eyes.x) < 1 && Math.abs(self.eyes.y - self.targetPosture.eyes.y) < 1 && Math.abs(self.rightFoot.x - self.targetPosture.rightFoot.x) < 1 && Math.abs(self.rightFoot.y - self.targetPosture.rightFoot.y) < 1 && Math.abs(self.leftFoot.x - self.targetPosture.leftFoot.x) < 1 && Math.abs(self.leftFoot.y - self.targetPosture.leftFoot.y) < 1;
+ if (handsAndLegsReached) {
+ //log("handsAndLegsReached !");
+ // Update currentPosture to the name of the targetPosture when hands and legs posture is reached
+ self.currentPosture = self.targetPosture.name;
+ self.targetPosture = null;
+ self.isChangingPosture = false;
+ if (self.nextPosture) {
+ self.setPosture(self.nextPosture);
+ }
+ return;
+ } else {
+ self.isChangingPosture = true;
+ }
+ if (self.targetPosture && self.targetPosture.head) {
+ self.head.x += (self.targetPosture.head.x - self.head.x) * speed;
+ }
+ self.head.y += (self.targetPosture.head.y - self.head.y) * speed;
+ self.rightArm.x += (self.targetPosture.rightArm.x - self.rightArm.x) * speed;
+ self.rightArm.y += (self.targetPosture.rightArm.y - self.rightArm.y) * speed;
+ self.rightHand.x += (self.targetPosture.rightHand.x - self.rightHand.x) * speed;
+ self.rightHand.y += (self.targetPosture.rightHand.y - self.rightHand.y) * speed;
+ self.leftArm.x += (self.targetPosture.leftArm.x - self.leftArm.x) * speed;
+ self.leftArm.y += (self.targetPosture.leftArm.y - self.leftArm.y) * speed;
+ self.leftHand.x += (self.targetPosture.leftHand.x - self.leftHand.x) * speed;
+ self.leftHand.y += (self.targetPosture.leftHand.y - self.leftHand.y) * speed;
+ self.trunk.x += (self.targetPosture.trunk.x - self.trunk.x) * speed;
+ self.trunk.y += (self.targetPosture.trunk.y - self.trunk.y) * speed;
+ self.rightLeg.x += (self.targetPosture.rightLeg.x - self.rightLeg.x) * speed;
+ self.rightLeg.y += (self.targetPosture.rightLeg.y - self.rightLeg.y) * speed;
+ self.rightFoot.x += (self.targetPosture.rightFoot.x - self.rightFoot.x) * speed;
+ self.rightFoot.y += (self.targetPosture.rightFoot.y - self.rightFoot.y) * speed;
+ self.leftLeg.x += (self.targetPosture.leftLeg.x - self.leftLeg.x) * speed;
+ self.leftLeg.y += (self.targetPosture.leftLeg.y - self.leftLeg.y) * speed;
+ self.leftFoot.x += (self.targetPosture.leftFoot.x - self.leftFoot.x) * speed;
+ self.leftFoot.y += (self.targetPosture.leftFoot.y - self.leftFoot.y) * speed;
+ };
self.moveRight = function () {
self.x += self.speedX;
};
self.jump = function () {
@@ -35,8 +157,25 @@
self.isOnGround = true;
}
}
};
+ self.setPosture = function (newPosture) {
+ log("Set posture: " + newPosture.name);
+ if (self.isChangingPosture) {
+ // Store next posture for when target one is reached
+ self.nextPosture = newPosture;
+ return;
+ }
+ if (self.nextPosture) {
+ // If a next posture is set, use it as target
+ newPosture = self.nextPosture;
+ self.nextPosture = null;
+ }
+ if (newPosture && self.currentPosture != newPosture.name) {
+ // Set new posture
+ self.targetPosture = newPosture;
+ }
+ };
});
/****************************************************************************************** */
/************************************** OBSTACLE CLASS ************************************ */
/****************************************************************************************** */
@@ -85,8 +224,51 @@
var isDebug = true;
/****************************************************************************************** */
/************************************** POSTURES ****************************************** */
/****************************************************************************************** */
+var idlePosture = {
+ name: "idlePosture",
+ head: {
+ x: 0,
+ y: -160
+ },
+ rightArm: {
+ x: 110,
+ y: 50
+ },
+ rightHand: {
+ x: 125,
+ y: 30
+ },
+ leftArm: {
+ x: -110,
+ y: 50
+ },
+ leftHand: {
+ x: -120,
+ y: 30
+ },
+ trunk: {
+ x: 0,
+ y: 0
+ },
+ rightLeg: {
+ x: 37.5,
+ y: 150
+ },
+ rightFoot: {
+ x: 50,
+ y: 250
+ },
+ leftLeg: {
+ x: -37.5,
+ y: 150
+ },
+ leftFoot: {
+ x: -50,
+ y: 250
+ }
+};
/****************************************************************************************** */
/*********************************** UTILITY FUNCTIONS ************************************ */
/****************************************************************************************** */
function log() {
@@ -113,14 +295,17 @@
// Initialize athlete
athlete = game.addChild(new Athlete());
athlete.x = 400;
athlete.y = groundLevel;
+ athlete.setPosture(idlePosture);
// Set the ground level globally accessible within the game instance
game.groundLevel = groundLevel;
+ gameState = GAME_STATE.PLAYING;
}
function gamePlaying() {
log("Game playing...");
athlete.update();
+ athlete.updatePosture();
// Move obstacles and check for off-screen
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].move();
// Remove obstacle if it moves off-screen
@@ -146,9 +331,8 @@
LK.effects.flashScreen(0xff0000, 500); // Flash screen red for half a second
LK.showGameOver(); // Show game over screen
}
});
- gameState = GAME_STATE.PLAYING;
}
/****************************************************************************************** */
/************************************** MAIN GAME LOOP ************************************ */
/****************************************************************************************** */
Elongated elipse with black top half and white bottom half.
full close and front view of empty stands. retro gaming style
delete
delete
Basquettes à ressort futuriste. vue de profile. Retro gaming style
a blue iron man style armor flying. Retro gaming style
a blue iron man style armor flying horizontally. Retro gaming style
round button with a big "up" arrow icon and a small line under it. UI
A big black horizontal arrow pointing left with centred text 'YOU' in capital letters, painted on an orange floor.. horizontal and pointing left
remove
gold athletics medal with ribbon. retro gaming style
a black oval with a crying smiley face.