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: nbTicksSinceEndOfWave is not defined' in or related to this line: 'nbTicksSinceEndOfWave -= 1; //On attend un peu avant de passer à la vague suivante' Line Number: 738
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 (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
===================================================================
--- original.js
+++ change.js
@@ -53,19 +53,8 @@
self.isGoingToRight = false;
self.isGoingToLeft = false;
self.isMoving = false;
self.coconutChoosen = null;
- //Function setMoveToGoalPosition : initialise les paramètres pour se déplacer à la position d'arrivée
- self.setMoveToGoalPosition = function (coconut, ticksToGoToGoalPosition) {
- if (coconut == null) {
- return;
- }
- self.coconutChoosen = coconut;
- self.ticksToGoToGoalPosition = ticksToGoToGoalPosition;
- self.goalPositionIndex = checkIndexPosition(coconut);
- self.actualPositionIndex = checkIndexPosition(self);
- //scoreTest = "actualPositionIndex: " + self.actualPositionIndex + " goalPositionIndex: " + self.goalPositionIndex;
- }; //fin setMoveToGoalPosition
// Function to change the asset
self.changeAsset = function (newAssetId, options) {
// Remove the existing asset
self.removeChild(monkeyAsset);
@@ -75,57 +64,9 @@
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) {
- if (self.actualPosition < self.goalPosition) {
- self.isGoingToRight = true;
- self.isGoingToLeft = false;
- self.assetsToUse = self.assetsToRight;
- } else {
- self.isGoingToRight = false;
- self.isGoingToLeft = true;
- self.assetsToUse = self.assetsToLeft;
- }
- self.sequenceIndexToUse = Math.abs(self.actualPositionIndex - self.goalPositionIndex) == 1 ? self.sequenceIndexToCenter : self.sequenceIndexToExtreme;
- self.ticksBeforeNextPosition = self.ticksToGoToGoalPosition / self.sequenceIndexToUse.length;
- self.isMoving = true;
- self.ticksBeforeNextPosition = self.ticksToGoToGoalPosition / self.sequenceIndexToUse.length;
- 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.sequenceIndex += 1;
- } else {
- self.ticksBeforeNextPosition -= 1;
- }
- } else if (self.isGoingToLeft) {
- if (self.ticksBeforeNextPosition <= 0) {
- self.changeAsset(self.assetsToUse[self.sequenceIndexToUse[self.sequenceIndex]]);
- self.sequenceIndex += 1;
- } else {
- self.ticksBeforeNextPosition -= 1;
- }
- }
- }
- if (checkIndexPosition(self) == self.goalPositionIndex) {
- //Le monkey est arrivé à la position voulue, on remet les paramètres à zéro
- self.isMoving = false;
- self.actualPositionIndex = self.goalPositionIndex;
- self.isGoingToRight = false;
- self.isGoingToLeft = false;
- self.sequenceIndex = 0;
- self.assetsToUse = [];
- self.sequenceIndexToUse = [];
- if (self.coconutChoosen) {
- self.coconutChoosen.trajectory.isStarted = true; //On lache la coconut
- self.coconutChoosen = null;
- }
- }
- }; //fin update
+ self.update = function () {}; //fin update
});
// Class for the Parasol
var Parasol = Container.expand(function () {
var self = Container.call(this);
@@ -226,11 +167,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.
@@ -274,8 +212,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,
@@ -313,15 +254,16 @@
var sommetParaboleBasse = ScoreZone.height + 400;
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 nbTicksBeforeThrow = 150;
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;
+var bullesInsultes = ['heInsultes1', 'sheInsultes', 'heInsultes2'];
/****
* Init game
* ***/
setCocoInTree();
@@ -489,10 +431,10 @@
monkey.x = coconut.x;
monkey.y = coconut.y;
game.addChild(monkey);
LK.setTimeout(function () {
- //coconut.trajectory.isStarted = true;
- }, 100);
+ coconut.trajectory.isStarted = true;
+ }, 500);
} //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);
@@ -626,8 +568,34 @@
coconut.trajectory.setParameters(1, coconut.x, XR + 2 * XL - deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
}
}
} //fin changeTrajectory
+//Fonction placeInsultes: place une bulle d'insultes autour de la tete du personnage designé par l'index
+//Retire la bulle d'insultes après un certain temps
+function placeInsultes(index) {
+ var insulte = LK.getAsset(bullesInsultes[index], {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var positionsInsultes = [{
+ x: XL - 200,
+ y: groundLevel
+ }, {
+ x: XC + 30,
+ y: groundLevel
+ }, {
+ x: XR + 100,
+ y: groundLevel
+ }];
+ var posInsulte = positionsInsultes[index];
+ insulte.x = posInsulte.x;
+ insulte.y = posInsulte.y;
+ game.addChild(insulte);
+ LK.setTimeout(function () {
+ game.removeChild(insulte);
+ insulte.destroy();
+ }, 2000);
+} //fin placeInsultes
/****
* Main loop
****/
game.update = function () {
@@ -641,19 +609,28 @@
coconuts[i].destroy();
coconuts.splice(i, 1);
} else if (coconuts[i].y >= groundLevel) {
//Si le coco est tombé au sol
- if (coconuts[i].x == XC) {
+ if (checkIndexPosition(coconuts[i]) == 1) {
LK.getSound('sheOuch').play();
+ placeInsultes(1);
+ } else if (checkIndexPosition(coconuts[i]) == 2) {
+ LK.getSound('heOuch2').play();
+ placeInsultes(2);
+ } else if (checkIndexPosition(coconuts[i]) == 0) {
+ LK.getSound('heOuch1').play();
+ placeInsultes(0);
} else {
LK.effects.flashScreen(0xff0000, 1000);
}
coconuts[i].destroy();
coconuts.splice(i, 1);
livesLeft -= 1;
if (livesLeft == 0) {
setLivesLeft();
- LK.showGameOver();
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 200);
}
}
}
//Check if a coconut has touched the parasol et changement de trajectoire
@@ -681,11 +658,9 @@
// 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);
} else {
nbTicksLeftBeforeNextThrow = nbTicksBeforeThrow;
coconutChoosen = null;
}