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
@@ -13,8 +13,11 @@
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 == -1) {
+ self.trajectory.updateStatic();
+ }
if (self.trajectory.typeTrajectory == 0) {
self.trajectory.updateLinear();
}
if (self.trajectory.typeTrajectory == 1) {
@@ -85,8 +88,14 @@
self.totalTicks = totalTicks;
self.isStarted = false;
//scoreTest = "typeTrajectory: " + typeTrajectory + " X1: " + self.X1 + " X2: " + self.X2 + " Y0: " + self.Y0 + " Yh: " + self.Yh + " totalTicks: " + self.totalTicks;
}; //fin setParameters
+ self.updateStatic = function () {
+ if (self.typeTrajectory == -1) {
+ self.x = self.X1;
+ self.y = self.Y0;
+ }
+ }; //fin updateStatic
self.updateLinear = function () {
// Trajectory logic can be added here
var lastY = self.y;
if (self.typeTrajectory == 0 && !self.isStarted) {
@@ -133,8 +142,11 @@
/****
* 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.
@@ -178,11 +190,8 @@
* 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,
@@ -199,8 +208,9 @@
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;
@@ -216,18 +226,18 @@
var sommetParaboleHaute = ScoreZone.height + 200;
var sommetParaboleBasse = ScoreZone.height + 400;
var nbTicksToBounceHight = 500;
var nbTicksTobounceLow = 500;
-var nbTicksBeforeThrow = 2000;
+var nbTicksBeforeThrow = 400;
+var nbTicksLeftBeforeNextThrow = 0;
var score = 0;
var scoreTest = 0;
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
****/
@@ -316,17 +326,20 @@
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.x = 1536; //startPoints[randomIndex]; // + randomDeltaX;
- newCoconut.y = 200; //monkeyLevel; // + randomDeltaY;
- scoreTest = "x= " + newCoconut.x + " y= " + newCoconut.y;
+ //var X1 = startPoints[randomIndex] + randomDeltaX;
+ var X1 = startPoints[1];
+ var X2 = X1;
+ var Y0 = monkeyLevel + randomDeltaY;
+ var Yh = Y0;
+ var totalTicks = 0;
+ newCoconut.trajectory.setParameters(typeTrajectory, X1, X2, Y0, Yh, totalTicks);
coconutsInTree.push(newCoconut);
- game.addChild(newCoconut);
}
//Affiche les coconuts dans les arbres
for (var i = 0; i < coconutsInTree.length; i++) {
- //game.addChild(coconutsInTree[i]);
+ game.addChild(coconutsInTree[i]);
}
} //fin setCocoInTree
//Fonction chooseNextStartPoint: choisit aléatoirement un point de départ d'un coconut
//Renvoie un objet Coconut
@@ -345,8 +358,26 @@
coconuts.push(newCoconut);
moveMonkeyToStartPoint(X1, monkeyLevel);
return newCoconut;
} //fin chooseNextStartPoint
+//Fonction chooseNextCoconut: choisit aléatoirement un coconut dans les arbres
+//Renvoie un objet Coconut
+function chooseNextCoconut() {
+ var randomIndex = Math.floor(Math.random() * coconutsInTree.length);
+ var newCoconut = coconutsInTree[randomIndex];
+ coconutsInTree.splice(randomIndex, 1);
+ var typeTrajectory = 0;
+ newCoconut.isFalling = true;
+ var X1 = newCoconut.x;
+ var X2 = X1;
+ var Y0 = groundLevel;
+ var Yh = newCoconut.y;
+ var totalTicks = 500;
+ newCoconut.trajectory.setParameters(typeTrajectory, X1, X2, Y0, Yh, totalTicks);
+ coconuts.push(newCoconut);
+ moveMonkeyToStartPoint(X1, monkeyLevel);
+ return newCoconut;
+} //fin chooseNextCoconut
//Fonction moveMonkeyToStartPoint: déplace le monkey au point de départ du coconut
function moveMonkeyToStartPoint(x, y) {
//Efface le monkey de l'écran
game.removeChild(monkey);
@@ -483,12 +514,16 @@
//Autres actions à effectuer sans urgence
if (LK.ticks % 60 == 0) {
//Afficher les coeurs
setLivesLeft();
- // Créer un nouveau coco
- //if (coconuts.length < nombreCoconuts) {
- // var newCoconut = chooseNextStartPoint();
- // game.addChild(newCoconut);
+ // Récupérer un coconut dans les arbres et le faire tomber si possible
+ if (coconutsInTree.length > 0 && nbTicksLeftBeforeNextThrow <= 0) {
+ var newCoconut = chooseNextCoconut();
+ game.addChild(newCoconut);
+ nbTicksLeftBeforeNextThrow = nbTicksBeforeThrow;
+ } else {
+ nbTicksLeftBeforeNextThrow -= 60;
+ }
}
//Check if a coconut has touched the parasol et changement de trajectoire
for (var i = coconuts.length - 1; i >= 0; i--) {
var deltaX = Math.abs(coconuts[i].x - parasol.x);
@@ -507,8 +542,9 @@
}
}
//Mise à jour des trajectoires des coconuts
for (var i = coconuts.length - 1; i >= 0; i--) {
+ scoreTest = " isFalling: " + coconuts[i].isFalling + " trajectory: " + coconuts[i].trajectory.typeTrajectory;
coconuts[i].update();
}
//Vérifier si un coco a touché le sol
for (var i = coconuts.length - 1; i >= 0; i--) {