pastilles + bouger

master
Victor BRUN 1 year ago
parent 9e387a7832
commit 35e386cc29

@ -10,6 +10,8 @@ class Jeu extends Scene {
public wall_ : Sprite; public wall_ : Sprite;
public pas_ : number; public pas_ : number;
public pacman_ : Pacman; public pacman_ : Pacman;
public noisette_ : Sprite;
public pastilles_ : Array<Array<Sprite>>;
@ -18,6 +20,7 @@ class Jeu extends Scene {
super(element,false); super(element,false);
/* Ecrire ici le code qui initialise la scene. */ /* Ecrire ici le code qui initialise la scene. */
this.pas_ = 32; this.pas_ = 32;
this.pastilles_ = [];
} }
@ -33,11 +36,11 @@ private initialiserCarte(){
this.carte_[7] = [1 ,2 ,1 ,2 ,1 ,1 ,2 ,1 ,1 ,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_[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_[9] = [1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1];
} }
private dessinerLabyrinthe(){ private dessinerLabyrinthe(){
for(let i = 0 ; i<this.carte_.length; i++){ for(let i = 0 ; i<this.carte_.length; i++){
this.pastilles_[i] = [];
for(let j = 0 ; j<this.carte_[i].length; j++){ for(let j = 0 ; j<this.carte_[i].length; j++){
if(this.carte_[i][j] == 1){ if(this.carte_[i][j] == 1){
this.wall_ = new Sprite(document.createElement("img")); this.wall_ = new Sprite(document.createElement("img"));
@ -46,13 +49,28 @@ private dessinerLabyrinthe(){
this.appendChild(this.wall_); this.appendChild(this.wall_);
} }
if (this.carte_[i][j] == 8){ if (this.carte_[i][j] == 8){
this.pacman_ = new Pacman(this,document.createElement("img"),4,7); this.pacman_ = new Pacman(this,document.createElement("img"),i,j);
this.pacman_.setImage("Squirrel.png",32,32); this.pacman_.setImage("Squirrel.png",32,32);
this.pacman_.setXY(this.pas_*j,this.pas_*i); this.pacman_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.pacman_); this.appendChild(this.pacman_);
} }
if (this.carte_[i][j] == 2){
this.noisette_ = new Sprite(document.createElement("img"));
this.noisette_.setImage("noisette.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 //--------------------------------------------------------------------------------------------start
public override start() { public override start() {
@ -61,6 +79,7 @@ private dessinerLabyrinthe(){
this.initialiserCarte(); this.initialiserCarte();
this.dessinerLabyrinthe(); this.dessinerLabyrinthe();
this.pacman_.animer(); this.pacman_.animer();
this.pacman_.estArriver();
} }
//--------------------------------------------------------------------------------------------pause //--------------------------------------------------------------------------------------------pause

@ -6,12 +6,13 @@ class Pacman extends Sprite {
public px_ : number; public px_ : number;
public py_ : number; public py_ : number;
//Constructeur //Constructeur
public constructor(scene : Jeu,element : HTMLElement, py_ : number, px_ : number){ public constructor(scene : Jeu,element : HTMLElement, py : number, px : number){
super(element); super(element);
this.scene_ = scene; this.scene_ = scene;
this.px_ = 4; this.px_ = px;
this.py_ = 7; this.py_ = py;
this.ecouteurDeplacer = (event : KeyboardEvent) => {this.deplacer(event)};; this.ecouteurDeplacer = (event : KeyboardEvent) => {this.deplacer(event)};
this.getElement().style.zIndex = "2";
} }
public haut(){ public haut(){
@ -20,6 +21,8 @@ class Pacman extends Sprite {
}else{ }else{
this.py_ = this.py_-1; this.py_ = this.py_-1;
this.setXY(this.getX(),this.getY()-this.scene_.pas_); this.setXY(this.getX(),this.getY()-this.scene_.pas_);
this.getElement().style.transform = 'rotate(-90deg)';
// this.setXY(this.px_*this.scene_.pas_,this.py_*this.scene_.pas_);
} }
} }
public bas(){ public bas(){
@ -28,6 +31,8 @@ class Pacman extends Sprite {
}else{ }else{
this.py_ = this.py_+1; this.py_ = this.py_+1;
this.setXY(this.getX(),this.getY()+this.scene_.pas_); this.setXY(this.getX(),this.getY()+this.scene_.pas_);
this.getElement().style.transform = 'rotate(90deg)';
// this.setXY(this.px_*this.scene_.pas_,this.py_*this.scene_.pas_);
} }
} }
public gauche(){ public gauche(){
@ -36,6 +41,8 @@ class Pacman extends Sprite {
}else{ }else{
this.px_ = this.px_-1; this.px_ = this.px_-1;
this.setXY(this.getX()-this.scene_.pas_,this.getY()); this.setXY(this.getX()-this.scene_.pas_,this.getY());
this.getElement().style.transform = 'rotate(90deg) scale(-1,1)';
// this.setXY(this.px_*this.scene_.pas_,this.py_*this.scene_.pas_);
} }
} }
public droite(){ public droite(){
@ -44,21 +51,26 @@ class Pacman extends Sprite {
}else{ }else{
this.px_ = this.px_+1; this.px_ = this.px_+1;
this.setXY(this.getX()+this.scene_.pas_,this.getY()); this.setXY(this.getX()+this.scene_.pas_,this.getY());
this.getElement().style.transform = 'rotate(90deg) scale(1,1)';
// this.setXY(this.px_*this.scene_.pas_,this.py_*this.scene_.pas_);
} }
} }
private deplacer(event : KeyboardEvent){ private deplacer(event : KeyboardEvent){
if(event.key == "ArrowLeft"){ if(this.estArriver() == false){
if(event.key == "ArrowLeft"){
this.gauche(); this.gauche();
}
if(event.key == "ArrowRight"){
this.droite();
}
if(event.key == "ArrowDown"){
this.bas();
}
if(event.key == "ArrowUp"){
this.haut();
}
} }
if(event.key == "ArrowRight"){
this.droite();
}
if(event.key == "ArrowDown"){
this.bas();
}
if(event.key == "ArrowUp"){
this.haut();
}
} }
public animer(){ public animer(){
@ -68,4 +80,8 @@ class Pacman extends Sprite {
public figer(){ public figer(){
window.removeEventListener("keydown", this.ecouteurDeplacer); window.removeEventListener("keydown", this.ecouteurDeplacer);
} }
public estArriver(){
return this.scene_.carte_[this.py_][this.px_] == 9;
}
} }
Loading…
Cancel
Save