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
@@ -199,9 +199,8 @@
y: game.height - ScoreZone.height,
width: game.width,
height: 200 * game.height / 2732
};
-setBackGroundImage('backGroundBeach', 0, 0, game.width, game.height);
/****
* Autres
****/
var monkeyLevel = 200;
@@ -212,9 +211,9 @@
parasol.x = 2048 / 2;
parasol.y = OptionsZone.y - 400;
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 nombreCoconuts = 15; //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;
@@ -224,8 +223,13 @@
var startPoints = [XL = game.width / 4, XC = game.width / 2, XR = 3 * game.width / 4]; // Define the startPoints array
var parasolLevel = OptionsZone.y - 600;
var groundLevel = OptionsZone.y - 300;
/****
+* Init game
+* ***/
+setBackGroundImage('backGroundBeach', 0, 0, game.width, game.height);
+setCocoInTree();
+/****
* Score
****/
var livesLeft = 3; //Nombre de vies restantes
var livesLeftGraphics = []; //Tableau des sprites 'life' représentant les vies restantes
@@ -300,18 +304,35 @@
for (var i = 0; i < livesLeft; i++) {
game.addChild(livesLeftGraphics[i]);
}
} //fin setLivesLeft
+//Fonction setCocoInTree: crée un coconut dans un arbre
+//Les coconuts sont créés au nombre de nombreCoconuts
+//puis elles réparties aléatoirement mais équitablement dans les arbres autour des trois points de départ (XL, XC, XR) + ou - 50 pixels
+//Elles sont stockées dans le tableau coconutsInTree
+function setCocoInTree() {
+ for (var i = 0; i < nombreCoconuts; i++) {
+ var newCoconut = new Coconut();
+ // Choisir aléatoirement un point de départ
+ var randomIndex = Math.floor(Math.random() * startPoints.length);
+ var randomDeltaX = Math.floor(Math.random() * 100) - 50;
+ var randomDeltaY = Math.floor(Math.random() * 100) - 50;
+ var typeTrajectory = -1;
+ newCoconut.isFalling = false;
+ newCoconut.x = startPoints[randomIndex] + randomDeltaX;
+ newCoconut.y = monkeyLevel + randomDeltaY;
+ coconutsInTree.push(newCoconut);
+ }
+} //fin setCocoInTree
//Fonction chooseNextStartPoint: choisit aléatoirement un point de départ d'un coconut
//Renvoie un objet Coconut
function chooseNextStartPoint() {
var newCoconut = new Coconut();
// 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[1];
+ var X1 = startPoints[randomIndex];
var X2 = X1;
var Y0 = groundLevel;
var Yh = monkeyLevel;
var totalTicks = 500;
@@ -343,8 +364,9 @@
}
if (deltaZ <= parasol.width / 2) {
Xreturn = XR;
}
+ scoreTest += " Xret = " + Xreturn;
return Xreturn;
} //fin checkPosition
//Fonction zoneIntersectParasol: renvoie la zone du parasol qui intersecte le coconut (0 : zone de gauche, 1 : zone centrale de gauche, 2 : zone centrale de droite, 3 : zone de droite)
//Sachant que l'ancrage du parasol est en (0.5, 0.5) et que l'ancrage du coconut est en (0.5, 0.5)
@@ -392,11 +414,9 @@
randomIndex = Math.floor(Math.random() * 4);
}
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);
}
@@ -412,9 +432,8 @@
//vers l'extrême droite, parabole basse
coconut.trajectory.setParameters(1, coconut.x, XR - deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
}
} 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);
}
@@ -430,9 +449,8 @@
//Vers la droite, sortie d'ecran
coconut.trajectory.setParameters(1, coconut.x, XR + 2 * XL - deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
}
} 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);
}
@@ -447,10 +465,8 @@
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
@@ -465,22 +481,22 @@
if (LK.ticks % 60 == 0) {
//Afficher les coeurs
setLivesLeft();
// Créer un nouveau coco
- if (coconuts.length < nombreCoconuts) {
- var newCoconut = chooseNextStartPoint();
- game.addChild(newCoconut);
- }
+ //if (coconuts.length < nombreCoconuts) {
+ // var newCoconut = chooseNextStartPoint();
+ // game.addChild(newCoconut);
}
//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) {
+ var deltaX = Math.abs(coconuts[i].x - parasol.x);
+ var deltaY = parasol.y - coconuts[i].y;
+ var isCloseEnough = deltaY > 0 && deltaY < 150;
+ if (coconuts[i].intersects(parasol) && coconuts[i].isFalling && deltaX < parasol.width / 2 && isCloseEnough) {
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]));