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
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'if (scoreText) {' Line Number: 169
===================================================================
--- 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 > 2732) {
+ if (self.y > groundLevel) {
self.destroy();
}
}; //fin update
});
@@ -196,8 +196,9 @@
y: game.height - ScoreZone.height,
width: game.width,
height: 200 * game.height / 2732
};
+setBackGroundImage('backGroundBeach', 0, 0, game.width, game.height);
/****
* Autres
****/
var monkey = game.addChild(new Monkey());
@@ -214,8 +215,10 @@
var nbTicksTobounceLow = 500;
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;
/****
* Score
****/
var livesLeft = 3; //Nombre de vies restantes
@@ -235,19 +238,27 @@
});
LK.gui.top.addChild(scoreTxt);
game.down = function (x, y, obj) {
parasol.x = x;
- //parasol.y = y;
- parasol.y = OptionsZone.y - 400;
+ parasol.y = parasolLevel;
};
game.move = function (x, y, obj) {
parasol.x = x;
- //parasol.y = y;
- parasol.y = OptionsZone.y - 400;
+ parasol.y = parasolLevel;
};
/****
* Functions
****/
+//Fonction setBackGroundImage : permet de définir l'image de fond du jeu
+function setBackGroundImage(image, x, y, width, height) {
+ backGroundImage = LK.getAsset(image, {
+ x: x,
+ y: y,
+ width: width,
+ height: height
+ });
+ game.addChild(backGroundImage);
+} //Fin de la fonction setBackGroundImage
function updateScoreTest(nouveauScore) {
scoreTestText.setText(nouveauScore);
} //fin updateScoreTest
function updateScore(nouveauScore) {
@@ -317,25 +328,34 @@
Xreturn = XR;
}
return Xreturn;
} //fin checkPosition
-//Fonction zoneIntersectParasol: renvoie la zone du parasol qui intersecte le coconut (PL=parasol.width/3, PC=2*PL, PR=3*PL)
+//Fonction zoneIntersectParasol: renvoie la zone du parasol qui intersecte le coconut (0 : zone de gauche, 1 : zone centrale de gauche, 2 : zone centrale de droite, 3 : zone de droite)
//Sachant que l'ancrage du parasol est en (0.5, 0.5) et que l'ancrage du coconut est en (0.5, 0.5)
-function zoneIntersectParasol(coconut, parasol) {
+//La zone 0 est la zone de gauche, la zone 1 est la zone centrale, la zone 2 est la zone de droite
+function zoneIntersectParasol(coconut) {
var zone = -1;
+ var oneThirdParasol = parasol.width / 3;
var parasolCenter = parasol.x;
var coconutCenter = coconut.x;
- var deltaX = Math.abs(parasolCenter - coconutCenter);
- if (deltaX <= parasol.width / 3) {
+ var deltaXToCenter = parasolCenter - coconutCenter; //distance du centre du coconut par rapport au centre du parasol (positif si à gauche, négatif si à droite)
+ if (deltaXToCenter > oneThirdParasol / 2) {
+ //La coco se trouve dans la zone gauche au delà du tiers gauche
zone = 0;
}
- if (deltaX > parasol.width / 3 && deltaX <= 2 * parasol.width / 3) {
+ if (deltaXToCenter <= oneThirdParasol / 2 && deltaXToCenter >= 0) {
+ //La coco se trouve dans la zone gauche entre le tiers gauche et le centre du parasol
zone = 1;
}
- if (deltaX > 2 * parasol.width / 3) {
+ if (deltaXToCenter >= -oneThirdParasol / 2 && deltaXToCenter <= 0) {
+ //La coco se trouve dans la zone droite entre le centre du parasol et le tiers droit
zone = 2;
}
- scoreTest = "deltaX = " + deltaX + " zone = " + zone;
+ 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 :
@@ -350,37 +370,43 @@
//Si la position du parasol est en XR le coconut rebondit aléatoirement :
// - 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) {
- var randomIndex = Math.floor(Math.random() * 3);
+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, sommetParaboleHaute, nbTicksToBounceHight);
+ coconut.trajectory.setParameters(1, coconut.x, -XL - deltaX, coconut.y, sommetParaboleBasse, nbTicksToBounceHight);
}
if (randomIndex == 1) {
+ //vers la gauche, sortie de l'écran
+ coconut.trajectory.setParameters(1, coconut.x, -XL - deltaX, coconut.y, sommetParaboleHaute, nbTicksToBounceHight);
+ }
+ if (randomIndex == 2) {
//vers le centre, parabole haute
coconut.trajectory.setParameters(1, coconut.x, XC - deltaX, coconut.y, sommetParaboleHaute, nbTicksToBounceHight);
}
- if (randomIndex == 2) {
+ if (randomIndex == 3) {
//vers l'extrême droite, parabole basse
coconut.trajectory.setParameters(1, coconut.x, XR - deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
}
}
if (Xposition == XC) {
- //randomIndex = Math.floor(Math.random() * 4);
- randomIndex = 2;
if (randomIndex == 0) {
- //vers la gauche, parabole haute
- coconut.trajectory.setParameters(1, coconut.x, XL + deltaX, coconut.y, sommetParaboleHaute, nbTicksToBounceHight);
- }
- if (randomIndex == 1) {
//vers la gauche, sortie d'ecran
coconut.trajectory.setParameters(1, coconut.x, -XL + deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
}
+ if (randomIndex == 1) {
+ //vers la gauche, parabole haute
+ coconut.trajectory.setParameters(1, coconut.x, XL + deltaX, coconut.y, sommetParaboleHaute, nbTicksToBounceHight);
+ }
if (randomIndex == 2) {
//Vers la droite, parabole haute
coconut.trajectory.setParameters(1, coconut.x, XR - deltaX, coconut.y, sommetParaboleHaute, nbTicksToBounceHight);
}
@@ -390,20 +416,23 @@
}
}
if (Xposition == XR) {
if (randomIndex == 0) {
- //vers la droite, sortie de l'écran
- coconut.trajectory.setParameters(1, coconut.x, XR + 2 * XL - deltaX, coconut.y, sommetParaboleHaute, nbTicksToBounceHight);
+ //vers l'extrême gauche, parabole basse
+ coconut.trajectory.setParameters(1, coconut.x, XL + deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
}
if (randomIndex == 1) {
//vers le centre, parabole haute
coconut.trajectory.setParameters(1, coconut.x, XC + deltaX, coconut.y, sommetParaboleHaute, nbTicksToBounceHight);
}
- //beta.frvr.ai/creator/P1fQaUz3am#
- https: if (randomIndex == 2) {
- //vers l'extrême gauche, parabole basse
- coconut.trajectory.setParameters(1, coconut.x, XL + deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
+ if (randomIndex == 2) {
+ //vers la droite, sortie de l'écran
+ coconut.trajectory.setParameters(1, coconut.x, XR + 2 * XL - deltaX, coconut.y, sommetParaboleHaute, nbTicksToBounceHight);
}
+ if (randomIndex == 3) {
+ //vers l'extrême gauche, parabole haute
+ coconut.trajectory.setParameters(1, coconut.x, XR + 2 * XL - deltaX, coconut.y, sommetParaboleBasse, nbTicksTobounceLow);
+ }
}
} //fin changeTrajectory
/****
* Main loop
@@ -425,14 +454,12 @@
}
//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) {
- zoneIntersectParasol(coconuts[i]);
score += 1;
coconuts[i].isFalling = false;
var deltaX = Math.abs(coconuts[i].x - XL);
- //coconuts[i].trajectory.setParameters(1, coconuts[i].x, XC - deltaX, coconuts[i].y, sommetParaboleHaute, 500);
- changeTrajectory(coconuts[i]);
+ changeTrajectory(coconuts[i], zoneIntersectParasol(coconuts[i]));
coconuts[i].isBouncing = true;
}
}
//Mise à jour des trajectoires des coconuts
@@ -440,12 +467,14 @@
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 >= OptionsZone.y && (coconuts[i].x < 0 || coconuts[i].x > game.width)) {
+ if (coconuts[i].y >= groundLevel && (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 >= OptionsZone.y && (coconuts[i].isFalling || coconuts[i].isBouncing)) {
+ } else if (coconuts[i].y >= groundLevel.y && (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;