Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'anchorX')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 69
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'anchorX')' in or related to this line: 'monkey.monkeyAsset.anchorX = 0.91;' Line Number: 421
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: initialAsset is not defined' in or related to this line: 'self.removeChild(initialAsset);' Line Number: 66
Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'x')' in or related to this line: 'monkey.sprite.x = 2048 / 2;' Line Number: 246
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (12 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: oconutsInTree is not defined' in or related to this line: 'oconutsInTree.push(newCoconut);' Line Number: 338
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (19 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: coconut is not defined' in or related to this line: 'scoreTest = "Zone contact = " + zoneIntersectParasol(coconut[i]);' Line Number: 434
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (16 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: livesLeftGraphics[i] is undefined' in or related to this line: 'livesLeftGraphics[i].destroy();' Line Number: 264
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -9,8 +9,10 @@
anchorY: 0.5
});
self.isFalling = false;
self.isBouncing = false;
+ self.Xintercept = 0; //Abscisse d'interception du coconut avec le parasol
+ self.Yintercept = 0; //Ordonnée d'interception du coconut avec le parasol
self.trajectory = new Trajectory();
self.update = function () {
if (self.trajectory.typeTrajectory == 0) {
self.trajectory.updateLinear();
@@ -131,11 +133,8 @@
/****
* Game Code
****/
/****
-* Game zones and backgrounds
-****/
-/****
* GAME DESCRIPTION:
* Game Principle:
* NAME: COCO MONKEY V1.0 by Dalhem 2024
* -There is beach where people are enjoying the sun by the shadow of palm trees.
@@ -179,8 +178,11 @@
* The left zone: the coconut will bounce to the extrem left.
* The center zone: the coconut will randomly bounce to the left or to the right.
* The right zone: the coconut will bounce to the extrem right.
****/
+/****
+* Game zones and backgrounds
+****/
var ScoreZone = {
x: 0,
y: 0,
width: game.width,
@@ -208,10 +210,11 @@
monkey.y = monkeyLevel;
var parasol = game.addChild(new Parasol());
parasol.x = 2048 / 2;
parasol.y = OptionsZone.y - 400;
-var coconuts = [];
-var nombreCoconuts = 1;
+var coconutsInTree = []; //Tableau des coconuts dans les arbres
+var coconuts = []; //Tableau des coconuts en mouvement
+var nombreCoconuts = 3; //Nombre de coconuts en mouvement en même temps
var sommetParaboleHaute = ScoreZone.height + 200;
var sommetParaboleBasse = ScoreZone.height + 400;
var nbTicksToBounceHight = 500;
var nbTicksTobounceLow = 500;
@@ -305,16 +308,16 @@
// Choisir aléatoirement un point de départ
var randomIndex = Math.floor(Math.random() * startPoints.length);
var typeTrajectory = 0;
newCoconut.isFalling = true;
- var X1 = startPoints[randomIndex];
+ //var X1 = startPoints[randomIndex];
+ var X1 = startPoints[1];
var X2 = X1;
var Y0 = groundLevel;
var Yh = monkeyLevel;
var totalTicks = 500;
newCoconut.trajectory.setParameters(typeTrajectory, X1, X2, Y0, Yh, totalTicks);
coconuts.push(newCoconut);
- scoreTest = "New coconut: (" + monkey.x + ", " + monkey.y + ")";
moveMonkeyToStartPoint(X1, monkeyLevel);
return newCoconut;
} //fin chooseNextStartPoint
//Fonction moveMonkeyToStartPoint: déplace le monkey au point de départ du coconut
@@ -322,24 +325,24 @@
//Efface le monkey de l'écran
game.removeChild(monkey);
monkey.x = x;
monkey.y = y;
- scoreTest = "New monkey: (" + monkey.x + ", " + monkey.y + ")";
- //game.addChild(monkey);
+ game.addChild(monkey);
} //fin moveMonkeyToStartPoint
//Fonction checkPosition : donne la position XL, XC, ou XR la plus proche de la position x du parasol
-function checkPosition(x) {
- var deltaX = Math.abs(x - XL);
- var deltaY = Math.abs(x - XC);
- var deltaZ = Math.abs(x - XR);
+function checkPosition(parasol) {
+ var deltaX = Math.abs(parasol.x - XL);
+ var deltaY = Math.abs(parasol.x - XC);
+ var deltaZ = Math.abs(parasol.x - XR);
+ scoreTest = " deltaX = " + deltaX + " deltaY = " + deltaY + " deltaZ = " + deltaZ + " parasol.x = " + parasol.x + " parasol.width = " + parasol.width;
var Xreturn = -1;
- if (deltaX <= deltaY && deltaX <= deltaZ) {
+ if (deltaX <= parasol.width / 2) {
Xreturn = XL;
}
- if (deltaY <= deltaX && deltaY <= deltaZ) {
+ if (deltaY <= parasol.width / 2) {
Xreturn = XC;
}
- if (deltaZ <= deltaX && deltaZ <= deltaY) {
+ if (deltaZ <= parasol.width / 2) {
Xreturn = XR;
}
return Xreturn;
} //fin checkPosition
@@ -387,11 +390,13 @@
function changeTrajectory(coconut, randomIndex) {
if (randomIndex != 0 && randomIndex != 1 && randomIndex != 2 && randomIndex != 3) {
randomIndex = Math.floor(Math.random() * 4);
}
- var Xposition = checkPosition(parasol.x);
+ var Xposition = checkPosition(parasol);
var deltaX = Math.abs(coconut.x - Xposition);
+ //scoreTest = " Xposition = " + Xposition + " deltaX = " + deltaX;
if (Xposition == XL) {
+ //scoreTest = " Xposition = XL";
if (randomIndex == 0) {
//vers la gauche, sortie de l'écran
coconut.trajectory.setParameters(1, coconut.x, -XL - deltaX, coconut.y, sommetParaboleBasse, nbTicksToBounceHight);
}
@@ -406,10 +411,10 @@
if (randomIndex == 3) {
//vers l'extrême droite, parabole basse
coconut.trajectory.setParameters(1, coconut.x, XR - deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
}
- }
- if (Xposition == XC) {
+ } else if (Xposition == XC) {
+ //scoreTest = " Xposition = XC";
if (randomIndex == 0) {
//vers la gauche, sortie d'ecran
coconut.trajectory.setParameters(1, coconut.x, -XL + deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
}
@@ -424,10 +429,10 @@
if (randomIndex == 3) {
//Vers la droite, sortie d'ecran
coconut.trajectory.setParameters(1, coconut.x, XR + 2 * XL - deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
}
- }
- if (Xposition == XR) {
+ } else if (Xposition == XR) {
+ //scoreTest = " Xposition = XR";
if (randomIndex == 0) {
//vers l'extrême gauche, parabole basse
coconut.trajectory.setParameters(1, coconut.x, XL + deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
}
@@ -442,16 +447,19 @@
if (randomIndex == 3) {
//vers l'extrême gauche, parabole haute
coconut.trajectory.setParameters(1, coconut.x, XR + 2 * XL - deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
}
+ } else {
+ //scoreTest = " NO POSITION";
}
} //fin changeTrajectory
/****
* Main loop
****/
game.update = function () {
//Mise à jour score
//scoreTest = livesLeft;
+ //scoreTest = "Coconuts restantes: " + coconuts.length;
updateScoreTest(scoreTest);
updateScore(score);
//Autres actions à effectuer sans urgence
if (LK.ticks % 60 == 0) {
@@ -465,11 +473,17 @@
}
//Check if a coconut has touched the parasol et changement de trajectoire
for (var i = coconuts.length - 1; i >= 0; i--) {
if (coconuts[i].intersects(parasol) && coconuts[i].isFalling) {
+ coconuts[i].Xintercept = parasol.x;
+ coconuts[i].Yintercept = coconuts[i].y;
+ //scoreTest = "Xintercept = " + coconuts[i].Xintercept + " Yintercept = " + coconuts[i].Yintercept;
score += 10;
coconuts[i].isFalling = false;
var deltaX = Math.abs(coconuts[i].x - XL);
+ var bouncingSoundList = ['bouncing1', 'bouncing2', 'bouncing3'];
+ var bouncingSound = bouncingSoundList[Math.floor(Math.random() * bouncingSoundList.length)];
+ LK.getSound(bouncingSound).play();
changeTrajectory(coconuts[i], zoneIntersectParasol(coconuts[i]));
coconuts[i].isBouncing = true;
}
}