From 35e386cc2983f5fd97e2058931affc24b7f62e20 Mon Sep 17 00:00:00 2001 From: Victor Brun Date: Wed, 3 May 2023 16:02:01 +0200 Subject: [PATCH] pastilles + bouger --- source/Jeu.ts | 25 ++++++++++++++++++++++--- source/Pacman.ts | 44 ++++++++++++++++++++++++++++++-------------- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/source/Jeu.ts b/source/Jeu.ts index 158b14d..4d336c6 100644 --- a/source/Jeu.ts +++ b/source/Jeu.ts @@ -10,6 +10,8 @@ class Jeu extends Scene { public wall_ : Sprite; public pas_ : number; public pacman_ : Pacman; + public noisette_ : Sprite; + public pastilles_ : Array>; @@ -18,6 +20,7 @@ class Jeu extends Scene { super(element,false); /* Ecrire ici le code qui initialise la scene. */ 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_[8] = [1 ,2 ,2 ,2 ,1 ,2 ,2 ,2 ,2 ,1]; this.carte_[9] = [1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1]; - } private dessinerLabyrinthe(){ for(let i = 0 ; i {this.deplacer(event)};; + this.px_ = px; + this.py_ = py; + this.ecouteurDeplacer = (event : KeyboardEvent) => {this.deplacer(event)}; + this.getElement().style.zIndex = "2"; } public haut(){ @@ -20,6 +21,8 @@ class Pacman extends Sprite { }else{ 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_); } } public bas(){ @@ -28,6 +31,8 @@ class Pacman extends Sprite { }else{ 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_); } } public gauche(){ @@ -36,6 +41,8 @@ class Pacman extends Sprite { }else{ 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_); } } public droite(){ @@ -44,21 +51,26 @@ class Pacman extends Sprite { }else{ 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_); } } private deplacer(event : KeyboardEvent){ - if(event.key == "ArrowLeft"){ + if(this.estArriver() == false){ + if(event.key == "ArrowLeft"){ 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(){ @@ -68,4 +80,8 @@ class Pacman extends Sprite { public figer(){ window.removeEventListener("keydown", this.ecouteurDeplacer); } + + public estArriver(){ + return this.scene_.carte_[this.py_][this.px_] == 9; + } } \ No newline at end of file