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.

73 lines
1.7 KiB

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