You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.2 KiB

//==================================================================================================
// ANIMATION AVEC TYPESCRIPT Jeu.ts
//==================================================================================================
// Classe J e u //---------------------------------------------------------------------------------
class Jeu extends Scene {
//----------------------------------------------------------------------------------------Attributs
/* Declarer ici les attributs de la scene. */
public carte_ : Array<Array<number>>;
public wall_ : Sprite;
public pas_ : number;
public rat_ : Rat;
public noisette_ : Sprite;
public pastilles_ : Array<Array<Sprite>>;
//-------------------------------------------------------------------------------------Constructeur
public constructor(element : HTMLElement) {
super(element,false);
/* Ecrire ici le code qui initialise la scene. */
this.pas_ = 32;
this.pastilles_ = [];
}
private initialiserCarte(){
// this.carte_ = [];
// this.carte_[0] = [1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1];
// this.carte_[1] = [1 ,3 ,2 ,2 ,2 ,1 ,3 ,2 ,2 ,1];
// this.carte_[2] = [1 ,1 ,2 ,1 ,1 ,1 ,2 ,1 ,2 ,1];
// this.carte_[3] = [1 ,2 ,2 ,2 ,1 ,1 ,2 ,1 ,1 ,1];
// this.carte_[4] = [1 ,2 ,1 ,1 ,2 ,2 ,2 ,1 ,2 ,9];
// this.carte_[5] = [1 ,2 ,2 ,2 ,2 ,1 ,2 ,1 ,2 ,1];
// this.carte_[6] = [1 ,2 ,1 ,8 ,1 ,1 ,2 ,2 ,2 ,1];
// this.carte_[7] = [1 ,2 ,1 ,2 ,1 ,1 ,2 ,1 ,1 ,1];
// this.carte_[8] = [1 ,2 ,2 ,2 ,1 ,2 ,2 ,2 ,2 ,1];
// this.carte_[9] = [1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1];
this.carte_ = [];
this.carte_[0] = [1 ,1 ,1 ,0 ,0 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,0 ,1 ,1 ,1 ,1 ,1 ,0 ,0 ];
this.carte_[1] = [1 ,8 ,1 ,0 ,0 ,1 ,2 ,2 ,2 ,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,1 ,1 ,2 ,9 ,1 ];
this.carte_[13] = [0 ,0 ,1 ,2 ,2 ,2 ,2 ,2 ,2 ,1 ,1 ,3 ,2 ,2 ,1 ,0 ,1 ,1 ,1 ,1 ];
this.carte_[14] = [0 ,0 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,0 ,0 ,0 ,0 ,0 ];
}
private dessinerLabyrinthe(){
for(let i = 0 ; i<this.carte_.length; i++){
this.pastilles_[i] = [];
for(let j = 0 ; j<this.carte_[i].length; j++){
if(this.carte_[i][j] == 1){
this.wall_ = new Sprite(document.createElement("img"));
this.wall_.setImage("mur.jpg",32,32);
this.wall_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.wall_);
}
if (this.carte_[i][j] == 8){
this.rat_ = new Rat(this,document.createElement("img"),i,j);
this.rat_.setImage("rat.png",32,32);
this.rat_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.rat_);
}
if (this.carte_[i][j] == 2){
this.noisette_ = new Sprite(document.createElement("img"));
this.noisette_.setImage("fromage.png",32,32);
this.noisette_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.noisette_);
}
if (this.carte_[i][j] == 3){
this.noisette_ = new Sprite(document.createElement("img"));
this.noisette_.setImage("fraise.png",32,32);
this.noisette_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.noisette_);
}
if(this.carte_[i][j] == 2){
this.pastilles_[i][j] = this.noisette_;
} else {
this.pastilles_[i][j] = null;
}
}
}console.log(this.pastilles_);
}
public retirePastille(){
}
//--------------------------------------------------------------------------------------------start
public override start() {
/* Ecrire ici le code qui demarre la scene. */
console.log(this.carte_);
this.initialiserCarte();
this.dessinerLabyrinthe();
this.rat_.animer();
this.rat_.estArriver();
}
//--------------------------------------------------------------------------------------------pause
public override pause() {
/* Ecrire ici le code qui met la scene en pause. */
this.rat_.figer();
}
//------------------------------------------------------------------------------------------unpause
public override unpause() {
/* Ecrire ici le code qui sort la scene de la pause. */
}
//--------------------------------------------------------------------------------------------clean
public override clean() {
/* Ecrire ici le code qui nettoie la scene en vue d'un redemarrage. */
}
}
// Fin //-------------------------------------------------------------------------------------------