Code edit (1 edits merged)
Please save this source code
Code edit (16 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: livesLeftGraphics[i] is undefined' in or related to this line: 'livesLeftGraphics[i].destroy();' Line Number: 264
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Sprite is not a constructor' in or related to this line: 'var newLife = new Sprite('life');' Line Number: 267
Code edit (12 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: scor is not defined' in or related to this line: 'scor += 1;' Line Number: 120
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: OptionsZone is undefined' in or related to this line: 'parasol.y = OptionsZone.y - 400;' Line Number: 189
Code edit (1 edits merged)
Please save this source code
Code edit (23 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: abs is not defined' in or related to this line: 'var deltaX = abs(coconuts[i].x - coconuts[i].X1);' Line Number: 307
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 (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
/****
* 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 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
});
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];
/****
* Functions
****/
function updateScoreTest(nouveauScore) {
scoreTestText.setText(nouveauScore);
} //fin updateScoreTest
function updateScore(nouveauScore) {
if (nouveauScore < 0) {
nouveauScore = 0;
score = 0;
}
scoreText.setText(nouveauScore);
} //fin updateScore
/****
* Main loop
****/
game.update = function () {
//Mise à jour score
//updateScoreTest(scoreTest);
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);
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();
}
}
};