pastilles + bouger

master
Victor BRUN 1 year ago
parent 9e387a7832
commit 35e386cc29

@ -10,6 +10,8 @@ class Jeu extends Scene {
public wall_ : Sprite;
public pas_ : number;
public pacman_ : Pacman;
public noisette_ : Sprite;
public pastilles_ : Array<Array<Sprite>>;
@ -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.carte_.length; i++){
this.pastilles_[i] = [];
for(let j = 0 ; j<this.carte_[i].length; j++){
if(this.carte_[i][j] == 1){
this.wall_ = new Sprite(document.createElement("img"));
@ -46,13 +49,28 @@ private dessinerLabyrinthe(){
this.appendChild(this.wall_);
}
if (this.carte_[i][j] == 8){
this.pacman_ = new Pacman(this,document.createElement("img"),4,7);
this.pacman_ = new Pacman(this,document.createElement("img"),i,j);
this.pacman_.setImage("Squirrel.png",32,32);
this.pacman_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.pacman_);
}
if (this.carte_[i][j] == 2){
this.noisette_ = new Sprite(document.createElement("img"));
this.noisette_.setImage("noisette.png",32,32);
this.noisette_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.noisette_);
}
if(this.carte_[i][j] == 2){
this.pastilles_[i][j] = this.noisette_;
} else {
this.pastilles_[i][j] = null;
}
}
}
}console.log(this.pastilles_);
}
public retirePastille(){
}
//--------------------------------------------------------------------------------------------start
public override start() {
@ -61,6 +79,7 @@ private dessinerLabyrinthe(){
this.initialiserCarte();
this.dessinerLabyrinthe();
this.pacman_.animer();
this.pacman_.estArriver();
}
//--------------------------------------------------------------------------------------------pause

@ -6,12 +6,13 @@ class Pacman extends Sprite {
public px_ : number;
public py_ : number;
//Constructeur
public constructor(scene : Jeu,element : HTMLElement, py_ : number, px_ : number){
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)};;
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;
}
}
Loading…
Cancel
Save