Code edit (19 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: nbTicksSinceEndOfWave is not defined' in or related to this line: 'nbTicksSinceEndOfWave -= 1; //On attend un peu avant de passer à la vague suivante' Line Number: 738
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 (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 95
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 95
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: ticksBeforeNextPosition is not defined' in or related to this line: 'scoreTest = "actualPIx: " + self.actualPositionIndex + " goalPIx: " + self.goalPositionIndex + " assetsToUse: " + self.assetsToUse + " seqIxToUse: " + self.sequenceIndexToUse + "\nticksBeforeNextPosition: " + ticksBeforeNextPosition;' Line Number: 114
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 96
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 96
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 96
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 96
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 94
Code edit (13 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'trajectory')' in or related to this line: 'coconutChoosen.trajectory.isStarted = true;' Line Number: 138
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'anchorX')' in or related to this line: 'monkeyAsset = self.attachAsset(newAssetId, {' Line Number: 69
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'anchorX')' in or related to this line: 'monkey.monkeyAsset.anchorX = 0.91;' Line Number: 421
===================================================================
--- original.js
+++ change.js
@@ -3,17 +3,28 @@
****/
// Class for the Coconut
var Coconut = Container.expand(function () {
var self = Container.call(this);
- var coconutGraphics = self.attachAsset('coconut', {
+ var coconutAsset = self.attachAsset('coconut', {
anchorX: 0.5,
anchorY: 0.5
});
self.isFalling = false;
self.isBouncing = false;
self.Xintercept = 0; //Abscisse d'interception du coconut avec le parasol
self.Yintercept = 0; //Ordonnée d'interception du coconut avec le parasol
self.trajectory = new Trajectory();
+ // Function to change the asset
+ self.changeAsset = function (newAssetId, options) {
+ // Remove the existing asset
+ self.removeChild(coconutAsset);
+ coconutAsset.destroy();
+ // Attach the new asset
+ coconutAsset = self.attachAsset(newAssetId, {
+ anchorX: options && options.anchorX !== undefined ? options.anchorX : 0.5,
+ anchorY: options && options.anchorY !== undefined ? options.anchorY : 0.5
+ });
+ }; //fin changeAsset
self.update = function () {
if (self.trajectory.typeTrajectory == -1) {
self.trajectory.updateStatic();
}
@@ -247,9 +258,9 @@
parasol.x = 2048 / 2;
parasol.y = OptionsZone.y - 400;
var coconutsInTree = []; //Tableau des coconuts dans les arbres
var coconuts = []; //Tableau des coconuts en mouvement
-var nombreCoconuts = 15; //Nombre de coconuts en mouvement en même temps
+var nombreCoconuts = 5; //Nombre de coconuts en mouvement en même temps
var coconutChoosen = null; //Coconut choisie pour tomber
var sommetParaboleHaute = ScoreZone.height + 200;
var sommetParaboleBasse = ScoreZone.height + 400;
var nbTicksToBounceHight = 230; //Nombre de ticks pour effectuer une parabole haute
@@ -257,17 +268,19 @@
var nbTicksToFall = 200; //Nombre de ticks pour tomber
var nbTicksBeforeThrow = 150;
var nbTicksLeftBeforeNextThrow = 0;
var score = 0;
+var scoreLast = score;
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 - 600;
var groundLevel = OptionsZone.y - 300;
var bullesInsultes = ['heInsultes1', 'sheInsultes', 'heInsultes2'];
+var wave = 1; //Nro de la vague
/****
* Init game
* ***/
-setCocoInTree();
+setCocoInTree(wave);
/****
* Score
****/
var livesLeft = 3; //Nombre de vies restantes
@@ -279,9 +292,9 @@
anchorY: 0
});
LK.gui.topLeft.addChild(scoreTestText);
var scoreTxt = new Text2('0', {
- size: 150,
+ size: 100,
fill: "#ff0000",
anchorX: 0.5,
anchorY: 0
});
@@ -330,12 +343,12 @@
for (var i = livesLeftGraphics.length; i < livesLeft; i++) {
var lifeGraphics = LK.getAsset('life', {
anchorX: 0.5,
anchorY: 0,
- scaleX: 1,
- scaleY: 1,
+ scaleX: 4 - livesLeft,
+ scaleY: 4 - livesLeft,
x: ScoreZone.x + 100 + 100 * i,
- y: ScoreZone.y + 100
+ y: ScoreZone.y + 50
});
livesLeftGraphics.push(lifeGraphics);
}
}
@@ -347,10 +360,10 @@
//Fonction setCocoInTree: crée un coconut dans un arbre
//Les coconuts sont créés au nombre de nombreCoconuts
//puis elles réparties aléatoirement mais équitablement dans les arbres autour des trois points de départ (XL, XC, XR) + ou - 50 pixels
//Elles sont stockées dans le tableau coconutsInTree
-function setCocoInTree() {
- for (var i = 0; i < nombreCoconuts; i++) {
+function setCocoInTree(wave) {
+ for (var i = 0; i < nombreCoconuts + wave * 5; i++) {
var newCoconut = new Coconut();
// Choisir aléatoirement un point de départ
var randomIndex = Math.floor(Math.random() * startPoints.length);
var randomDeltaX = Math.floor(Math.random() * 100) - 50;
@@ -363,8 +376,12 @@
var Yh = Y0;
var totalTicks = 0;
newCoconut.trajectory.setParameters(typeTrajectory, X1, X2, Y0, Yh, totalTicks);
coconutsInTree.push(newCoconut);
+ nbTicksBeforeThrow /= wave; //Diminue le nombre de ticks avant le prochain lancer
+ LK.getSound('monkeySquirk').play();
+ LK.getSound('boomBoom').play();
+ LK.getSound('boomBoom').play();
}
//Affiche les coconuts dans les arbres
for (var i = 0; i < coconutsInTree.length; i++) {
game.addChild(coconutsInTree[i]);
@@ -457,15 +474,15 @@
var deltaX = Math.abs(obj.x - XL);
var deltaY = Math.abs(obj.x - XC);
var deltaZ = Math.abs(obj.x - XR);
var Xreturn = -1;
- if (deltaX <= obj.width / 2) {
+ if (deltaX <= obj.width) {
Xreturn = 0;
}
- if (deltaY <= obj.width / 2) {
+ if (deltaY <= obj.width) {
Xreturn = 1;
}
- if (deltaZ <= obj.width / 2) {
+ if (deltaZ <= obj.width) {
Xreturn = 2;
}
return Xreturn;
} //fin checkIndexPosition
@@ -576,16 +593,16 @@
anchorX: 0.5,
anchorY: 0.5
});
var positionsInsultes = [{
- x: XL - 200,
- y: groundLevel
+ x: XL - 300,
+ y: groundLevel - 30
}, {
- x: XC + 30,
+ x: XC + 50,
y: groundLevel
}, {
- x: XR + 100,
- y: groundLevel
+ x: XR + 250,
+ y: groundLevel - 20
}];
var posInsulte = positionsInsultes[index];
insulte.x = posInsulte.x;
insulte.y = posInsulte.y;
@@ -594,8 +611,18 @@
game.removeChild(insulte);
insulte.destroy();
}, 2000);
} //fin placeInsultes
+//Fonction letShout: fait crier le personnage designé par l'index de la position
+function letShoutNInsultes(index) {
+ if (index != 0 && index != 1 && index != 2) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ }
+ var shouts = ['heShout1', 'sheShout', 'heShout2'];
+ var shout = shouts[index];
+ LK.getSound(shout).play();
+ placeInsultes(index);
+} //fin letShoutNInsultes
/****
* Main loop
****/
game.update = function () {
@@ -609,8 +636,9 @@
coconuts[i].destroy();
coconuts.splice(i, 1);
} else if (coconuts[i].y >= groundLevel) {
//Si le coco est tombé au sol
+ //letShoutNInsultes(checkIndexPosition(coconuts[i])); //Bug : sound doesnt play that way!
if (checkIndexPosition(coconuts[i]) == 1) {
LK.getSound('sheOuch').play();
placeInsultes(1);
} else if (checkIndexPosition(coconuts[i]) == 2) {
@@ -628,9 +656,9 @@
if (livesLeft == 0) {
setLivesLeft();
LK.setTimeout(function () {
LK.showGameOver();
- }, 200);
+ }, 2000);
}
}
}
//Check if a coconut has touched the parasol et changement de trajectoire
@@ -641,8 +669,12 @@
if (coconuts[i].intersects(parasol) && coconuts[i].isFalling && deltaX < parasol.width / 2 && isCloseEnough) {
coconuts[i].Xintercept = parasol.x;
coconuts[i].Yintercept = coconuts[i].y;
score += 10;
+ if (score - scoreLast >= 1000 && livesLeft < 10) {
+ livesLeft += 1; //Bonus de 11 coeur tous les 1000 noix
+ scoreLast = score;
+ }
coconuts[i].isFalling = false;
var bouncingSoundList = ['bouncing1', 'bouncing2', 'bouncing3'];
var bouncingSound = bouncingSoundList[Math.floor(Math.random() * bouncingSoundList.length)];
LK.getSound(bouncingSound).play();
@@ -655,17 +687,20 @@
if (LK.ticks % 60 == 0) {
//Afficher les coeurs
setLivesLeft();
// Récupérer un coconut dans les arbres et le faire tomber si l'heure est venue
- if (coconutsInTree.length > 0 && nbTicksLeftBeforeNextThrow <= 0) {
+ if (coconutsInTree.length > 0 && nbTicksLeftBeforeNextThrow <= 0 && livesLeft > 0) {
if (coconutChoosen == null) {
coconutChoosen = chooseNextCoconut();
game.addChild(coconutChoosen);
} else {
nbTicksLeftBeforeNextThrow = nbTicksBeforeThrow;
coconutChoosen = null;
}
- } else {
+ } else if (coconutsInTree.length > 0 && nbTicksLeftBeforeNextThrow > 0) {
nbTicksLeftBeforeNextThrow -= 60;
+ } else if (coconutsInTree.length == 0) {
+ wave += 1;
+ setCocoInTree(wave);
}
}
};
\ No newline at end of file