Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -34,10 +34,9 @@
//<Assets used in the game will automatically appear here>
// Class for the Monkey
var Monkey = Container.expand(function () {
var self = Container.call(this);
- var monkeyAsset;
- monkeyAsset = self.attachAsset('monkeyToLeft', {
+ var monkeyAsset = self.attachAsset('monkeyToLeft', {
anchorX: 0.5,
anchorY: 0.5
});
self.assetsToRight = ['monkeyToRight', 'monkeyInterRight'];
@@ -71,14 +70,12 @@
// Remove the existing asset
self.removeChild(monkeyAsset);
monkeyAsset.destroy();
// Attach the new asset
- if (self.assetsToUse.length > 0) {
- monkeyAsset = self.attachAsset(newAssetId, {
- anchorX: options && options.anchorX !== undefined ? options.anchorX : 0.5,
- anchorY: options && options.anchorY !== undefined ? options.anchorY : 0.5
- });
- }
+ monkeyAsset = self.attachAsset(newAssetId, {
+ anchorX: options && options.anchorX !== undefined ? options.anchorX : 0.5,
+ anchorY: options && options.anchorY !== undefined ? options.anchorY : 0.5
+ });
};
self.update = function () {
//scoreTest = "actualPositionIndex: " + self.actualPositionIndex + " goalPositionIndex: " + self.goalPositionIndex + " isMoving: " + self.isMoving;
if (!self.isMoving && self.actualPositionIndex != self.goalPositionIndex) {
@@ -98,24 +95,16 @@
scoreTest = "actualPIx: " + self.actualPositionIndex + " goalPIx: " + self.goalPositionIndex + " assetsToUse: " + self.assetsToUse + " seqIxToUse: " + self.sequenceIndexToUse + "\nticksBeforeNextPosition: " + self.ticksBeforeNextPosition;
} else if (self.isMoving) {
if (self.isGoingToRight) {
if (self.ticksBeforeNextPosition <= 0) {
- //self.changeAsset(self.assetsToUse[self.sequenceIndexToUse[self.sequenceIndex]]);
- self.changeAsset('monkeyToRight', {
- anchorX: 0.91,
- anchorY: 0.11
- });
+ self.changeAsset(self.assetsToUse[self.sequenceIndexToUse[self.sequenceIndex]]);
self.sequenceIndex += 1;
} else {
self.ticksBeforeNextPosition -= 1;
}
} else if (self.isGoingToLeft) {
if (self.ticksBeforeNextPosition <= 0) {
- //self.changeAsset(self.assetsToUse[self.sequenceIndexToUse[self.sequenceIndex]]);
- self.changeAsset('monkeyToLeft', {
- anchorX: 0.09,
- anchorY: 0.11
- });
+ self.changeAsset(self.assetsToUse[self.sequenceIndexToUse[self.sequenceIndex]]);
self.sequenceIndex += 1;
} else {
self.ticksBeforeNextPosition -= 1;
}
@@ -461,9 +450,9 @@
function chooseNextCoconut() {
var randomIndex = Math.floor(Math.random() * coconutsInTree.length);
var newCoconut = coconutsInTree[randomIndex];
coconutsInTree.splice(randomIndex, 1);
- //moveMonkeyToCoconut(newCoconut);
+ moveMonkeyToCoconut(newCoconut);
var typeTrajectory = 0; //Trajectoire linéaire
var X1 = newCoconut.x;
var X2 = X1;
var Y0 = groundLevel;
@@ -475,14 +464,22 @@
//Fonction moveMoveMonkeyToCoconut: déplace le monkey au point de depart du coconut
function moveMonkeyToCoconut(coconut) {
//Efface le monkey de l'écran
game.removeChild(monkey);
- if (monkey.x < coconut.x) {
+ var deltaIndex = checkIndexPosition(monkey) - checkIndexPosition(coconut);
+ if (deltaIndex < 0) {
//Le monkey est à gauche du coconut
monkey.changeAsset('monkeyToRight', {
anchorX: 0.91,
anchorY: 0.11
});
+ if (deltaIndex > -1) {
+ //Le monkey est à gauche du coconut mais pas trop
+ monkey.changeAsset('monkeyInterRight', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ }
} else {
//Le monkey est à droite du coconut
monkey.changeAsset('monkeyToLeft', {
anchorX: 0.09,
@@ -490,10 +487,12 @@
});
}
monkey.x = coconut.x;
monkey.y = coconut.y;
- coconut.trajectory.isStarted = true;
game.addChild(monkey);
+ LK.setTimeout(function () {
+ //coconut.trajectory.isStarted = true;
+ }, 100);
} //fin moveMonkeyToCoconut
//Fonction checkPosition : donne la position XL, XC, ou XR la plus proche de la position x du parasol
function checkPosition(parasol) {
var deltaX = Math.abs(parasol.x - XL);
@@ -682,11 +681,11 @@
// Récupérer un coconut dans les arbres et le faire tomber si l'heure est venue
if (coconutsInTree.length > 0 && nbTicksLeftBeforeNextThrow <= 0) {
if (coconutChoosen == null) {
coconutChoosen = chooseNextCoconut();
- //coconutChoosen.trajectory.isStarted = true;
- //game.addChild(coconutChoosen);
- monkey.setMoveToGoalPosition(coconutChoosen, nbTicksBeforeThrow);
+ coconutChoosen.trajectory.isStarted = true;
+ game.addChild(coconutChoosen);
+ //monkey.setMoveToGoalPosition(coconutChoosen, nbTicksBeforeThrow);
} else {
nbTicksLeftBeforeNextThrow = nbTicksBeforeThrow;
coconutChoosen = null;
}