|
|
|
@ -3,39 +3,49 @@ class Pacman extends Sprite {
|
|
|
|
|
//Attributs
|
|
|
|
|
public scene_ : Jeu;
|
|
|
|
|
private ecouteurDeplacer : any;
|
|
|
|
|
public px_ : number;
|
|
|
|
|
public py_ : number;
|
|
|
|
|
//Constructeur
|
|
|
|
|
public constructor(scene : Jeu,element : HTMLElement){
|
|
|
|
|
public constructor(scene : Jeu,element : HTMLElement, py_ : number, px_ : number){
|
|
|
|
|
super(element);
|
|
|
|
|
this.scene_ = scene;
|
|
|
|
|
this.ecouteurDeplacer
|
|
|
|
|
this.px_ = 4;
|
|
|
|
|
this.py_ = 7;
|
|
|
|
|
this.ecouteurDeplacer = (event : KeyboardEvent) => {this.deplacer(event)};;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public haut(){
|
|
|
|
|
if(this.scene_.carte_[this.scene_.py-1][this.scene_.px] == 1){
|
|
|
|
|
this.py_ = this.py_-1;
|
|
|
|
|
this.px_ = this.px_-1;
|
|
|
|
|
if(this.scene_.carte_[this.py_-1][this.px_] == 1){
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
this.setXY(this.getX()-this.scene_.pas_,this.getY());
|
|
|
|
|
this.py_ = this.py_-1;
|
|
|
|
|
this.setXY(this.getX(),this.getY()-this.scene_.pas_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public bas(){
|
|
|
|
|
if(this.scene_.carte_[this.scene_.py+1][this.scene_.px] == 1){
|
|
|
|
|
if(this.scene_.carte_[this.py_+1][this.px_] == 1){
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
this.setXY(this.getX()+this.scene_.pas_,this.getY());
|
|
|
|
|
this.py_ = this.py_+1;
|
|
|
|
|
this.setXY(this.getX(),this.getY()+this.scene_.pas_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public gauche(){
|
|
|
|
|
if(this.scene_.carte_[this.scene_.py][this.scene_.px-1] == 1){
|
|
|
|
|
if(this.scene_.carte_[this.py_][this.px_-1] == 1){
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
this.setXY(this.getX(),this.getY()-this.scene_.pas_);
|
|
|
|
|
this.px_ = this.px_-1;
|
|
|
|
|
this.setXY(this.getX()-this.scene_.pas_,this.getY());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public droite(){
|
|
|
|
|
if(this.scene_.carte_[this.scene_.py+1][this.scene_.px+1] == 1){
|
|
|
|
|
if(this.scene_.carte_[this.py_][this.px_+1] == 1){
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
this.setXY(this.getX(),this.getY()+this.scene_.pas_);
|
|
|
|
|
this.px_ = this.px_+1;
|
|
|
|
|
this.setXY(this.getX()+this.scene_.pas_,this.getY());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private deplacer(event : KeyboardEvent){
|
|
|
|
@ -46,13 +56,18 @@ class Pacman extends Sprite {
|
|
|
|
|
this.droite();
|
|
|
|
|
}
|
|
|
|
|
if(event.key == "ArrowDown"){
|
|
|
|
|
this.haut();
|
|
|
|
|
}
|
|
|
|
|
if(event.key == "ArrowLeft"){
|
|
|
|
|
this.bas();
|
|
|
|
|
}
|
|
|
|
|
if(event.key == "ArrowUp"){
|
|
|
|
|
this.haut();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public animer(){
|
|
|
|
|
window.addEventListener("keydown", this.ecouteurDeplacer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public figer(){
|
|
|
|
|
window.removeEventListener("keydown", this.ecouteurDeplacer);
|
|
|
|
|
}
|
|
|
|
|
}
|