From 03e8f828030b125adcd58bf18f97cf584a22caf1 Mon Sep 17 00:00:00 2001 From: Victor Brun Date: Sat, 20 May 2023 18:15:51 +0100 Subject: [PATCH] deplacement fonctionnelle --- source/Rat.ts | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/source/Rat.ts b/source/Rat.ts index 467da4e..727905a 100644 --- a/source/Rat.ts +++ b/source/Rat.ts @@ -15,44 +15,36 @@ class Rat extends Sprite { this.getElement().style.zIndex = "2"; } - public haut(){ - if(this.scene_.carte_[this.py_-1][this.px_] == 1){ - - }else{ + async haut(){ + while(this.scene_.carte_[this.py_-1][this.px_] != 1){ this.py_ = this.py_-1; 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_); + await new Promise(resolve => setTimeout(resolve, 20)); } } - public bas(){ - if(this.scene_.carte_[this.py_+1][this.px_] == 1){ - - }else{ + async bas(){ + while(this.scene_.carte_[this.py_+1][this.px_] != 1){ this.py_ = this.py_+1; 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_); + await new Promise(resolve => setTimeout(resolve, 20)); } } - public gauche(){ - if(this.scene_.carte_[this.py_][this.px_-1] == 1){ - - }else{ + async gauche(){ + while(this.scene_.carte_[this.py_][this.px_-1] != 1){ this.px_ = this.px_-1; 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_); + await new Promise(resolve => setTimeout(resolve, 20)); } } - public droite(){ - if(this.scene_.carte_[this.py_][this.px_+1] == 1){ - - }else{ + async droite(){ + while(this.scene_.carte_[this.py_][this.px_+1] != 1){ this.px_ = this.px_+1; 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_); + await new Promise(resolve => setTimeout(resolve, 20)); } } private deplacer(event : KeyboardEvent){ @@ -83,5 +75,5 @@ class Rat extends Sprite { public estArriver(){ return this.scene_.carte_[this.py_][this.px_] == 9; - } + } } \ No newline at end of file