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.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
};
});
/****
* 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 scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 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];
game.update = function () {
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);
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
@@ -49,8 +49,54 @@
/****
* 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());