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
/**** * Classes ****/ // Class for the Coconut var Coconut = Container.expand(function () { var self = Container.call(this); var coconutGraphics = self.attachAsset('coconut', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.trajectory = new Trajectory(); self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> // Class for the Monkey var Monkey = Container.expand(function () { var self = Container.call(this); var monkeyGraphics = self.attachAsset('monkey', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Monkey logic can be added here }; }); // Class for the Parasol var Parasol = Container.expand(function () { var self = Container.call(this); var parasolGraphics = self.attachAsset('parasol', { anchorX: 0.5, anchorY: 0.5 }); 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 ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ /**** * 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. * -Above them, three palm trees are growing coconuts. * -In the trees, a monkey is throwing coconuts from the top of the trees, thus three points of departure. * -The player controls a guy who holding a parasol to protect everyone from the coconuts. * -The coconuts are falling at a regular speed, falling in straight lines. * -If a coconut touches the parasol, the player earns points. * -If a coconut touches the ground, the player loses a life. * -The game is over when the player has no more lives. * Game Areas: * The screen is divided into 3 main zones in the following descending order: 1. Score area: displays the player's score. 2. The main game area: where the game takes place, it is divided into 3 zones corresponding to the 3 points of departure of the coconuts : * The left zone: the coconuts fall from the left tree. * The center zone: the coconuts fall from the center tree. * The right zone: the coconuts fall from the right tree. 3. Options area (or advertisement). * Game Progression: * At the beginning of the game, the player has 0 points. * The player has 3 lives. * The player can move the parasol by dragging it. * The monkey throws coconuts at a regular interval randomly from the top of the trees. * When a coconut touches the parasol, it bounces up following a parabolic trajectory. * The parabolic trajectory depends on the angle of the parasol: * The more the parasol is inclined, the more the coconut will bounce back : * If the parasol is in the left zone, the coconut may bounce following a parabolic trajectory : * to the left, thus outside the screen. * to the right, thus towards the center zone. * to the extrem right, thus towards the right zone. * If the parasol is in the center zone, the coconut may bounce following a parabolic trajectory : * to the left, thus towards the left zone. * to the extrem left, thus outside the screen. * to the right, thus towards the right zone. * to the extrem right, thus outside the screen. * If the parasol is in the right zone, the coconut may bounce following a parabolic trajectory : * to the left, thus towards the center zone. * to the extrem left, thus towards the left zone. * to the right, thus outside the screen. * the parasol has three zones of influence: * 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. ****/ var monkey = game.addChild(new Monkey()); monkey.x = 2048 / 2; monkey.y = 200; var parasol = game.addChild(new Parasol()); parasol.x = 2048 / 2; parasol.y = 2500; var coconuts = []; var score = 0; var scoreTest = 0; /**** * Game zones and backgrounds ****/ var ScoreZone = { x: 0, y: 0, width: game.width, height: 200 * game.height / 2732 }; var MainZone = { x: 0, y: ScoreZone.height, width: game.width, height: game.height - 2 * ScoreZone.height }; var OptionsZone = { x: 0, y: game.height - ScoreZone.height, width: game.width, height: 200 * game.height / 2732 }; /**** * Score ****/ var scoreTestText = new Text2('0', { size: 30, fill: "#000000", anchorX: 0.5, anchorY: 0 }); LK.gui.topLeft.addChild(scoreTestText); var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff", anchorX: 0.5, anchorY: 0 }); LK.gui.top.addChild(scoreTxt); game.down = function (x, y, obj) { parasol.x = x; parasol.y = y; }; game.move = function (x, y, obj) { parasol.x = x; parasol.y = y; }; // Define the startPoints array var startPoints = [2048 / 4, 2048 / 2, 2048 / 4 * 3]; /**** * Functions ****/ function updateScoreTest(nouveauScore) { scoreTestText.setText(nouveauScore); } //fin updateScoreTest function updateScore(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); //Autres actions à effectuer sans urgence if (LK.ticks % 60 == 0) { // 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)) { score += 1; //scoreTxt.setText(score); coconuts[i].destroy(); coconuts.splice(i, 1); } else if (coconuts[i].y > 2732) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } };
===================================================================
--- original.js
+++ change.js
@@ -8,8 +8,9 @@
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
+ self.trajectory = new Trajectory();
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();