Code edit (3 edits merged)
Please save this source code
User prompt
Ignore taps during intro
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: K is not defined' in or related to this line: 'K.clearInterval(startClearInterval);' Line Number: 649
Code edit (1 edits merged)
Please save this source code
User prompt
play start sound after press start
User prompt
wait 1sec before gameover
Code edit (1 edits merged)
Please save this source code
User prompt
in the intro, play the fallsound when ninja arrive on platform
User prompt
cool. in the intro, add a y move to make it a parabolic jump
User prompt
the asset is not changed because of the ninja update logic...add an intro flag and use it in the ninja.update to prenvent updates
User prompt
for the intro animation, use ninjaRun graphic
User prompt
add an intro annimationwhere the ninja with asset jumps from x<0 to the 1st platform
User prompt
to ajust to distance of new platform per level, you must use platformNext.speedRatio
User prompt
like for the width, make the distance between platforms depend on the level (1st levels quite close, the far)
Code edit (2 edits merged)
Please save this source code
User prompt
log every time stick.y is set with the name of the function. use log() function
User prompt
log every time ninja.y is set with the name of the function. use log() function
Code edit (2 edits merged)
Please save this source code
User prompt
add an isDebug global variable
Code edit (1 edits merged)
Please save this source code
Code edit (16 edits merged)
Please save this source code
User prompt
for ninja run anim, use the following sequence : 1,2,1,3,4,3
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -33,16 +33,16 @@
});
var cloudGraphics = self.attachAsset('clouds1', {
anchorX: 0.5,
anchorY: 0.5,
- alpha: 0.8,
+ alpha: 0.9,
x: Math.random() * 512,
y: Math.random() * 480
});
var cloudGraphics2 = self.attachAsset('clouds1', {
anchorX: 0.5,
anchorY: 0.5,
- alpha: 0.8,
+ alpha: 0.9,
scaleX: -1.1,
scaleY: 1.1,
x: 1024 + Math.random() * 1024,
y: Math.random() * 480
@@ -120,9 +120,9 @@
self.ninjaRun3.visible = false; // Initially hide the running ninja graphic
self.ninjaRun4.visible = false;
self.runSoundPlaying = false;
self.update = function () {
- if (isNinjaMoving && !isStickFalling && ninja.x + ninja.width / 2 < stick.x + stick.length) {
+ if (isNinjaMoving && !isStickFalling && stick.length && ninja.x + ninja.width / 2 < stick.x + stick.length) {
self.ninjaStand.visible = false;
if (LK.ticks % 10 < 5) {
self.ninjaRun.visible = false;
self.ninjaRun1.visible = true;
@@ -164,28 +164,32 @@
self.ninjaRun2.visible = false;
self.ninjaRun3.visible = true;
self.ninjaRun4.visible = false;
}
- */
+ */
if (!self.runSoundPlaying) {
+ self.runSoundPlaying = true;
LK.getSound('runSound').play();
- self.runSoundInterval = LK.setInterval(function () {
+ log("Play sound :", isNinjaMoving, !isStickFalling, stick.length, ninja.x + ninja.width / 2, stick.x + stick.length, isReturningToBase);
+ /*self.runSoundInterval = LK.setInterval(function () {
LK.getSound('runSound').play();
- }, 540);
- self.runSoundPlaying = true;
+ }, 540);*/
}
} else {
- if (self.runSoundPlaying) {
+ /*if (self.runSoundPlaying) {
LK.clearInterval(self.runSoundInterval);
self.runSoundPlaying = false;
}
+ */
self.ninjaStand.visible = true;
self.ninjaRun.visible = false;
self.ninjaRun1.visible = false;
self.ninjaRun2.visible = false;
self.ninjaRun3.visible = false;
self.ninjaRun4.visible = false;
- self.runSoundPlaying = false;
+ if (!isNinjaMoving) {
+ self.runSoundPlaying = false;
+ }
}
};
});
// Platform class
@@ -344,9 +348,9 @@
game.addChild(midground2);
createInitialPlatforms();
if (platformCurrent) {
ninja.x = platformCurrent.x;
- ninja.y = platformCurrent.y - platformCurrent.height + 20; // Adjusted y-coordinate to ensure ninja is visible on the first hill with an offset of 20
+ ninja.y = platformCurrent.y - platformCurrent.height + 25; // Adjusted y-coordinate to ensure ninja is visible on the first hill with an offset of 20
log("ninja.y set in startGame:", ninja.y);
} else {
console.error("platformCurrent is not defined");
}
@@ -377,9 +381,9 @@
// Play background music every 10 seconds
LK.getSound('bgMusic').play();
LK.setInterval(function () {
LK.getSound('bgMusic').play();
- }, 10000);
+ }, 8730);
}
function handleNinjaReachPlatform() {
if (isDebug) {
console.log("Start of handleNinjaReachPlatform");
@@ -402,13 +406,13 @@
stick.rotation = 0;
stick.x = platformCurrent.x + platformCurrent.width / 2 - 30; // Set stick to the right edge of the current platform with an offset of -30
stick.y = platformCurrent.y - platformCurrent.height + 30; // Adjusted y-coordinate to ensure stick is on the platform with an offset of 20
log("stick.y set in handleNinjaReachPlatform:", stick.y);
- var minDistance = 200;
- var maxDistance = 400;
+ var minDistance = Math.max(100, 300 - level * 10); // Decrease minimum distance as level increases, with a minimum of 100
+ var maxDistance = Math.min(600, 400 + level * 20); // Increase maximum distance as level increases, with a maximum of 600
var distance = Math.floor(Math.random() * (maxDistance - minDistance + 1)) + minDistance;
platformNext.x = 2048 + distance; //platformTarget.x + platformTarget.width / 2 + distance;
- platformNext.y = 2732; // Adjusted y-coordinate to touch the ground
+ platformNext.y = groundOffset; // Adjusted y-coordinate to touch the ground
log("ninja.y set in handleNinjaReachPlatform:", ninja.y);
platformMinWidth = Math.max(50, 300 - level * 10); // Decrease minimum width as level increases, with a minimum of 50
platformNext.width = Math.floor(Math.random() * (platformMaxWidth - platformMinWidth + 1)) + platformMinWidth; // Randomize width between platformMinWidth and platformMaxWidth
level++; // Increment the level after each platform is reached
@@ -432,19 +436,11 @@
ninja.ninjaStand.rotation = Math.PI; // Rotate the ninja by 180 degrees
if (!fallSoundPlayed) {
LK.getSound('fallSound').play();
fallSoundPlayed = true; // Set the flag to true after playing the sound
- if (ninja.runSoundPlaying) {
- LK.getSound('runSound').stop();
- ninja.runSoundPlaying = false;
- }
}
if (ninja.y > 2732 && isNinjaMoving) {
// If ninja falls off the screen
- if (ninja.runSoundPlaying) {
- LK.clearInterval(ninja.runSoundInterval);
- ninja.runSoundPlaying = false;
- }
LK.showGameOver();
}
}
function handleNinjaAfterStick() {
@@ -465,9 +461,9 @@
}
}
function moveNinja() {
if (isDebug) {
- console.log("Moving...", "ninja.x= " + ninja.x, "stick.x= " + (stick.x + stick.length));
+ //console.log("Moving...", "ninja.x= " + ninja.x, "stick.x= " + (stick.x + stick.length));
}
// Shift platforms, ninja, and stick to the left
if (isNinjaMoving) {
handleBackgroundMovement(NINJA_MOVEMENT_SPEED);
@@ -485,13 +481,14 @@
}
}
function fallStick() {
stick.rotation += 0.1;
- if (stick.rotation >= Math.PI / 2) {
- LK.getSound('stickTapSound').play();
- stick.rotation = Math.PI / 2;
+ if (!isNinjaMoving && stick.rotation >= Math.PI / 2) {
isStickFalling = false;
isNinjaMoving = true;
+ log("Stick finnished falling");
+ LK.getSound('stickTapSound').play();
+ stick.rotation = Math.PI / 2;
}
}
function growStick() {
if (stick.length < 2048 - stick.x - 100) {
@@ -553,11 +550,11 @@
if (platformNext.x - platformNext.width < 2048) {
platformNext.x = 2048 + platformNext.width;
}
ninja.x += moveSpeed * Math.sign(distanceToMove);
- log("ninja.y set in handleReturningToBase:", ninja.y);
+ //log("ninja.y set in handleReturningToBase:", ninja.y);
stick.x += moveSpeed * Math.sign(distanceToMove);
- log("stick.y set in handleReturningToBase:", stick.y);
+ //log("stick.y set in handleReturningToBase:", stick.y);
handleBackgroundMovement(moveSpeed * Math.sign(distanceToMove));
}
}
// Create initial platforms
@@ -570,18 +567,18 @@
platform1.width = Math.floor(Math.random() * (platformMaxWidth - platformMinWidth + 1)) + platformMinWidth; // Randomize width between platformMinWidth and platformMaxWidth
game.addChild(platform1);
platformCurrent = platform1;
var platform2 = new Platform();
- var minDistance = 200;
- var maxDistance = 400;
+ var minDistance = Math.max(100, 300 - level * 10); // Decrease minimum distance as level increases, with a minimum of 100
+ var maxDistance = Math.min(600, 400 + level * 20); // Increase maximum distance as level increases, with a maximum of 600
var distance = Math.floor(Math.random() * (maxDistance - minDistance + 1)) + minDistance;
platform2.x = platform1.x + platform1.width + distance;
platform2.y = groundOffset; // Adjusted y-coordinate to touch the ground
platform2.width = Math.floor(Math.random() * (platformMaxWidth - platformMinWidth + 1)) + platformMinWidth; // Randomize width between platformMinWidth and platformMaxWidth
game.addChild(platform2);
platformTarget = platform2;
var platform3 = new Platform();
- platform3.x = platform2.x + platform2.width + distance; // Position the third platform outside the screen
+ platform3.x = 2048 + distance; // Position the third platform outside the screen
platform3.y = groundOffset; // Adjusted y-coordinate to touch the ground
platform3.width = Math.floor(Math.random() * (platformMaxWidth - platformMinWidth + 1)) + platformMinWidth; // Randomize width between platformMinWidth and platformMaxWidth
game.addChild(platform3);
platformNext = platform3;