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: 'ReferenceError: scoreText is not defined' in or related to this line: 'scoreText.setText(nouveauScore);' Line Number: 214
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'if (scoreText) {' Line Number: 169
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'scoreText.setText(nouveauScore);' Line Number: 169
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'scoreText.setText(nouveauScore);' Line Number: 172
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'scoreText.setText(nouveauScore);' Line Number: 178
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'scoreText.setText(nouveauScore);' Line Number: 173
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'scoreText.setText(nouveauScore);' Line Number: 172
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: startPoints is not defined' in or related to this line: 'var randomIndex = Math.floor(Math.random() * startPoints.length);' Line Number: 86
Code edit (1 edits merged)
Please save this source code
Initial prompt
Coco Monkey
===================================================================
--- original.js
+++ change.js
@@ -38,8 +38,51 @@
self.update = function () {
// Parasol logic can be added here
};
});
+//Class for the trajectory of the coconut
+//Gestion d'une trajectoire parabolique de sommet ((X1 + X2)/2, Yh)
+//et de point de départ (X1, Y0) et d'arrivée (X2, Y0) avec Y0 > Yh et X1 < X2.
+//la fonction de mise à jour calcule la position du point suivant en fonction de speed .
+//Sachant que speed correspond à un certain nombre de ticks avant le calcul de la position suivante.
+//L'equation de la trajectoire est de la forme y = a(x - X1)(x - X2) + Yh
+var Trajectory = Container.expand(function () {
+ var self = Container.call(this);
+ var trajectoryGraphics = self.attachAsset('trajectory', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.X1 = 0;
+ self.X2 = 0;
+ self.Y0 = 0;
+ self.Yh = 0;
+ self.xCurrent = 0;
+ self.yCurrent = 0;
+ self.speed = 1;
+ self.isStarted = false; //Indique si la trajectoire a commencé
+ self.setParameters = function (X1, X2, Y0, Yh, speed) {
+ self.X1 = X1;
+ self.X2 = X2;
+ self.Y0 = Y0;
+ self.Yh = Yh;
+ self.speed = speed;
+ self.a = (Y0 - Yh) / ((X1 - X2) * (X1 - X2));
+ }; //fin setParameters
+ self.update = function () {
+ // Trajectory logic can be added here
+ if (!self.isStarted) {
+ self.xCurrent = self.X1;
+ self.yCurrent = self.Y0;
+ self.isStarted = true;
+ var distance_per_tick = (self.X2 - self.X1) / self.speed;
+ } else {
+ if (self.xCurrent < self.X2) {
+ self.xCurrent += distance_per_tick;
+ self.yCurrent = self.a * (self.xCurrent - self.X1) * (self.xCurrent - self.X2) + self.Yh;
+ }
+ }
+ }; //fin update
+});
/****
* Initialize Game
****/
@@ -137,11 +180,12 @@
});
LK.gui.topLeft.addChild(scoreTestText);
var scoreTxt = new Text2('0', {
size: 150,
- fill: "#ffffff"
+ fill: "#ffffff",
+ anchorX: 0.5,
+ anchorY: 0
});
-scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
game.down = function (x, y, obj) {
parasol.x = x;
parasol.y = y;
@@ -158,30 +202,33 @@
function updateScoreTest(nouveauScore) {
scoreTestText.setText(nouveauScore);
} //fin updateScoreTest
function updateScore(nouveauScore) {
- if (nouveauScore < 0) {
- nouveauScore = 0;
- score = 0;
- }
- scoreText.setText(nouveauScore);
+ scoreTxt.setText(nouveauScore);
} //fin updateScore
+//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);
+ newCoconut.x = startPoints[randomIndex];
+ newCoconut.y = monkey.y;
+ coconuts.push(newCoconut);
+ return newCoconut;
+} //fin chooseNextStartPoint
/****
* Main loop
****/
game.update = function () {
//Mise à jour score
scoreTest = score;
updateScoreTest(scoreTest);
- //updateScore(score);
+ updateScore(score);
//Autres actions à effectuer sans urgence
if (LK.ticks % 60 == 0) {
- var newCoconut = new Coconut();
- // Choisir aléatoirement un point de départ
- var randomIndex = Math.floor(Math.random() * startPoints.length);
- newCoconut.x = startPoints[randomIndex];
- newCoconut.y = monkey.y;
- coconuts.push(newCoconut);
+ // Créer un nouveau coco
+ var newCoconut = chooseNextStartPoint();
game.addChild(newCoconut);
}
for (var i = coconuts.length - 1; i >= 0; i--) {
if (coconuts[i].intersects(parasol)) {