Code edit (21 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: OrdiZone is not defined' in or related to this line: 'var outRight = this.sprite.x + this.dxHotLeftSpot >= OrdiZone.x; //L'abscisse du point chaud de gauche est superieur a l'abscisse de la zone ordi' Line Number: 377
User prompt
Please fix the bug: 'ReferenceError: scoreOrdiText is not defined' in or related to this line: 'scoreOrdiText.text = mettreAJourScore(scoreOrdiText, scoreOrdi);' Line Number: 781
User prompt
Please fix the bug: 'ReferenceError: scoreHumainText is not defined' in or related to this line: 'scoreHumainText.text = mettreAJourScore(scoreHumainText, scoreHumain);' Line Number: 776
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: buldorock_sprite is not defined' in or related to this line: 'buldos[i].sprite = buldorock_sprite;' Line Number: 681
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: this.setLigneVtoY is not a function' in or related to this line: 'this.setLigneVtoY(y); //On effectue le deplacement vertical' Line Number: 469
Code edit (10 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: buldoRock1.sprite.setAnchor is not a function' in or related to this line: 'buldoRock1.sprite.setAnchor(0.5, 0.5);' Line Number: 603
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'forEach')' in or related to this line: 'buldos.forEach(function (buldoCheck) {' Line Number: 341
Code edit (17 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'sprite')' in or related to this line: 'buldo.sprite.tint = 0xFFFFFF; //on enleve le filtre coloré' Line Number: 342
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: checkMovesStack is not defined' in or related to this line: 'LK.on('tick', checkMovesStack(delta)); //Verification des mouvements en cours' Line Number: 578
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'bind')' in or related to this line: 'buldos[i].sprite.on('down', this.onClickBuldo.bind(buldos[i], buldos));' Line Number: 474
User prompt
Please fix the bug: 'Uncaught ReferenceError: onClickBuldo is not defined' in or related to this line: 'buldos[i].sprite.on('down', onClickBuldo(buldos));' Line Number: 474
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'onClickBuldo')' in or related to this line: 'self.onClickBuldo = function (buldos) {' Line Number: 388
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -7,8 +7,9 @@
/****
* Game Code
****/
+//PARAMETRES DIVERS DU JEU
/*
Game Zones:
- The game is played on a 2048x2732 pixels screen.
0. let playersZoneWidth = 200;
@@ -16,8 +17,32 @@
2. let OptionsZone = {x: 0, y: app.screen.height-200, width: app.screen.width, height: 200};
3. let HumanZone = {x: 0, y: 200, width: playersZoneWidth, height: app.screen.height-OptionsZone.height-ScoreZone.height};
4. let ComputerZone = {x: app.screen.width-playersZoneWidth, y: 200, width: playersZoneWidth, height: app.screen.height-OptionsZone.height-ScoreZone.height};
5. let RoadZone = {x: playersZoneWidth, y: 200, width: app.screen.width-HumanZone.width-OrdiZone.width, height: app.screen.height-OptionsZone.height-ScoreZone.height};
+- At the start of the game, 10 rocks of three different sizes are randomly placed in the RoadZone.
+- Each player has two bulldozers to move the rocks.
+- A bulldozer moving without pushing anything has a base speed V.
+- When a bulldozer pushes a small rock, the combined speed is V/2.
+- When a bulldozer pushes a medium rock, the combined speed is V/4.
+- When a bulldozer pushes a large rock, the combined speed is V/8.
+- When two bulldozers push a rock together, one behind the other, the pushing speeds are doubled compared to the speed of a single bulldozer.
+- The human player clicks on a rock to command the nearest free bulldozer to push it towards the ComputerZone.
+- The computer-controlled bulldozers randomly choose a rock and push it towards the HumanZone.
+- If a human bulldozer is free, the player can click on a rock already being pushed to have the bulldozer move behind the first one and push the rock faster.
+- It is possible to push a rock that is being pushed by the opponent to block or slow down its movement. If a second bulldozer is added in this situation, the rock will be pushed in the direction where there are fewer bulldozers.
+- The game ends when all rocks have been moved out of the RoadZone. The winner is the one with the highest score, based on the number and size of rocks successfully moved to the opposing zone.
+- The goal for the human player is to move all the rocks to the ComputerZone while preventing the computer from doing the same. Effective strategy and skillful bulldozer management are necessary to maximize the score.
+There is no time limit in this game, and players must use their judgment to determine the best way to move rocks and use their bulldozers to win the game.
+*/
+/*
+Game Zones:
+- The game is played on a 2048x2732 pixels screen.
+0. let playersZoneWidth = 200;
+1. let ScoreZone = {x: 0, y: 0, width: app.screen.width, height: 200};
+2. let OptionsZone = {x: 0, y: app.screen.height-200, width: app.screen.width, height: 200};
+3. let HumanZone = {x: 0, y: 200, width: playersZoneWidth, height: app.screen.height-OptionsZone.height-ScoreZone.height};
+4. let ComputerZone = {x: app.screen.width-playersZoneWidth, y: 200, width: playersZoneWidth, height: app.screen.height-OptionsZone.height-ScoreZone.height};
+5. let RoadZone = {x: playersZoneWidth, y: 200, width: app.screen.width-HumanZone.width-OrdiZone.width, height: app.screen.height-OptionsZone.height-ScoreZone.height};
Game settings:
- At the start of the game, 10 rocks of three different sizes (small, medium, large) are randomly placed in the RoadZone.
- The rocks have square 100x100 pixels sprites centered (anchor 0.5, 0.5).
- The Rocks have a front and a back zone to simulate a contact area with the Buldos.
@@ -50,33 +75,8 @@
- The winner is the one with the highest score, based on the number and size of rocks successfully moved to the opposing zone (small rock is 1 point, medium rock is 2 points, large rock is 3 points).
- The goal for the human player is to move all the rocks to the ComputerZone while preventing the computer from doing the same.
- There is no time limit in this game, and players must use their judgment to determine the best way to move rocks and use their Buldos to win the game.
*/
-/*
-Game Zones:
-- The game is played on a 2048x2732 pixels screen.
-0. let playersZoneWidth = 200;
-1. let ScoreZone = {x: 0, y: 0, width: app.screen.width, height: 200};
-2. let OptionsZone = {x: 0, y: app.screen.height-200, width: app.screen.width, height: 200};
-3. let HumanZone = {x: 0, y: 200, width: playersZoneWidth, height: app.screen.height-OptionsZone.height-ScoreZone.height};
-4. let ComputerZone = {x: app.screen.width-playersZoneWidth, y: 200, width: playersZoneWidth, height: app.screen.height-OptionsZone.height-ScoreZone.height};
-5. let RoadZone = {x: playersZoneWidth, y: 200, width: app.screen.width-HumanZone.width-OrdiZone.width, height: app.screen.height-OptionsZone.height-ScoreZone.height};
-- At the start of the game, 10 rocks of three different sizes are randomly placed in the RoadZone.
-- Each player has two bulldozers to move the rocks.
-- A bulldozer moving without pushing anything has a base speed V.
-- When a bulldozer pushes a small rock, the combined speed is V/2.
-- When a bulldozer pushes a medium rock, the combined speed is V/4.
-- When a bulldozer pushes a large rock, the combined speed is V/8.
-- When two bulldozers push a rock together, one behind the other, the pushing speeds are doubled compared to the speed of a single bulldozer.
-- The human player clicks on a rock to command the nearest free bulldozer to push it towards the ComputerZone.
-- The computer-controlled bulldozers randomly choose a rock and push it towards the HumanZone.
-- If a human bulldozer is free, the player can click on a rock already being pushed to have the bulldozer move behind the first one and push the rock faster.
-- It is possible to push a rock that is being pushed by the opponent to block or slow down its movement. If a second bulldozer is added in this situation, the rock will be pushed in the direction where there are fewer bulldozers.
-- The game ends when all rocks have been moved out of the RoadZone. The winner is the one with the highest score, based on the number and size of rocks successfully moved to the opposing zone.
-- The goal for the human player is to move all the rocks to the ComputerZone while preventing the computer from doing the same. Effective strategy and skillful bulldozer management are necessary to maximize the score.
-There is no time limit in this game, and players must use their judgment to determine the best way to move rocks and use their bulldozers to win the game.
-*/
-//PARAMETRES DIVERS DU JEU
function _typeof2(o) {
"@babel/helpers - typeof";
return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
@@ -184,32 +184,33 @@
throw new TypeError("Cannot call a class as a function");
}
}
var nbRochers = 10; //nombre de rochers
+var delta = 1;
var vitesseBuldo = 8.0; //vitesse de déplacement des buldos a vide, vitesse/2 quand ils poussent un petit rocher, vitesse/4 pour un moyen, vitesse/8 pour un gros
var humanCamp = 1; //camp du joueur humain
var ordiCamp = -1; //camp du joueur ordinateur
var ancrageMedian = 0.5; //ancrage median des sprites
-var buldoRockHotSpotX = 35; //hotspot X du sprite buldoRock, offset du sprite par rapport à l'ancrage
+var buldoRockHotSpotX = 45; //hotspot X du sprite buldoRock, offset du sprite par rapport à l'ancrage
var buldoRockHotSpotY = 0; //hotspot Y du sprite buldoRock
-var buldoRockBkHotSpotX = -40; //hotspot arriere du buldoRock
+var buldoRockBkHotSpotX = -45; //hotspot arriere du buldoRock
var buldoRockBkHotSpotY = 0;
-var buldoZerHotSpotX = -35; //hotspot X du sprite buldoZer, offset du sprite par rapport à l'ancrage
+var buldoZerHotSpotX = -45; //hotspot X du sprite buldoZer, offset du sprite par rapport à l'ancrage
var buldoZerHotSpotY = 0; //hotspot Y du sprite buldoZer
-var buldoZerBkHotSpotX = 35; //hotspot arriere du buldoZer
+var buldoZerBkHotSpotX = 45; //hotspot arriere du buldoZer
var buldoZerBkHotSpotY = 0;
var petitRocher = 2; //taille du rocher (2=petit, 4=moyen, 8=gros)
-var petitRocherDxHotLeft = -16; //hotspot X du sprite petitRocher, offset du sprite par rapport à l'ancrage
+var petitRocherDxHotLeft = -25; //hotspot X du sprite petitRocher, offset du sprite par rapport à l'ancrage
var petitRocherDyHotLeft = 0; //hotspot Y du sprite petitRocher
-var petitRocherDxHotRight = 20; //hotspot X du sprite petitRocher, offset du sprite par rapport à l'ancrage
+var petitRocherDxHotRight = 25; //hotspot X du sprite petitRocher, offset du sprite par rapport à l'ancrage
var petitRocherDyHotRight = 0; //hotspot Y du sprite petitRocher
var moyenRocher = 4; //taille du rocher (2=petit, 4=moyen, 8=gros)
-var moyenRocherDxHotLeft = -35; //hotspot X du sprite moyenRocher, offset du sprite par rapport à l'ancrage
+var moyenRocherDxHotLeft = -30; //hotspot X du sprite moyenRocher, offset du sprite par rapport à l'ancrage
var moyenRocherDyHotLeft = 0; //hotspot Y du sprite moyenRocher
-var moyenRocherDxHotRight = 15; //hotspot X du sprite moyenRocher, offset du sprite par rapport à l'ancrage
+var moyenRocherDxHotRight = 30; //hotspot X du sprite moyenRocher, offset du sprite par rapport à l'ancrage
var moyenRocherDyHotRight = 0; //hotspot Y du sprite moyenRocher
var grosRocher = 8; //taille du rocher (2=petit, 4=moyen, 8=gros)
-var grosRocherDxHotLeft = -40; //hotspot X du sprite grosRocher, offset du sprite par rapport à l'ancrage
+var grosRocherDxHotLeft = -45; //hotspot X du sprite grosRocher, offset du sprite par rapport à l'ancrage
var grosRocherDyHotLeft = 0; //hotspot Y du sprite grosRocher
var grosRocherDxHotRight = 45; //hotspot X du sprite grosRocher, offset du sprite par rapport à l'ancrage
var grosRocherDyHotRight = 0; //hotspot Y du sprite grosRocher
var typeRotation = 1; //Type 1 = rotation
@@ -288,8 +289,9 @@
self.sprite.x = x;
self.sprite.y = y;
self.sprite.anchor.set(0.5);
self.sprite.scale.set(1.0);
+ self.sprite.visible = false;
if (self.tailleRocher == petitRocher) {
self.dxHotLeftSpot = petitRocherDxHotLeft;
self.dyHotLeftSpot = petitRocherDyHotLeft;
self.dxHotRightSpot = petitRocherDxHotRight;
@@ -315,8 +317,28 @@
}
if (self.tailleRocher == grosRocher) {
self.name = "Gros Rocher";
}
+ this.onClickRocherBuldo = function (buldos) {
+ //Action à effectuer lorsqu'on clique sur un rocher
+ //Récupération des coordonnées du sprite rocher cliqué
+ var x = this.sprite.x;
+ var y = this.sprite.y;
+ //Parcours de la liste des buldos pour trouver le buldo selectionne
+ var buldo = null;
+ for (var i = 0; i < buldos.length; i++) {
+ if (buldos[i].isSelected) {
+ buldo = buldos[i];
+ break;
+ }
+ }
+ //Si le buldo selectionne est trouve, on le deplace vers le sprite rocher
+ if (buldo != null && !buldo.isMoving) {
+ x = buldo.camp == humanCamp ? x + this.dxHotLeftSpot : x + this.dxHotRightSpot;
+ y = buldo.camp == humanCamp ? y + this.dyHotLeftSpot : y + this.dyHotRightSpot;
+ buldo.rocherDestination = this; //Le buldo a pour destination le sprite rocher cliqué
+ }
+ }; //fin onClickRocherBuldo
}); //fin class Rocher
var Buldo = /*#__PURE__*/_createClass2(function Buldo(x, y, camp) {
_classCallCheck2(this, Buldo);
var self = this; // Ensure 'self' is defined to refer to the Buldo instance
@@ -347,8 +369,9 @@
this.sprite.x = x;
this.sprite.y = y;
this.sprite.anchor.set(0.5);
this.sprite.scale.set(1.0);
+ this.sprite.visible = false;
this.xBase = x; //Position de base du sprite
this.yBase = y;
this.stack = []; //Pile des points x,y destination cliqués par la souris
this.movesStack = []; //Pile des mouvements a effectuer (types de mouvements : 1 : rotation, 2 : horizontal, 3 : vertical, 4 : xy)
@@ -356,17 +379,15 @@
this.vitesseEnCours = 0.0; //vitesse de deplacement en cours en pixels par secondes en cours de deplacement
this.isMoving = false; //Flag qui indique si le Buldo est en mouvement
this.isMovingH = false; //Flag qui indique si le Buldo est en mouvement horizontal
this.isMovingV = false; //Flag qui indique si le Buldo est en mouvement vertical
- this.isMovingXY = false; //Flag qui indique si le Buldo est en mouvement vers un point x,y
- this.isMovingHtoPush = false; //Flag qui indique si le Buldo est en mouvement horizontal pour pousser un rocher
this.xDestination = 0.0; //Abscisse x du point x,y destination
this.yDestination = 0.0; //Ordonnee y du point x,y destination
+ this.rocherDestination = null; //Rocher destination du Buldo
this.isPushing = false; //Flag qui indique si le Buldo est en train de pousser un rocher
this.rocherPushed = null; //Rocher pousse par le Buldo
this.isRotating = false; //Flag qui indique si le Buldo est en rotation
this.sprite.rotation = 0.0;
- this.angleDegresTotal = 0.0; //Angle total a tourner en degres
this.angleRadiansLeft = 0.0; //Angle restant a tourner en radians
this.vitesseAngulaireDS = 2.0; //vitesse de rotation du sprite en degres par secondes
this.vitesseAngulaireRms = 0.0; //vitesse angulaire en radians par millisecondes
this.onClickBuldo = function (buldos) {
@@ -386,12 +407,79 @@
//Sinon on le selectionne s'il n'est pas en mouvement ou en rotation
var isNotMoving = !this.isRotating && !this.isMovingH && !this.isMovingV && !this.isMovingXY;
if (isNotMoving) {
this.isSelected = true;
- this.sprite.tint = 0xD00D0D; //on ajoute un filtre coloré
+ this.sprite.tint = 0xD0D00D; //on ajoute un filtre coloré
}
}
}; //fin onClickBuldo
+ this.addMoveToStack = function (type, x, y) {
+ //type = 1 : rotation, type = 2 : deplacement horizontal, type = 3 : deplacement vertical, type = 6 : combinaison
+ this.movesStack.push([type, x, y]); //On ajoute le mouvement a la pile des mouvements a effectuer
+ }; //fin addMoveToStack
+ this.checkMovesStack = function (delta) {
+ //Verification d'un mouvement en cours
+ if (this.isRotating || this.isMovingH || this.isMovingV) {
+ if (this.isRotating) {
+ this.tourneMoi(delta);
+ } //Si le Buldo est en rotation, on continue la rotation
+ if (this.isMovingH) {
+ this.deplaceHtoX(delta);
+ } //Si le Buldo est en deplacement horizontal, on continue le deplacement
+ if (this.isMovingV) {
+ this.deplaceVtoY(delta);
+ } //Si le Buldo est en deplacement vertical, on continue le deplacement
+ return;
+ }
+ if (this.movesStack.length > 0) {
+ //Si la pile des mouvements a effectuer n'est pas vide
+ var move = this.movesStack.shift(); //On recupere le premier mouvement de la pile
+ var type = move[0]; //Type de mouvement (1 : rotation, 2 : deplacement horizontal, 3 : deplacement vertical)
+ var x = move[1]; //Abscisse x du point x,y destination ou angle de rotation ou fonction de deplacement
+ var y = move[2]; //Ordonnee y du point x,y destination ou fonction de deplacement
+ switch (type) {
+ case typeRotation:
+ //Si le mouvement est une rotation, on effectue la rotation
+ this.setRotation(x); //On effectue la rotation
+ break;
+ case typeLigneHtoX:
+ //Si le mouvement est un deplacement horizontal, on effectue le deplacement
+ this.setLigneHtoX(x); //On effectue le deplacement horizontal
+ break;
+ case typeLigneVtoY:
+ //Si le mouvement est un deplacement vertical, on effectue le deplacement
+ this.setLigneVtoY(y); //On effectue le deplacement vertical
+ break;
+ default:
+ break;
+ }
+ }
+ }; //fin checkMovesStack
+ this.setRotation = function (alphaDegres) {
+ //Fonction d'initialisation de la rotation
+ this.isRotating = true; //on indique que le Buldo est en rotation
+ this.angleRadiansLeft = Math.abs(alphaDegres * Math.PI / 180); //on indique l'angle restant a tourner en radians
+ var sens = alphaDegres > 0 ? 1 : -1; //sens de rotation
+ this.vitesseAngulaireRms = sens * this.vitesseAngulaireDS * Math.PI / 180 / 1000; //vitesse angulaire
+ }; //fin setRotation
+ this.tourneMoi = function (delta) {
+ //Fonction de rotation du Buldo
+ if (this.isRotating) {
+ //Si le Buldo est en rotation
+ // Si l'angle total à tourner est atteint, on arrête la rotation
+ // et on ajoute à la rotation du sprite la valeur en radians de l'angle qu'il reste à tourner
+ if (this.angleRadiansLeft <= Math.abs(this.vitesseAngulaireRms * delta * 1000)) {
+ this.isRotating = false;
+ this.sprite.rotation += this.vitesseAngulaireRms > 0 ? this.angleRadiansLeft : -this.angleRadiansLeft; // ajout de l'angle alphaDegresMS (en radians) à la rotation du sprite
+ return;
+ } else {
+ // Ajout à la rotation du sprite la valeur en radians de l'angle alphaDegresMS (vitesse angulaire en radians par millisecondes * delta * 1000)
+ this.sprite.rotation += this.vitesseAngulaireRms * delta * 1000; // ajout de l'angle alphaDegresMS (en radians) à la rotation du sprite
+ // Calcul de l'angle restant à tourner
+ this.angleRadiansLeft -= Math.abs(this.vitesseAngulaireRms * delta * 1000); // soustraction de l'angle alphaDegresMS à l'angle restant à tourner
+ }
+ }
+ }; //fin tourneMoi
}); //fin constructor
function generateRandomRock(nombreRochers) {
//Calcul de positions aléatoire pour les rochers dans la zone de route
var zoneMiniy = RoadZone.y;
@@ -420,8 +508,9 @@
var y = ordonneesPossibles[index];
ordonneesPossibles.splice(index, 1);
// Créer le rocher
var rock = new Rocher(size, x, y);
+ rock.sprite.visible = true;
rochers.push(rock);
}
return rochers;
} //fin generateRandomRock
@@ -448,19 +537,35 @@
buldoZer2.vitessePS = vitesseBuldo;
//On initialise leurs positions de base xBase et yBase
buldoRock1.xBase = buldoRock1.sprite.x;
buldoRock1.yBase = buldoRock1.sprite.y;
+ buldoRock1.sprite.visible = true;
buldoRock2.xBase = buldoRock2.sprite.x;
buldoRock2.yBase = buldoRock2.sprite.y;
+ buldoRock2.sprite.visible = true;
buldoZer1.xBase = buldoZer1.sprite.x;
buldoZer1.yBase = buldoZer1.sprite.y;
+ buldoZer1.sprite.visible = true;
buldoZer2.xBase = buldoZer2.sprite.x;
buldoZer2.yBase = buldoZer2.sprite.y;
+ buldoZer2.sprite.visible = true;
//On ajoute les evenements de clic sur les sprites Buldo
for (var i = 0; i < buldos.length; i++) {
buldos[i].sprite.on('down', buldos[i].onClickBuldo.bind(buldos[i], buldos));
}
; // Fonction de callback pour le clic gauche sur les sprites.
return buldos;
} //fin de createBuldos
var rochers = generateRandomRock(nbRochers); //création des rochers
-var buldos = createBuldos(); //Creation des Buldos
\ No newline at end of file
+var buldos = createBuldos(); //Creation des Buldos
+// Fonction de rappel pour le tick
+function onGameTick() {
+ // Appel de checkMovesStack à chaque tick
+ checkMovesStack(delta);
+ // Autres mises à jour du jeu ici en cours de test..
+}
+// Instead of directly calling checkMovesStack, iterate over buldos and call checkMovesStack for each
+LK.on('tick', function () {
+ buldos.forEach(function (buldo) {
+ buldo.checkMovesStack(delta);
+ });
+});
\ No newline at end of file
A small rock
a rock without any shadow and four time smaller than the original.
Blue color
a rock is being crunched so there is smoke and peaces of rocks viewed from top.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Un trophée de victoire sous forme d'une coupe d'où s'échappe un feu d'artifice.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Red bulldozer viewed strictly from top. Top view as if we are a drone.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Remove yellow lines.