Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: game.playSound is not a function' in or related to this line: 'game.playSound(rock_appears);' Line Number: 959
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self is undefined' in or related to this line: 'rocher.sprite = self.rocher_split_sprite;' Line Number: 1160
Code edit (16 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: rocher_split_sprite is not defined' in or related to this line: 'rocher.sprite = rocher_split_sprite;' Line Number: 1159
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: animatinImageOn is not defined' in or related to this line: 'if (!animatinImageOn) {' Line Number: 1221
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: coupeVictoire is not defined' in or related to this line: 'var imageCoupeVictoire = {' Line Number: 856
Code edit (13 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: Score is not defined' in or related to this line: 'imageCoupeVictoire.yToReach = Score;' Line Number: 1236
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: 'ReferenceError: nbTicksLeft is not defined' in or related to this line: 'nbTicksLeft = scrollRescaleImage(coupeVictoire, 1, game.width / 2, game.height / 2, nbTicksLeft);' Line Number: 1182
Code edit (1 edits merged)
Please save this source code
Code edit (22 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: victoireX is not defined' in or related to this line: 'var coupeVictoire = LK.getAsset('coupeVictoire', {' Line Number: 842
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 ReferenceError: rocher_petit_sprite is not defined' in or related to this line: 'self.sprite = rocher_petit_sprite;' Line Number: 327
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: rocher_moyen_sprite is not defined' in or related to this line: 'self.sprite = rocher_moyen_sprite;' Line Number: 330
Code edit (11 edits merged)
Please save this source code
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xAAAAAA
});
/****
* Game Code
****/
//LK.init.image('pouf', {width:100, height:100, id:'662e608a2a374391362a0467'})
//PARAMETRES DIVERS DU JEU
/*
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.
*/
/*
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.
- Each rock is on its own horizontal 100 pixels wide line.
- There are two players: the human player and the computer.
- Each player has two Buldos to move the rocks, a kind of bulldozer.
- The human Buldos are called "buldoRocks" and the computer Buldos are called "buldoZers".
- The buldoRocks have a 100x100 pixels sprite centered (anchor 0.5, 0.5).
- The buldoZers have a 100x100 pixels sprite centered (anchor 0.5, 0.5).
- The Buldos have a front and a back zone to simulate the pushing of the rocks.
- At the start of the game, the buldoRocks are placed in the HumanZone and the buldoZers are placed in the ComputerZone (abscissa centered and ordinate equally spaced 1/3, 2/3).
- The buldoRocks are facing right and the buldoZers are facing left.
Game rules:
- The buldoZers are controlled by the computer and will move randomly (or futher with AI) to push the rocks towards the HumanZone.
- The buldoRocks are controlled by the human player and will move when the player clicks or taps to push the rocks towards the ComputerZone.
- The human player selects a buldoRock by clicking or tapping on it, then selects a rock to push by clicking or tapping on it.
- The Buldos may only move in lignes, horizontally or vertically, and may not move diagonally.
- When a Buldo is selected to push a rock, the Buldo must move to the ordonnate of the rock
- To move to the ordonnate of the rock, the Buldo will probably have to make a 90 degres rotation, then move vertically up or down to the ordonnate of the rock, then make a 90 degres rotation to face the rock.
- When a rock is entirely into the HumanZone or the ComputerZone, it is out of the game (loss of visibility of its sprite or destruction of the object Rock).
- When a Buldo has finished pushing a rock, it comes back to its camp (HumanZone or ComputerZone) horizontally and once in its camp, it turns at 180 degres to face the RoadZone.
- A Buldo moving without pushing anything has a base speed V (to futher adjust).
- 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.
- It is possible to push a rock that is being pushed by the opponent to block or slow down its movement.
- If a second Buldo is added in this situation, the rock will be pushed in the direction where there are fewer Buldos.
- When a rock is blocked, it splits into smaller rocks depending of its size.
- A large rock splits into a small and a medium one.
- A medium rock splits into two small rocks.
- A small rock is destroyed and disappears.
- The splitted new rocks are thrown from the position of the blocked rock to a free ligne.
- 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 (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.
*/
function _typeof2(o) {
"@babel/helpers - typeof";
return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof2(o);
}
function __defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) {
descriptor.writable = true;
}
Object.defineProperty(target, _toPropertyKey2(descriptor.key), descriptor);
}
}
function _createClass2(Constructor, protoProps, staticProps) {
if (protoProps) {
__defineProperties(Constructor.prototype, protoProps);
}
if (staticProps) {
__defineProperties(Constructor, staticProps);
}
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _toPropertyKey2(t) {
var i = _toPrimitive2(t, "string");
return "symbol" == _typeof2(i) ? i : String(i);
}
function _toPrimitive2(t, r) {
if ("object" != _typeof2(t) || !t) {
return t;
}
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof2(i)) {
return i;
}
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _classCallCheck2(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) {
descriptor.writable = true;
}
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) {
_defineProperties(Constructor.prototype, protoProps);
}
if (staticProps) {
_defineProperties(Constructor, staticProps);
}
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : String(i);
}
function _toPrimitive(t, r) {
if ("object" != _typeof(t) || !t) {
return t;
}
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof(i)) {
return i;
}
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
var nbRochers = 10; //nombre de rochers
var nbBuldoRocks = 0; //nombre de buldoRocks
var nbBuldoZers = 0; //nombre de buldoZers
var delta = 1; //Heritage des tests en PixiJS
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 buldoRockHotSpotX = 40 * 2; //hotspot X du sprite buldoRock, offset du sprite par rapport à l'ancrage
var buldoRockHotSpotY = 0; //hotspot Y du sprite buldoRock
var buldoRockBkHotSpotX = -28 * 2; //hotspot arriere du buldoRock
var buldoRockBkHotSpotY = 0;
var buldoZerHotSpotX = 40 * 2; //hotspot X du sprite buldoZer, offset du sprite par rapport à l'ancrage
var buldoZerHotSpotY = 0; //hotspot Y du sprite buldoZer
var buldoZerBkHotSpotX = 28 * 2; //hotspot arriere du buldoZer
var buldoZerBkHotSpotY = 0;
var ordonneesRestantes = []; //liste des ordonnees non encore utilisees pour le placement des rochers
var petitRocher = 2; //taille du rocher (2=petit, 4=moyen, 8=gros)
var petitRocherDxHotLeft = -25 * 2; //hotspot X du sprite petitRocher, offset du sprite par rapport à l'ancrage
var petitRocherDyHotLeft = 0; //hotspot Y du sprite petitRocher
var petitRocherDxHotRight = 25 * 2; //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 = -30 * 2; //hotspot X du sprite moyenRocher, offset du sprite par rapport à l'ancrage
var moyenRocherDyHotLeft = 0; //hotspot Y du sprite moyenRocher
var moyenRocherDxHotRight = 30 * 2; //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 = -45 * 2; //hotspot X du sprite grosRocher, offset du sprite par rapport à l'ancrage
var grosRocherDyHotLeft = 0; //hotspot Y du sprite grosRocher
var grosRocherDxHotRight = 45 * 2; //hotspot X du sprite grosRocher, offset du sprite par rapport à l'ancrage
var grosRocherDyHotRight = 0; //hotspot Y du sprite grosRocher
var timeBeforeSplit = 200; //temps en ticks avant division du rocher bloque
var nbTicksBeforeStopFlashing = 10; //nombre de ticks avant d'arreter de clignoter
var rocher_split_sprite = game.addChild(LK.getAsset('pouf', {
anchorX: 0.5,
anchorY: 0.5
}));
var typeRotation = 1; //Type 1 = rotation
var typeLigneHtoX = 2; //Type 2 = déplacement horizontal vers une position X
var typeLigneVtoY = 3; //Type 3 = déplacement vertical vers une position Y
var typeLigneHtoR = 4; //Type 4 = déplacement horizontal vers un rocher
var gameHasStarted = false; //Flag qui indique si le jeu a commence (premiers clics buldo puis rocher)
var activeCamp = 0; //Camp selectionne par le joueur
var humanCamp = 1; //camp du joueur humain
var ordiCamp = -1; //camp du joueur ordinateur
var scoreHumain = 0;
var scoreOrdi = 0;
var scoreTest = 0; // Define scoreTest variable
var ScoreZone = {
x: 0,
y: 0,
width: game.width,
height: 200
};
var OptionsZone = {
x: 0,
y: game.height - 200,
width: game.width,
height: 200
};
var HumanZone = {
x: 0,
y: ScoreZone.height,
width: game.width / 10,
height: game.height - ScoreZone.height - OptionsZone.height
};
var ComputerZone = {
x: game.width - game.width / 10,
y: ScoreZone.height,
width: game.width / 10,
height: HumanZone.height
};
var RoadZone = {
x: HumanZone.width,
y: ScoreZone.height,
width: game.width - HumanZone.width - ComputerZone.width,
height: game.height - OptionsZone.height - ScoreZone.height
};
//Ajout d'un fond a la zone route
var route_sprite = game.addChild(LK.getAsset('zoneRoute', {}));
route_sprite.width *= 5.2;
route_sprite.height *= 1.0;
route_sprite.x -= 4325;
route_sprite.y += -50;
// Since direct manipulation like Graphics is not allowed, and LK does not support drawing shapes dynamically,
// we remove the code that causes the error. Instead, consider using a predefined shape or image asset if needed.
//CLASS ROCHER
var Rocher = /*#__PURE__*/_createClass(function Rocher() {
var tailleRocher = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : petitRocher;
var x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : RoadZone.width / 2;
var y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : RoadZone.height / 2;
_classCallCheck(this, Rocher);
var self = this; // Initialize self to refer to the Rocher instance
self.name = "rocher";
self.dxHotLeftSpot = petitRocherDxHotLeft; //Offset du point chaud du sprite (point de contact avec le rocher a gauche) décalage par rapport au point d'ancrage
self.dyHotLeftSpot = petitRocherDyHotLeft;
self.dxHotRightSpot = petitRocherDxHotRight; //Offset du point chaud du sprite (point de contact avec le rocher a droite) décalage par rapport au point d'ancrage
self.dyHotRightSpot = petitRocherDyHotRight;
self.isBeingPushed = false; //Flag qui indique si le rocher est pousse par un buldo
self.isBlocked = false; //Flag qui indique si le rocher est bloque
self.tempoBlocked = 0; //Temps de blocage du rocher
self.vitesse = 0.0;
self.pushers = []; //Liste des buldos qui vont pousser ou qui poussent le rocher
self.totalForce = 0; //Somme des forces qui poussent le rocher (+1 pour un buldoRock, -1 pour un buldoZer)
self.totalBuldos = 0; //Nombre de Buldos qui poussent le rocher
self.rocher_petit_sprite = LK.getAsset('small_rock', {
anchorX: 0.5,
anchorY: 0.5
});
self.rocher_moyen_sprite = LK.getAsset('medium_rock', {
anchorX: 0.5,
anchorY: 0.5
});
self.rocher_gros_sprite = LK.getAsset('large_rock', {
anchorX: 0.5,
anchorY: 0.5
});
self.tailleRocher = tailleRocher;
if (self.tailleRocher == petitRocher) {
self.sprite = rocher_petit_sprite;
}
if (self.tailleRocher == moyenRocher) {
self.sprite = rocher_moyen_sprite;
}
if (self.tailleRocher == grosRocher) {
self.sprite = rocher_gros_sprite;
}
self.sprite.x = x;
self.sprite.y = y;
self.sprite.anchor.set(0.5);
self.sprite.scale.set(1.5);
self.sprite.visible = false;
if (self.tailleRocher == petitRocher) {
self.dxHotLeftSpot = petitRocherDxHotLeft;
self.dyHotLeftSpot = petitRocherDyHotLeft;
self.dxHotRightSpot = petitRocherDxHotRight;
self.dyHotRightSpot = petitRocherDyHotRight;
}
if (self.tailleRocher == moyenRocher) {
self.dxHotLeftSpot = moyenRocherDxHotLeft;
self.dyHotLeftSpot = moyenRocherDyHotLeft;
self.dxHotRightSpot = moyenRocherDxHotRight;
self.dyHotRightSpot = moyenRocherDyHotRight;
}
if (self.tailleRocher == grosRocher) {
self.dxHotLeftSpot = grosRocherDxHotLeft;
self.dyHotLeftSpot = grosRocherDyHotLeft;
self.dxHotRightSpot = grosRocherDxHotRight;
self.dyHotRightSpot = grosRocherDyHotRight;
}
if (self.tailleRocher == petitRocher) {
self.name = "Petit Rocher";
}
if (self.tailleRocher == moyenRocher) {
self.name = "Moyen Rocher";
}
if (self.tailleRocher == grosRocher) {
self.name = "Gros Rocher";
}
self.isClicked = false; //Flag qui indique si le rocher est clique
self.nbTicksSinceClicked = 0; //Nombre de ticks depuis le dernier clic
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;
this.sprite.tint = 0xF0B030; //on ajoute un filtre coloré
self.isClicked = true; //Le rocher est clique
//Parcours de la liste des buldos pour trouver le buldo selectionne
if (buldos) {
var buldo = null;
buldos.forEach(function (buldoCheck) {
if (buldoCheck != null) {
if (buldoCheck.isSelected) {
buldo = buldoCheck;
if (activeCamp == 0) {
//On fixe le camp actif choisi par le joueur
activeCamp = buldo.camp;
}
}
}
});
//Si le buldo selectionne est trouve, on le deplace vers le sprite rocher ou on stock le prochain rocher cible
if (buldo != null) {
buldo.rochersCibles.push(this); //On stock le prochain rocher cible
} else {
//Sinon on retire la teinte du rocher
this.sprite.tint = 0xFFFFFF;
}
}
}; //fin onClickRocherBuldo
this.timeToReach = function (x, y) {
//Donne le temps pour un buldo situe en x,y de rejoindre le rocher additonne au temps pour le pousser hors de la zone route (sans tenir compte du temps des rotations)
var dy = Math.abs(y - this.sprite.y); //On calcule la distance verticale entre le buldo et le rocher
var dx = Math.abs(x - this.sprite.x); //On calcule la distance horizontale entre le buldo et le rocher
var dout = RoadZone.width - dx; //On calcule la distance horizontale entre le rocher et la zone route
var timeToReach = (dx + dy) / vitesseBuldo; //On calcule le temps pour le buldo de rejoindre le rocher
var timeToPush = dout / (vitesseBuldo / this.tailleRocher); //On calcule le temps pour le buldo de pousser le rocher hors de la zone route
return Math.ceil(timeToReach + timeToPush); //On arrondi le temps a l'unite superieure
}; //fin timeToReach
this.destroy = function () {
//On previent les eventuels buldos qui poussent le rocher que le rocher est detruit
if (this.pushers) {
this.pushers.forEach(function (buldo) {
if (buldo != null) {
buldo.rocherDestination = null;
buldo.rocherPushed = null;
buldo.isPushing = false;
//On supprime eventuellement le rocher de la liste des rochers cibles
var index = buldo.rochersCibles.indexOf(this);
if (index > -1) {
buldo.rochersCibles.splice(index, 1);
}
}
});
}
//On vide la liste des buldos qui poussent le rocher
this.pushers = [];
//On recupere l'ordonnee du rocher pour une potentielle reutilisation
ordonneesRestantes.push(this.sprite.y);
//On supprime le rocher de la liste des rochers
var index = rochers.indexOf(this);
if (index > -1) {
rochers.splice(index, 1);
}
nbRochers = nbRochers - 1; //Decrement du nombre de rochers
//Invisibilite du sprite rocher
this.sprite.visible = false;
}; //fin destroy
this.onOutRocher = function () {
var outRight = this.sprite.x + this.dxHotLeftSpot >= ComputerZone.x; //L'abscisse du point chaud de gauche est superieur a l'abscisse de la zone ordi
var outLeft = this.sprite.x + this.dxHotRightSpot <= HumanZone.x + HumanZone.width; //L'abscisse du point chaud de droite est inferieur a l'abscisse de la zone humaine
if (outRight || outLeft) {
//Si le sprite rocher sort de la zone route
//Incrementation du score en fonction de la taille du rocher (1 pour petit, 2 pour moyen, 3 pour gros)
//Sachant que tailleRocher = 2 pour petit, 4 pour moyen, 8 pour gros
if (outRight) {
scoreHumain = Number(scoreHumain) + Math.log2(this.tailleRocher);
}
if (outLeft) {
scoreOrdi = Number(scoreOrdi) + Math.log2(this.tailleRocher);
}
this.vitesse = 0.0; //Arret du rocher (et donc des buldos qui le poussent)
this.isBeingPushed = false; //Le rocher n'est plus pousse
this.totalForce = 999; //On annule la poussee
this.totalBuldos = 0; //Plus aucun Buldo ne pousse le rocher
this.destroy(); //Destruction du sprite rocher
}
}; //fin onOutRocher
this.checkPushed = function () {
if (this == null) {
return;
}
if (this.sprite.visible == false) {
return;
}
if (this.isBeingPushed) {
//Si le rocher est pousse par un bul
this.sprite.x += this.vitesse; //Deplacement du rocher
this.onOutRocher(); //Si le rocher sort de la zone route, on le detruit (invisible)
}
}; //fin checkPushed
this.sortPushers = function () {
//Tri du tableau this.pushers des buldos qui poussent le rocher par ordre croissant de distance au rocher (distance entre le centre du rocher et le centre du buldo)
var actualPushers = []; //Liste des buldos qui poussent le rocher
var nonPushers = []; //Liste des buldos qui ne poussent pas le rocher
this.pushers.forEach(function (buldo) {
if (buldo.isPushing) {
actualPushers.push(buldo);
} else {
nonPushers.push(buldo);
}
});
actualPushers.sort(function (a, b) {
var distA = dist(a.sprite.x, a.sprite.y, self.sprite.x, self.sprite.y);
var distB = dist(b.sprite.x, b.sprite.y, self.sprite.x, self.sprite.y);
return distA - distB;
});
this.pushers = actualPushers.concat(nonPushers);
}; //fin sortPushers
}); //fin class Rocher
//CLASS BULDO
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
this.name = "buldo";
this.camp = camp; //Camp du buldo (1=Human buldoRock ou -1=Ordi buldoZer)
this.isSelected = false; //Flag qui indique si le Buldo est selectionne
this.buldorock_sprite = LK.getAsset('bulldorock', {
anchorX: 0.5,
anchorY: 0.5
});
this.buldozer_sprite = LK.getAsset('bulldozer', {
anchorX: 0.5,
anchorY: 0.5
});
if (this.camp == humanCamp) {
this.sprite = this.buldorock_sprite;
} else if (this.camp == ordiCamp) {
this.sprite = this.buldozer_sprite;
}
this.sprite.x = x;
this.sprite.y = y;
this.sprite.anchor.set(0.5);
this.sprite.scale.set(2.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)
this.vitessePS = vitesseBuldo; //vitesse de deplacement du sprite en pixels par secondes
this.vitesseEnCours = 0.0; //vitesse de deplacement en cours en pixels par secondes en cours de deplacement
this.isOnBase = true; //Flag qui indique si le Buldo est sur sa base
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.isMovingR = false; //Flag qui indique si le Buldo est en mouvement horizontal vers 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.rochersCibles = []; //Liste des rochers cibles
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.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) {
//On exclu le clic sur l'autre camp si un camp est actif
if (activeCamp != 0 && this.camp != activeCamp) {
return;
}
//On deselectionne tous les sprites Buldo
for (var i = 0; i < buldos.length; i++) {
if (buldos[i].name != this.name) {
buldos[i].isSelected = false;
buldos[i].sprite.tint = 0xFFFFFF; //on enleve le filtre coloré
}
}
//Gestion du clic sur le sprite Buldo
if (this.isSelected) {
//Si le sprite est deja selectionne, on le deselectionne
this.isSelected = false;
this.sprite.tint = 0xFFFFFF; //on enleve le filtre coloré
} else {
//Sinon on le selectionne
this.isSelected = true;
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 = 4 : deplacement horizontal vers un rocher, 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 || this.isMovingR) {
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
if (this.isMovingR) {
this.deplaceHtoR(delta);
} //Si le Buldo est en deplacement horizontal vers un rocher, on continue le deplacement
return;
}
if (this.movesStack.length > 0) {
//Si la pile des mouvements a effectuer n'est pas vide
this.isOnBase = false; //Le Buldo n'est plus sur sa base
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);
break;
case typeLigneHtoR:
//Si le mouvement est un deplacement horizontal vers un rocher, on effectue le deplacement
this.setLigneHtoR(this.rocherDestination);
default:
break;
}
return;
}
//Si la pile des mouvements (movesStack) est vide, on verifie la pile des rochers cibles et on deplace le Buldo vers le prochain rocher cible
if (this.rochersCibles.length > 0) {
var rocher = this.rochersCibles.shift(); //On recupere le premier rocher de la pile des rochers cibles
if (rocher != null && rocher.sprite.visible) {
//Si le rocher est visible
if (!this.isMoving) {
this.moveToRock(rocher); //On deplace le Buldo vers le rocher
}
}
} else if (this.sprite.y != this.yBase) {
//Si la liste des rochers a pousser est vide, on retourne au point de base
this.moveBackToBase();
} else {
//Si le Buldo est a son point de base
this.isOnBase = true;
}
}; //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
this.setLigneHtoX = function (x) {
//Fonction d'initialisation du deplacement horizontal du Buldo
//Si la distance AD est inferieure a la distance HD, le point D est derriere le point A, le Buldo ne se deplace pas
this.isMovingH = true; //on indique que le Buldo est en mouvement
this.xDestination = x - this.camp * this.dxAvHotSpot; //le point d'ancrage doit s'arreter un peu avant x pour superposer le point chaud AV (rappel : dxAvHotSpot est negatif pour les buldoZer de l'ordi)
var sens = this.xDestination > this.sprite.x ? 1 : -1; //Calcul du sens du deplacement horizontal : 1=droite, -1=gauche
this.vitesseEnCours = sens * this.vitessePS; //on indique la vitesse de deplacement en cours en pixels par secondes
}; //fin setLigneHtoX
this.deplaceHtoX = function (delta) {
//Fonction de deplacement horizontal du Buldo
// Vérifie si le Buldo est en mouvement
if (this.isMovingH) {
// Si la distance entre le sprite et le point destination est inférieure à la vitesse en cours, on arrête le déplacement
// et on donne à l'abscisse du sprite la valeur qui superpose avec le point destination
var dx = Math.abs(this.xDestination - this.sprite.x);
if (dx < this.vitessePS * delta) {
this.sprite.x = this.xDestination;
this.isMovingH = false; //Fin du mouvement H simple
return;
} else {
// Sinon on déplace le sprite horizontalement
// Déplacement du sprite
this.sprite.x += this.vitesseEnCours * delta;
return;
}
}
}; // fin deplaceHtoX
this.setLigneVtoY = function (y) {
this.isMovingV = true; //on indique que le Buldo est en mouvement
this.yDestination = y; //le point d'ancrage doit s'arreter sur y
//Calcul du sens du deplacement verticale : 1=bas, -1=haut
this.vitesseEnCours = this.sprite.y < y ? this.vitessePS : -this.vitessePS; //on donne le sens du deplacement vertical
}; //fin setLigneVtoY
this.deplaceVtoY = function (delta) {
// Vérifie si le Buldo est en mouvement
if (this.isMovingV) {
var AD = dist(0, this.sprite.y, 0, this.yDestination);
if (AD <= Math.abs(this.vitesseEnCours * delta)) {
// Si la distance entre l'ordonnee du sprite et l'ordonnee y destination est inférieure à la vitesse en cours, on arrête le déplacement
this.sprite.y = this.yDestination; // on donne à l'ordonnée du sprite la valeur y destination
this.isMovingV = false; // on indique que le Buldo n'est plus en mouvement
return;
} else {
// Sinon on déplace le sprite verticalement
var sensAngleBuldo = sensRotation(this.sprite.rotation * 180 / Math.PI % 360); //Sens de rotation du Buldo (1=horaire, -1=antihoraire) (0=meme ordonnee)
var HD = dist(0, this.sprite.y + sensAngleBuldo * this.dxAvHotSpot, 0, y);
// Déplacement du sprite
//if (AD < HD) {
this.sprite.y += this.vitesseEnCours * delta;
//} //Si la distance AD est inferieure a la distance HD, le point D est derriere le point A, le Buldo ne se deplace pas
return;
}
}
}; // fin deplaceVtoY
this.checkTarget = function () {
//Choix de la cible : point chaud du rocher ou point chaud arriere du Buldo (du meme camp) poussant (isPushing = true) situe avant dans le tableau pushers
var targetX = this.rocherDestination.sprite.x; //Cible principale par defaut
var dxHotSpotR = this.camp == humanCamp ? this.rocherDestination.dxHotLeftSpot : this.rocherDestination.dxHotRightSpot; //Point chaud du rocher
if (this.rocherDestination.pushers) {
var pushers = this.rocherDestination.pushers;
var pusher = null;
for (var i = 0; i < pushers.length; i++) {
if (pushers[i] != null && pushers[i] == this) {
//Si pas de pousseur du meme camp avant dans le tableau pushers, la cible est le rocher (la liste des pushers est classee en permanence par ordre de distance au rocher)
break;
}
if (pushers[i] != null && pushers[i].camp == this.camp && pushers[i] != this) {
if (pushers[i].isPushing) {
//Si pousseur du meme camp avant dans le tableau pushers, la cible principale est le pousseur precedent
pusher = pushers[i];
}
}
}
if (pusher != null) {
targetX = pusher.sprite.x; //La cible principale est le Buldo allie poussant
dxHotSpotR = pusher.dxBkHotSpot; //Le point chaud est l'arriere du Buldo allie poussant
}
}
return targetX + dxHotSpotR;
}; //fin checkTarget
this.setLigneHtoR = function (rocher) {
this.isMovingR = true; //on indique que le Buldo est en mouvement
this.rocherDestination = rocher; //le point d'ancrage doit s'arreter sur le rocher
//Calcul du sens du deplacement horizontale : 1=droite, -1=gauche
if (rocher && rocher.sprite) {
this.vitesseEnCours = this.sprite.x < rocher.sprite.x ? this.vitessePS : -this.vitessePS; //on donne le sens du deplacement horizontal
} else {
this.vitesseEnCours = 0; // Set to 0 if rocher or rocher.sprite is null to avoid errors
}
}; //fin setLigneHtoR
this.deplaceHtoR = function (delta) {
// Vérifie si le Buldo est en mouvement
if (this.rocherDestination != null || this.rocherPushed != null) {
this.isMovingR = true; // on indique que le Buldo est en mouvement
} else {
this.isMovingR = false; // on indique que le Buldo n'est plus en train de pousser un rocher
this.lastHD = 0; // on remet la dernière direction horizontale à 0
return;
}
if (this.isMovingR) {
if (this.rocherDestination && this.rocherDestination.sprite != null) {
var xTarget = this.checkTarget(); //Abscisse x du point chaud AV du rocher ou du point chaud arriere du Buldo allie poussant
} else {
return; // Exit the function if rocherDestination or its sprite is null
}
var HD = dist(this.sprite.x + this.camp * this.dxAvHotSpot, 0, xTarget, 0); //Distance entre le point chaud AV du sprite et l'abscisse x destination
if (HD <= Math.abs(this.vitesseEnCours * delta)) {
// Si la distance entre l'abscisse du sprite et l'abscisse x destination est inférieure à la vitesse en cours, on atteint l'objectif
this.sprite.x = xTarget - this.camp * this.dxAvHotSpot; // on donne à l'abscisse du sprite la valeur x destination
if (this.rocherDestination != null && !this.isPushing) {
this.isPushing = true; // on indique que le Buldo est en train de pousser un rocher
this.rocherPushed = this.rocherDestination; // on indique le rocher pousse par le Buldo
this.rocherPushed.totalForce += this.camp; // on indique le Buldo qui pousse le rocher
this.rocherPushed.totalBuldos += 1; // on ajoute un pousseur au rocher
this.rocherDestination.isBeingPushed = true; // on indique que le rocher est pousse par un Buldo
if (this.camp == humanCamp && this.rocherDestination.pushedByHuman == null) {
this.rocherDestination.pushedByHuman = this; // on indique le Buldo qui pousse le rocher
}
if (this.camp == ordiCamp && this.rocherDestination.pushedByOrdi == null) {
this.rocherDestination.pushedByOrdi = this; // on indique le Buldo qui pousse le rocher
}
}
} else {
var isTooFar = this.camp == humanCamp ? this.sprite.x > this.rocherDestination.sprite.x : this.sprite.x < this.rocherDestination.sprite.x; //Le Buldo est trop loin du rocher
var AD = dist(this.sprite.x, 0, xTarget, 0); //Distance entre le centre du sprite et l'abscisse x destination
var Bh = this.sprite.x + this.camp * this.dxAvHotSpot; //Abscisse x du point chaud AV du sprite
var AH = dist(this.sprite.x, 0, this.sprite.x + this.camp * this.dxAvHotSpot, 0); //Distance entre le centre du sprite et le point chaud AV
var dxHotSpotR = this.camp == humanCamp ? this.rocherDestination.dxHotLeftSpot : this.rocherDestination.dxHotRightSpot; //Point chaud du rocher
var Rh = this.rocherDestination.sprite.x + dxHotSpotR; //Abscisse x du point chaud du rocher
if (AH <= AD) {
//Securite au cas ou le point destination se trouve entre le centre du sprite et le point chaud AV du sprite
this.sprite.x += this.vitesseEnCours * delta; // Sinon on déplace le sprite horizontalement
} else if (AH > AD || Bh > Rh || isTooFar) {
//Securite au cas ou le buldo depasse le point chaud du rocher
this.sprite.x -= this.vitesseEnCours * delta; //Sinon il recule pour se repositionner derriere
}
}
}
return;
}; // fin deplaceHtoR
this.moveBackToBase = function () {
//Deplacement du Buldo vers sa position de base lors du retour au camp
var sens = this.yBase < this.sprite.y ? 1 : -1; //Calcul du sens de deplacement verticale : 1=bas, -1=haut
sens = this.camp == humanCamp ? sens : -sens; //L'inverse pour les ordis
this.addMoveToStack(typeRotation, sens * 90, 0); //Rotation de 90 degres vers l'ordonnee de la position de base
this.addMoveToStack(typeLigneVtoY, this.xBase, this.yBase); //Deplacement vertical vers la position de base
this.addMoveToStack(typeRotation, sens * 90, 0); //Rotation de 90 degres pour faire face a la route
}; //fin moveBackToBase
this.moveToRock = function (rocher) {
x = this.camp == humanCamp ? x + rocher.dxHotLeftSpot : x + rocher.dxHotRightSpot;
y = rocher.sprite.y;
this.rocherDestination = rocher; //Le buldo a pour destination le sprite rocher cliqué
rocher.pushers.push(this); //On ajoute le Buldo a la liste des Buldos qui poussent le rocher
var sens = this.sprite.y < y ? 1 : -1; //Calcul du sens de rotation : 1=horaire, -1=antihoraire
sens = this.camp == humanCamp ? sens : -sens; //Test Si le Buldo est humain, il doit arriver horizontalement par la gauche (abscisse croissante), sinon par la droite (abscisse decroissante)
sensBase = this.sprite.y == this.yBase ? 1 : -1; //Sens du depart face route depart de sa base ou l'inverse de retour d'une poussee
this.addMoveToStack(typeRotation, sensBase * sens * 90, 0); //Rotation de 90 degres vers l'ordonnee du rocher
this.addMoveToStack(typeLigneVtoY, 0, y); //Deplacement vertical vers l'ordonnee du rocher
this.addMoveToStack(typeRotation, -sens * 90, 0); //Rotation de 90 degres vers le rocher
this.addMoveToStack(typeLigneHtoR, rocher, 0); //Deplacement vers le rocher jusqu'au contact s'il n'est pas detruit avant
this.addMoveToStack(typeRotation, 180, 0); //Demi tour vers le camp de base
this.addMoveToStack(typeLigneHtoX, this.xBase + this.camp * this.dxAvHotSpot, 0); //Deplacement jusqu'au camp de base
}; //fin moveToRock
}); //fin constructor
function sensRotation(angleDegres) {
//03/03/2024//entre 0 et 180: 1, entre 180 et 360: -1, 0:0
var sens = Math.sin(angleDegres * Math.PI / 180);
var signeSens = sens > 0 ? 1 : sens < 0 ? -1 : 0;
return signeSens;
} //fin sensRotation
function dist(x1, y1, x2, y2) {
//fonction distance entre deux points
var dx = x2 - x1;
var dy = y2 - y1;
var distance = Math.sqrt(dx * dx + dy * dy);
return distance;
} //fin distance
// Fonction pour mettre à jour le score du camp humain
function updateScoreHumain(nouveauScore) {
scoreHumainText.setText(nouveauScore);
} //fin updateScoreHumain
// Fonction pour mettre à jour le score du camp ordinateur
function updateScoreOrdi(nouveauScore) {
scoreOrdiText.setText(nouveauScore);
} //fin updateScoreOrdi
function updateScoreTest(nouveauScore) {
scoreFictifText.setText(nouveauScore);
} //fin updateScoreTest
// Fonction pour afficher la victoire d'une equipe en fonction de sa couleur
function afficheVictoire(camp) {
var victoireText = game.addChild(new Text2('WINNER!', {
size: 90,
fill: camp == humanCamp ? 'blue' : 'red'
}));
LK.gui.topLeft.addChild(victoireText);
victoireText.x = camp == humanCamp ? HumanZone.width : game.width / 2;
victoireText.y = ScoreZone.height;
} //fin afficheVictoire
function createSingleRandomRock(size) {
//Creation d'un rocher de taille donnee a ajouter a la liste des rochers
//L'ordonnee est choisie aleatoirement dans la zone de route disponible (ordonneesRestantes)
if (ordonneesRestantes.length == 0) {
return null;
}
var index = Math.floor(Math.random() * ordonneesRestantes.length);
var y = ordonneesRestantes[index];
ordonneesRestantes.splice(index, 1); //On supprime l'ordonnee choisie de la liste des ordonnees restantes
// Choisir une abscisse aléatoire pour le rocher
var zoneMinix = RoadZone.x + 100;
var zoneMaxix = RoadZone.x + RoadZone.width - 100;
var x = Math.random() * (zoneMaxix - zoneMinix) + zoneMinix;
var rock = new Rocher(size, x, y);
rock.sprite.visible = true;
rock.sprite.anchor.set(0.5, 0.5);
if (size == petitRocher) {
rock.dxHotLeftSpot = petitRocherDxHotLeft;
rock.dyHotLeftSpot = petitRocherDyHotLeft;
rock.dxHotRightSpot = petitRocherDxHotRight;
rock.dyHotRightSpot = petitRocherDyHotRight;
}
if (size == moyenRocher) {
rock.dxHotLeftSpot = moyenRocherDxHotLeft;
rock.dyHotLeftSpot = moyenRocherDyHotLeft;
rock.dxHotRightSpot = moyenRocherDxHotRight;
rock.dyHotRightSpot = moyenRocherDyHotRight;
}
if (size == grosRocher) {
rock.dxHotLeftSpot = grosRocherDxHotLeft;
rock.dyHotLeftSpot = grosRocherDyHotLeft;
rock.dxHotRightSpot = grosRocherDxHotRight;
rock.dyHotRightSpot = grosRocherDyHotRight;
}
rock.totalForce = 0;
rock.sprite.on('down', rock.onClickRocherBuldo.bind(rock, buldos));
var rock_sprite = size == petitRocher ? rock.petit_rocher_sprite : size == moyenRocher ? rock.moyen_rocher_sprite : rock.gros_rocher_sprite;
game.addChild(rock_sprite);
return rock;
} //fin createSingleRandomRock
function generateRandomRock(nombreRochers) {
//Calcul de positions aléatoire pour les rochers dans la zone de route
var zoneMiniy = RoadZone.y;
var zoneMaxiy = RoadZone.y + RoadZone.height;
//Calcul des ordonnees possibles pour les rochers entre zoneMiniy + 50 et zoneMaxiy - 50
var ordonneesPossibles = [];
for (var i = zoneMiniy + 50 * 1.5; i < zoneMaxiy - 50 * 1.5; i += 100 * 1.5) {
ordonneesPossibles.push(i);
}
//Securite : si le nombre de rochers demande est superieur au nombre d'ordonnees possibles, on ajuste le nombre de rochers
if (nombreRochers > ordonneesPossibles.length) {
nombreRochers = ordonneesPossibles.length;
}
//Creation des rochers
var rochers = [];
ordonneesRestantes = ordonneesPossibles; //On stocke les ordonnees restantes pour une utilisations ulterieure
for (var i = 0; i < nombreRochers; i++) {
// Choisir une taille de rocher aléatoire
var sizes = [petitRocher, moyenRocher, grosRocher];
var size = sizes[Math.floor(Math.random() * sizes.length)];
var rock = createSingleRandomRock(size);
rochers.push(rock);
}
//On ajoute les evenements de clic sur les sprites rocher
for (var i = 0; i < rochers.length; i++) {
rochers[i].sprite.on('down', rochers[i].onClickRocherBuldo.bind(rochers[i], buldos));
}
ordonneesRestantes = ordonneesPossibles; //On stocke les ordonnees restantes pour une utilisations ulterieure
return rochers;
} //fin generateRandomRock
function createSingleBuldo(x, y, camp) {
//CREATION D'OBJETS A PARTIR DES SPRITES //constructor(x, y, camp)
var buldo = new Buldo(x, y, camp);
buldo.sprite.anchor.set(0.5, 0.5);
buldo.xBase = x;
buldo.yBase = y;
buldo.vitessePS = vitesseBuldo;
buldo.sprite.visible = true;
//On ajoute les evenements de clic sur le sprite Buldo
buldo.sprite.on('down', function () {
buldo.onClickBuldo(buldos);
});
buldo.rocherDestination = null;
buldo.rocherPushed = null;
//On donne leurs hotspots
if (buldo.camp == humanCamp) {
buldo.dxAvHotSpot = buldoRockHotSpotX; //Hotspot avant du sprite (point de contact avec un rocher) décalage par rapport au point d'ancrage
buldo.dyAvHotSpot = buldoRockHotSpotY;
buldo.dxBkHotSpot = buldoRockBkHotSpotX * 2; //Offset du point chaud arriere du sprite (point de contact avec un autre Buldo) décalage par rapport au point d'ancrage
buldo.dyBkHotSpot = buldoRockBkHotSpotY;
} else if (buldo.camp == ordiCamp) {
buldo.dxAvHotSpot = buldoZerHotSpotX; //Hotspot avant du sprite (point de contact avec un rocher) décalage par rapport au point d'ancrage
buldo.dyAvHotSpot = buldoZerHotSpotY;
buldo.dxBkHotSpot = buldoZerBkHotSpotX * 2; //Offset du point chaud arriere du sprite (point de contact avec un autre Buldo) décalage par rapport au point d'ancrage
buldo.dyBkHotSpot = buldoZerBkHotSpotY;
}
//On initialise la position de base
buldo.sprite.x = buldo.xBase;
buldo.sprite.y = buldo.yBase;
var buldo_sprite = buldo.camp == humanCamp ? buldo.buldorock_sprite : buldo.buldozer_sprite;
game.addChild(buldo_sprite);
return buldo;
} //fin createSingleBuldo
function createBuldos() {
//CREATION D'OBJETS A PARTIR DES SPRITES //constructor(x, y, camp)
//var buldoRockTest1 = createSingleBuldo(HumanZone.x + HumanZone.width / 2, HumanZone.y + HumanZone.height / 2, humanCamp); //Position : milieu de la zone humaine, 1/2 de la hauteur
//var buldoRockTest2 = createSingleBuldo(HumanZone.x + HumanZone.width / 2, HumanZone.y + HumanZone.height / 4, humanCamp);
var buldoRock1 = createSingleBuldo(HumanZone.x + HumanZone.width / 2, HumanZone.y + HumanZone.height / 3, humanCamp);
var buldoRock2 = createSingleBuldo(HumanZone.x + HumanZone.width / 2, HumanZone.y + 2 * HumanZone.height / 3, humanCamp);
var buldoZer1 = createSingleBuldo(ComputerZone.x + ComputerZone.width / 2, ComputerZone.y + ComputerZone.height / 3, ordiCamp);
var buldoZer2 = createSingleBuldo(ComputerZone.x + ComputerZone.width / 2, ComputerZone.y + 2 * ComputerZone.height / 3, ordiCamp);
//On stocke les objets dans un tableau
var buldos = [];
//buldos.push(buldoRockTest1);
//buldos.push(buldoRockTest2);
buldos.push(buldoRock1);
buldos.push(buldoRock2);
buldos.push(buldoZer1);
buldos.push(buldoZer2);
//On donne un nom aux objets
buldoRock1.name = 'buldoRock1';
buldoRock2.name = 'buldoRock2';
buldoZer1.name = 'buldoZer1';
buldoZer2.name = 'buldoZer2';
return buldos;
} //fin de createBuldos
var buldos = createBuldos(); //Creation des Buldos
var rochers = generateRandomRock(nbRochers); //création des rochers
// Création de l'objet de texte pour le score du camp humain
var scoreHumainText = new Text2('0', {
size: 90,
fill: "#0000ff",
anchorX: 0.5,
anchorY: 0
});
// Positionnement du score du camp humain dans la zone score au depart de la zone humaine
LK.gui.top.addChild(scoreHumainText); //Point de depart (game.width/2,0)
scoreHumainText.x -= HumanZone.width / 2; //puis decalage vers la gauche
// Création de l'objet de texte pour le score du camp ordinateur
var scoreOrdiText = new Text2('0', {
size: 90,
fill: "#ff0000",
anchorX: 0.5,
anchorY: 0
});
// Positionnement du score du camp ordinateur dans la zone score au depart de la zone ordi
LK.gui.top.addChild(scoreOrdiText); //Point de reference (game.width/2,0)
scoreOrdiText.x += ComputerZone.width / 2; //Puis decalage a droite
// Positionnement au top centre d'un score fictif pour tests
var scoreFictifText = new Text2('0', {
size: 70,
fill: "#00ff00",
anchorX: 0.5,
anchorY: 0
});
//LK.gui.top.addChild(scoreFictifText);
//Creation de l'objet coupe de la victoire a partir de l'image coupeVictoire entre les deux scores
var coupeVictoire = LK.getAsset('coupeVictoire', {
anchorX: 0,
anchorY: 0,
scaleX: 2,
scaleY: 2,
x: game.width / 2,
y: ScoreZone.height / 2
});
game.addChild(coupeVictoire);
// Fonction de rappel pour le tick
function onGameTick() {
// 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 () {
//Lancement du jeu : choix des rochers a pousser pour l'ordinateur
//Si le camp actif est selectionne (-1, 1), mais que la partie n'a pas encore commence (gameHasStarted = false):
//Pour chaque Buldo du camp non actif, on copie la liste des rochers (rochers) et on la trie par ordre de temps de poussee croissant (timeToReach)
//Puis on met dans la pile des rochers cibles du Buldo du camp non actif, tous les rochers de cette liste triee
if (activeCamp != 0 && !gameHasStarted) {
var campNonActif = activeCamp == humanCamp ? ordiCamp : humanCamp;
var buldosCampNonActif = [];
buldos.forEach(function (buldo) {
if (buldo.camp == campNonActif) {
buldosCampNonActif.push(buldo);
}
});
if (buldosCampNonActif) {
buldosCampNonActif.forEach(function (buldo) {
buldo.rochersCibles = []; //On vide la pile des rochers cibles en cas de creation de nouveaux rochers
var rochersCopy = rochers.slice();
rochersCopy.sort(function (a, b) {
return a.timeToReach(buldo.sprite.x, buldo.sprite.y) - b.timeToReach(buldo.sprite.x, buldo.sprite.y);
});
rochersCopy.forEach(function (rocher) {
buldo.rochersCibles.push(rocher);
});
});
}
gameHasStarted = true;
}
//Animation des Buldos
if (buldos) {
buldos.forEach(function (buldo) {
buldo.isMoving = buldo.isMovingH || buldo.isMovingV || buldo.isMovingR || buldo.isRotating;
buldo.checkMovesStack(delta);
});
}
//Animation des rochers
for (var i = 0; i < rochers.length; i++) {
if (rochers[i] == null || rochers[i].sprite.visible == false) {
//si le rocher n'existe pas, ou est sorti de la route on passe au suivant
continue;
}
rochers[i].sortPushers(); //On trie les pousseurs par ordre de distance croissante au rocher
rochers[i].vitesse = rochers[i].totalForce * vitesseBuldo / rochers[i].tailleRocher; //vitesse de déplacement du rocher
if (rochers[i].isBeingPushed) {
rochers[i].checkPushed();
} //Fin de déplacement du rocher
if (rochers[i] && rochers[i].isClicked) {
rochers[i].nbTicksSinceClicked += 1;
if (rochers[i].nbTicksSinceClicked >= nbTicksBeforeStopFlashing) {
rochers[i].isClicked = false;
rochers[i].nbTicksSinceClicked = 0;
rochers[i].sprite.alpha = 1;
} else {
rochers[i].sprite.alpha = Math.abs(Math.sin(LK.ticks / 0.5)); //Clignotement du rocher brievement lorsqu'il est cliqué
}
} //Fin de clignotement du rocher brievement lorsqu'il est clique
}
//Gestion des rochers bloques
var rochersToDestroy = []; //Tableau des potentiels rochers a detruire
if (rochers) {
rochers.forEach(function (rocher) {
if (rocher.vitesse == 0 && rocher.isBeingPushed) {
//Si le rocher est immobilise alors qu'il est pousse
if (buldos) {
var allBuldosPushing = true;
buldos.forEach(function (buldo) {
//et que tous les Buldos sont en train de pousser
if (!buldo.isPushing) {
allBuldosPushing = false;
}
});
if (allBuldosPushing) {
//alors aucun buldo ne peut venir le pousser
rocher.isBlocked = true; //donc le rocher est bloque
}
}
}
//Si le rocher est bloque, on le fait clignoter
if (rocher.isBlocked) {
rocher.sprite.alpha = Math.abs(Math.sin(LK.ticks / 20)); //Clignotement du rocher
//On compte le temps de blocage
rocher.tempoBlocked += 1;
if (rocher.tempoBlocked > timeBeforeSplit) {
//Si le rocher est bloque depuis plus de n ticks on arrete de le faire clignoter
rocher.sprite.alpha = 1;
rocher.tempoBlocked = 0;
rocher.sprite.visible = true;
rochersToDestroy.push(rocher);
}
}
});
//On detruit les rochers bloques apres quelques secondes
//LK.setTimeout(function () { //A garder pour memoire
if (rochersToDestroy.length > 0) {
rochersToDestroy.forEach(function (rocher) {
//Creation de un ou deux rochers de taille inferieure (si possible) a la place du rocher detruit
//Un gros rocher se divise en un moyen et un petit, un moyen en deux petits, un petit est détruit sans se diviser
var x = rocher.sprite.x;
var y = rocher.sprite.y;
var taille = rocher.tailleRocher;
var rocher1 = null;
var rocher2 = null;
if (taille == grosRocher) {
rocher1 = createSingleRandomRock(moyenRocher);
if (rocher1) {
rocher1.sprite.visible = true;
rochers.push(rocher1);
nbRochers += 1;
}
rocher2 = createSingleRandomRock(petitRocher);
if (rocher2) {
rocher2.sprite.visible = true;
rochers.push(rocher2);
nbRochers += 1;
}
}
if (taille == moyenRocher) {
rocher1 = createSingleRandomRock(petitRocher);
if (rocher1) {
rocher1.sprite.visible = true;
rochers.push(rocher1);
nbRochers += 1;
}
rocher2 = createSingleRandomRock(petitRocher);
if (rocher2) {
rocher2.sprite.visible = true;
rochers.push(rocher2);
nbRochers += 1;
}
}
//On supprime le rocher detruit de la liste des rochers
rocher.destroy();
});
gameHasStarted = false; //On remet le jeu en attente de lancement pour que les ordinateurs choisissent de nouveaux rochers a pousser
}
rochersToDestroy = []; //On vide le tableau des rochers a detruire
//}, 4000);
}
//Mise à jour des scores
updateScoreHumain(scoreHumain);
updateScoreOrdi(scoreOrdi);
//updateScoreTest(scoreTest);
//Fin de partie
if (nbRochers <= 0) {
if (scoreHumain >= scoreOrdi) {
afficheVictoire(humanCamp);
} else {
afficheVictoire(ordiCamp);
}
//On attend que tous les Buldos soient revenus a leur position de base pour afficher le message de fin de partie
var allBack = true;
if (buldos) {
buldos.forEach(function (buldo) {
if (buldo.isMoving || buldo.sprite.x != buldo.xBase || buldo.sprite.y != buldo.yBase || !buldo.isOnBase) {
allBack = false;
}
});
}
if (allBack) {
LK.showGameOver();
}
}
});
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.