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 (19 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: coconut is not defined' in or related to this line: 'scoreTest = "Zone contact = " + zoneIntersectParasol(coconut[i]);' Line Number: 434
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -20,9 +20,9 @@
}
self.y = self.trajectory.y;
self.x = self.trajectory.x;
self.isFalling = self.trajectory.isFalling;
- if (self.y > groundLevel) {
+ if (self.y > 2732) {
self.destroy();
}
}; //fin update
});
@@ -94,8 +94,9 @@
self.isStarted = true;
} else {
if (self.y < self.Y0) {
self.y += distPerTick;
+ //scoreTest = "x= " + self.x + " y= " + self.y + " distPerTick= " + self.distPerTick;
}
}
self.isFalling = lastY < self.y;
}; //fin updateLinear
@@ -130,8 +131,11 @@
/****
* 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.
@@ -175,11 +179,8 @@
* 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,
@@ -200,11 +201,12 @@
setBackGroundImage('backGroundBeach', 0, 0, game.width, game.height);
/****
* Autres
****/
+var monkeyLevel = 200;
var monkey = game.addChild(new Monkey());
monkey.x = 2048 / 2;
-monkey.y = 200;
+monkey.y = monkeyLevel;
var parasol = game.addChild(new Parasol());
parasol.x = 2048 / 2;
parasol.y = OptionsZone.y - 400;
var coconuts = [];
@@ -212,28 +214,29 @@
var sommetParaboleHaute = ScoreZone.height + 200;
var sommetParaboleBasse = ScoreZone.height + 400;
var nbTicksToBounceHight = 500;
var nbTicksTobounceLow = 500;
+var nbTicksBeforeThrow = 2000;
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 - 500;
-var groundLevel = OptionsZone.y - 200;
+var parasolLevel = OptionsZone.y - 600;
+var groundLevel = OptionsZone.y - 300;
/****
* Score
****/
var livesLeft = 3; //Nombre de vies restantes
var livesLeftGraphics = []; //Tableau des sprites 'life' représentant les vies restantes
var scoreTestText = new Text2('0', {
size: 30,
- fill: "#000000",
+ fill: "#FFFFFF",
anchorX: 0.5,
anchorY: 0
});
LK.gui.topLeft.addChild(scoreTestText);
var scoreTxt = new Text2('0', {
size: 150,
- fill: "#ffffff",
+ fill: "#ff0000",
anchorX: 0.5,
anchorY: 0
});
LK.gui.top.addChild(scoreTxt);
@@ -304,15 +307,26 @@
var typeTrajectory = 0;
newCoconut.isFalling = true;
var X1 = startPoints[randomIndex];
var X2 = X1;
- var Y0 = OptionsZone.y;
- var Yh = monkey.y;
+ var Y0 = groundLevel;
+ var Yh = monkeyLevel;
var totalTicks = 500;
newCoconut.trajectory.setParameters(typeTrajectory, X1, X2, Y0, Yh, totalTicks);
coconuts.push(newCoconut);
+ scoreTest = "New coconut: (" + monkey.x + ", " + monkey.y + ")";
+ moveMonkeyToStartPoint(X1, monkeyLevel);
return newCoconut;
} //fin chooseNextStartPoint
+//Fonction moveMonkeyToStartPoint: déplace le monkey au point de départ du coconut
+function moveMonkeyToStartPoint(x, y) {
+ //Efface le monkey de l'écran
+ game.removeChild(monkey);
+ monkey.x = x;
+ monkey.y = y;
+ scoreTest = "New monkey: (" + monkey.x + ", " + monkey.y + ")";
+ //game.addChild(monkey);
+} //fin moveMonkeyToStartPoint
//Fonction checkPosition : donne la position XL, XC, ou XR la plus proche de la position x du parasol
function checkPosition(x) {
var deltaX = Math.abs(x - XL);
var deltaY = Math.abs(x - XC);
@@ -353,9 +367,8 @@
if (deltaXToCenter < -oneThirdParasol / 2) {
//La coco se trouve dans la zone droite au delà du tiers droit
zone = 3;
}
- scoreTest = "deltaXToCenter = " + deltaXToCenter + " zone = " + zone;
return zone;
} //fin zoneIntersectParasol
//Fonction changeTrajectory: change la trajectoire d'un coconut en fonction de la position du parasol en XL, XC ou XR (position de startPoints)
//Si la position du parasol est en XL le coconut rebondit aléatoirement :
@@ -371,15 +384,13 @@
// - vers la droite, donc vers l'extérieur de l'écran
// - vers la gauche, donc vers la zone centrale avec une parabole de somment sommetParaboleHaute
// - vers l'extrême gauche, donc vers la zone de gauche avec une parabole de somment sommetParaboleBasse
function changeTrajectory(coconut, randomIndex) {
- scoreTest = "RandomIndex = " + randomIndex;
if (randomIndex != 0 && randomIndex != 1 && randomIndex != 2 && randomIndex != 3) {
randomIndex = Math.floor(Math.random() * 4);
}
var Xposition = checkPosition(parasol.x);
var deltaX = Math.abs(coconut.x - Xposition);
- scoreTest += " ramdom: " + randomIndex;
if (Xposition == XL) {
if (randomIndex == 0) {
//vers la gauche, sortie de l'écran
coconut.trajectory.setParameters(1, coconut.x, -XL - deltaX, coconut.y, sommetParaboleBasse, nbTicksToBounceHight);
@@ -454,9 +465,9 @@
}
//Check if a coconut has touched the parasol et changement de trajectoire
for (var i = coconuts.length - 1; i >= 0; i--) {
if (coconuts[i].intersects(parasol) && coconuts[i].isFalling) {
- score += 1;
+ score += 10;
coconuts[i].isFalling = false;
var deltaX = Math.abs(coconuts[i].x - XL);
changeTrajectory(coconuts[i], zoneIntersectParasol(coconuts[i]));
coconuts[i].isBouncing = true;
@@ -467,19 +478,20 @@
coconuts[i].update();
}
//Vérifier si un coco a touché le sol
for (var i = coconuts.length - 1; i >= 0; i--) {
- if (coconuts[i].y >= groundLevel && (coconuts[i].x < 0 || coconuts[i].x > game.width)) {
+ if (coconuts[i].y >= groundLevel / 2 && (coconuts[i].x < 0 || coconuts[i].x > game.width)) {
//Si le coco est sorti de l'écran sur les côtés
coconuts[i].destroy();
coconuts.splice(i, 1);
- } else if (coconuts[i].y >= groundLevel.y && (coconuts[i].isFalling || coconuts[i].isBouncing)) {
+ } else if (coconuts[i].y >= groundLevel && (coconuts[i].isFalling || coconuts[i].isBouncing)) {
//Si le coco est tombé au sol
LK.effects.flashScreen(0xff0000, 1000);
coconuts[i].destroy();
coconuts.splice(i, 1);
livesLeft -= 1;
if (livesLeft == 0) {
+ setLivesLeft();
LK.showGameOver();
}
}
}