work in progress avancement du perso

master
Victor BRUN 2 years ago
parent cca8533f05
commit d419c4d33e

@ -9,8 +9,6 @@ class Jeu extends Scene {
public carte_ : Array<Array<number>>;
public wall_ : Sprite;
public pas_ : number;
public px : number;
public py : number;
public pacman_ : Pacman;
@ -19,9 +17,7 @@ class Jeu extends Scene {
public constructor(element : HTMLElement) {
super(element,false);
/* Ecrire ici le code qui initialise la scene. */
this.pas_ = 32;
this.px = 4;
this.py = 7;
this.pas_ = 32;
}
@ -50,7 +46,7 @@ private dessinerLabyrinthe(){
this.appendChild(this.wall_);
}
if (this.carte_[i][j] == 8){
this.pacman_ = new Pacman(this,document.createElement("img"));
this.pacman_ = new Pacman(this,document.createElement("img"),4,7);
this.pacman_.setImage("Squirrel.png",32,32);
this.pacman_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.pacman_);
@ -64,11 +60,13 @@ private dessinerLabyrinthe(){
console.log(this.carte_);
this.initialiserCarte();
this.dessinerLabyrinthe();
this.pacman_.animer();
}
//--------------------------------------------------------------------------------------------pause
public override pause() {
/* Ecrire ici le code qui met la scene en pause. */
this.pacman_.figer();
}
//------------------------------------------------------------------------------------------unpause

@ -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);
}
}
Loading…
Cancel
Save