Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 95
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 95
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: ticksBeforeNextPosition is not defined' in or related to this line: 'scoreTest = "actualPIx: " + self.actualPositionIndex + " goalPIx: " + self.goalPositionIndex + " assetsToUse: " + self.assetsToUse + " seqIxToUse: " + self.sequenceIndexToUse + "\nticksBeforeNextPosition: " + ticksBeforeNextPosition;' Line Number: 114
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 96
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 96
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 96
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 96
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 94
Code edit (13 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'trajectory')' in or related to this line: 'coconutChoosen.trajectory.isStarted = true;' Line Number: 138
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -38,8 +38,18 @@
var monkeyAsset = self.attachAsset('monkeyToLeft', {
anchorX: 0.5,
anchorY: 0.5
});
+ self.assetSequenceToRight = ['monkeyToRight', 'monkeyInterRight', 'monkeyToRight', 'monkeyInterRight', 'monkeyToRight'];
+ self.assetSequenceToLeft = ['monkeyToLeft', 'monkeyInterLeft', 'monkeyToLeft', 'monkeyInterLeft', 'monkeyToLeft'];
+ self.assetSequenceToUse = [];
+ self.assetSequenceActualPosition = 0;
+ self.assetSequenceGoalPosition = 0;
+ self.ticksToGoToGoalPosition = 0;
+ self.ticksBeforeNextPosition = 0;
+ self.isGoingToRight = false;
+ self.isGoingToLeft = false;
+ self.isMoving = false;
// Function to change the asset
self.changeAsset = function (newAssetId, options) {
// Remove the existing asset
self.removeChild(monkeyAsset);
@@ -50,10 +60,43 @@
anchorY: options && options.anchorY !== undefined ? options.anchorY : 0.5
});
};
self.update = function () {
- // Monkey logic can be added here
- };
+ if (!self.isMoving && self.assetSequenceActualPosition != self.assetSequenceGoalPosition) {
+ if (self.assetSequenceActualPosition < self.assetSequenceGoalPosition) {
+ self.isGoingToRight = true;
+ self.isGoingToLeft = false;
+ self.assetSequenceToUse = self.assetSequenceToRight;
+ self.ticksBeforeNextPosition = self.ticksToGoToGoalPosition / (self.assetSequenceGoalPosition - self.assetSequenceActualPosition);
+ } else {
+ self.isGoingToRight = false;
+ self.isGoingToLeft = true;
+ self.assetSequenceToUse = self.assetSequenceToLeft;
+ self.ticksBeforeNextPosition = self.ticksToGoToGoalPosition / (self.assetSequenceActualPosition - self.assetSequenceGoalPosition);
+ }
+ self.isMoving = true;
+ } else if (self.isMoving) {
+ if (self.isGoingToRight) {
+ if (self.ticksBeforeNextPosition <= 0) {
+ self.assetSequenceActualPosition += 1;
+ self.changeAsset(self.assetSequenceToUse[self.assetSequenceActualPosition]);
+ } else {
+ self.ticksBeforeNextPosition -= 1;
+ }
+ } else if (self.isGoingToLeft) {
+ if (self.ticksBeforeNextPosition <= 0) {
+ self.assetSequenceActualPosition -= 1;
+ self.changeAsset(self.assetSequenceToUse[self.assetSequenceActualPosition]);
+ } else {
+ self.ticksBeforeNextPosition -= 1;
+ }
+ }
+ }
+ if (self.assetSequenceActualPosition == self.assetSequenceGoalPosition) {
+ //Le monkey est arrivé à la position voulue
+ self.isMoving = false;
+ }
+ }; //fin update
});
// Class for the Parasol
var Parasol = Container.expand(function () {
var self = Container.call(this);
@@ -235,12 +278,14 @@
parasol.y = OptionsZone.y - 400;
var coconutsInTree = []; //Tableau des coconuts dans les arbres
var coconuts = []; //Tableau des coconuts en mouvement
var nombreCoconuts = 15; //Nombre de coconuts en mouvement en même temps
+var coconutChoosen = null; //Coconut choisie pour tomber
var sommetParaboleHaute = ScoreZone.height + 200;
var sommetParaboleBasse = ScoreZone.height + 400;
-var nbTicksToBounceHight = 500;
-var nbTicksTobounceLow = 500;
+var nbTicksToBounceHight = 230; //Nombre de ticks pour effectuer une parabole haute
+var nbTicksTobounceLow = 220; //Nombre de ticks pour effectuer une parabole basse
+var nbTicksToFall = 200; //Nombre de ticks pour tomber
var nbTicksBeforeThrow = 200;
var nbTicksLeftBeforeNextThrow = 0;
var score = 0;
var scoreTest = 0;
@@ -365,10 +410,9 @@
var X1 = startPoints[randomIndex];
var X2 = X1;
var Y0 = groundLevel;
var Yh = monkeyLevel;
- var totalTicks = 500;
- newCoconut.trajectory.setParameters(typeTrajectory, X1, X2, Y0, Yh, totalTicks);
+ newCoconut.trajectory.setParameters(typeTrajectory, X1, X2, Y0, Yh, nbTicksToFall);
coconuts.push(newCoconut);
moveMonkeyToStartPoint(X1, monkeyLevel);
return newCoconut;
} //fin chooseNextStartPoint
@@ -379,15 +423,13 @@
var newCoconut = coconutsInTree[randomIndex];
coconutsInTree.splice(randomIndex, 1);
moveMonkeyToCoconut(newCoconut);
var typeTrajectory = 0; //Trajectoire linéaire
- 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);
+ newCoconut.trajectory.setParameters(typeTrajectory, X1, X2, Y0, Yh, nbTicksToFall);
coconuts.push(newCoconut);
return newCoconut;
} //fin chooseNextCoconut
//Fonction moveMoveMonkeyToCoconut: déplace le monkey au point de depart du coconut
@@ -395,16 +437,16 @@
//Efface le monkey de l'écran
game.removeChild(monkey);
if (monkey.x < coconut.x) {
//Le monkey est à gauche du coconut
- monkey.changeAsset('monkeyToLeft', {
+ monkey.changeAsset('monkeyToRight', {
anchorX: 0.91,
anchorY: 0.11
});
} else {
//Le monkey est à droite du coconut
- monkey.changeAsset('monkeyToRight', {
- anchorX: 0.91,
+ monkey.changeAsset('monkeyToLeft', {
+ anchorX: 0.09,
anchorY: 0.11
});
}
monkey.x = coconut.x;
@@ -539,9 +581,9 @@
updateScoreTest(scoreTest);
updateScore(score);
//Mise à jour des trajectoires des coconuts
for (var i = coconuts.length - 1; i >= 0; i--) {
- coconuts[i].update();
+ //coconuts[i].update();
}
//Vérifier si un coco a touché le sol
for (var i = coconuts.length - 1; i >= 0; i--) {
if (coconuts[i].y >= groundLevel / 2 && (coconuts[i].x < 0 || coconuts[i].x > game.width)) {
@@ -549,9 +591,13 @@
coconuts[i].destroy();
coconuts.splice(i, 1);
} else if (coconuts[i].y >= groundLevel) {
//Si le coco est tombé au sol
- LK.effects.flashScreen(0xff0000, 1000);
+ if (coconuts[i].x == XC) {
+ LK.getSound('sheOuch').play();
+ } else {
+ LK.effects.flashScreen(0xff0000, 1000);
+ }
coconuts[i].destroy();
coconuts.splice(i, 1);
livesLeft -= 1;
if (livesLeft == 0) {
@@ -583,11 +629,15 @@
//Afficher les coeurs
setLivesLeft();
// Récupérer un coconut dans les arbres et le faire tomber si l'heure est venue
if (coconutsInTree.length > 0 && nbTicksLeftBeforeNextThrow <= 0) {
- var newCoconut = chooseNextCoconut();
- newCoconut.trajectory.isStarted = true;
- game.addChild(newCoconut);
+ if (coconutChoosen == null) {
+ coconutChoosen = chooseNextCoconut();
+ } else {
+ coconutChoosen.trajectory.isStarted = true;
+ game.addChild(coconutChoosen);
+ coconutChoosen = null;
+ }
nbTicksLeftBeforeNextThrow = nbTicksBeforeThrow;
} else {
nbTicksLeftBeforeNextThrow -= 60;
}