master
Victor BRUN 1 year ago
parent 9ee942037d
commit cca8533f05

@ -7,6 +7,7 @@
<script src="Sprite.js"></script>
<script src="Scene.js"></script>
<script src="Jeu.js"></script>
<script src="Pacman.js"></script>
<!-- Inclure ici les fichiers JavaScript necessaires a la scene. -->
<script>
let scene;

@ -9,6 +9,9 @@ class Jeu extends Scene {
public carte_ : Array<Array<number>>;
public wall_ : Sprite;
public pas_ : number;
public px : number;
public py : number;
public pacman_ : Pacman;
@ -17,7 +20,8 @@ class Jeu extends Scene {
super(element,false);
/* Ecrire ici le code qui initialise la scene. */
this.pas_ = 32;
this.px = 4;
this.py = 7;
}
@ -33,6 +37,7 @@ 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(){
@ -44,6 +49,12 @@ private dessinerLabyrinthe(){
this.wall_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.wall_);
}
if (this.carte_[i][j] == 8){
this.pacman_ = new Pacman(this,document.createElement("img"));
this.pacman_.setImage("Squirrel.png",32,32);
this.pacman_.setXY(this.pas_*j,this.pas_*i);
this.appendChild(this.pacman_);
}
}
}
}

@ -0,0 +1,58 @@
class Pacman extends Sprite {
//Attributs
public scene_ : Jeu;
private ecouteurDeplacer : any;
//Constructeur
public constructor(scene : Jeu,element : HTMLElement){
super(element);
this.scene_ = scene;
this.ecouteurDeplacer
}
public haut(){
if(this.scene_.carte_[this.scene_.py-1][this.scene_.px] == 1){
}else{
this.setXY(this.getX()-this.scene_.pas_,this.getY());
}
}
public bas(){
if(this.scene_.carte_[this.scene_.py+1][this.scene_.px] == 1){
}else{
this.setXY(this.getX()+this.scene_.pas_,this.getY());
}
}
public gauche(){
if(this.scene_.carte_[this.scene_.py][this.scene_.px-1] == 1){
}else{
this.setXY(this.getX(),this.getY()-this.scene_.pas_);
}
}
public droite(){
if(this.scene_.carte_[this.scene_.py+1][this.scene_.px+1] == 1){
}else{
this.setXY(this.getX(),this.getY()+this.scene_.pas_);
}
}
private deplacer(event : KeyboardEvent){
if(event.key == "ArrowLeft"){
this.gauche();
}
if(event.key == "ArrowRight"){
this.droite();
}
if(event.key == "ArrowDown"){
this.haut();
}
if(event.key == "ArrowLeft"){
this.bas();
}
}
public animer(){
}
}
Loading…
Cancel
Save