Skip to content

Commit

Permalink
Amélioration de l'IA des fantômes
Browse files Browse the repository at this point in the history
  • Loading branch information
michel.begoc committed Aug 19, 2009
1 parent 8f6c49c commit e4f0dd3
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 30 deletions.
49 changes: 33 additions & 16 deletions pacman/src/pacman/controlleur/Controlleur.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.IOException;
import java.util.Date;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.Timer;

import pacman.modele.Fantome;
import pacman.modele.Game;
import pacman.modele.Level;
import pacman.modele.Pacman;
import pacman.modele.lang.Direction;
import pacman.modele.lang.LevelListener;
import pacman.modele.lang.PacmanEvent;
import pacman.modele.lang.PacmanListener;
Expand All @@ -22,7 +30,7 @@
public class Controlleur implements ActionListener, KeyListener, LevelListener, PacmanListener{

public static final long serialVersionUID = 1L;
private static final int FREQUENCE_JEU = 50;
private static final int FREQUENCE_JEU = 40;
public static final int TEMPO_DEBUT = 5;//temporisation au début en secondes

private Timer tJeu, tDebutPartie;
Expand All @@ -47,6 +55,20 @@ public Controlleur(){
tJeu = new Timer(FREQUENCE_JEU, this);
tDebutPartie = new Timer(TEMPO_DEBUT * 1000, this);
tDebutPartie.start();

// try {
// AudioInputStream a = AudioSystem.getAudioInputStream(new File("src/pacman/sounds/burzum.wav"));
// DataLine.Info info = new DataLine.Info(Clip.class, a.getFormat());
// Clip c = (Clip) AudioSystem.getLine(info);
// c.open(a);
// c.start();
// } catch (UnsupportedAudioFileException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } catch (LineUnavailableException e) {
// e.printStackTrace();
// }
}

public static void main(String[] args) throws IOException {
Expand All @@ -61,18 +83,13 @@ public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == tJeu){
Date ancDate = dureeBoucle;
dureeBoucle = new Date();
// System.out.print(dureeBoucle.getTime() - ancDate.getTime() + " - ");
// setDebugMessage(this, "délai boucle principale: ", Long.toString(dureeBoucle.getTime()));

if(!pause){
vue.getGameDrawer().corrigerBouchePacman();
game.tour();

game.getPacman().deplacer();
for(Fantome fantome: game.getFantomes()){
fantome.deplacer();
game.getPacman().confronter(fantome);
}

vue.getGameDrawer().repaint();
vue.repaint();
}else if(tempsPause >= 0){
if(tempsPause-- == 0){
pause = false;
Expand All @@ -99,22 +116,22 @@ public void keyTyped(KeyEvent ke) {
game.getPacman().reinitialiser();
vue.getMessager().initPointsFantomes();
vue.getMessager().setMessage("", -1);
}
}
}

public void keyPressed(KeyEvent ke) {
switch(ke.getKeyCode()){
case 39:
game.getPacman().setOrientationSuivante(Pacman.WE);
game.getPacman().setOrientationSuivante(Direction.WE);
break;
case 40:
game.getPacman().setOrientationSuivante(Pacman.NS);
game.getPacman().setOrientationSuivante(Direction.NS);
break;
case 37:
game.getPacman().setOrientationSuivante(Pacman.EW);
game.getPacman().setOrientationSuivante(Direction.EW);
break;
case 38:
game.getPacman().setOrientationSuivante(Pacman.SN);
game.getPacman().setOrientationSuivante(Direction.SN);
}
}

Expand Down Expand Up @@ -187,8 +204,8 @@ public Game getGame() {
return game;
}

public void setDebugMessage(String message){

public void setDebugMessage(Object source, String nom, String message){
vue.getDebugger().addMessage(source, nom, message);
}
}

Expand Down
Binary file modified pacman/src/pacman/maps/level.psd
Binary file not shown.
Binary file modified pacman/src/pacman/maps/levelO.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 15 additions & 10 deletions pacman/src/pacman/vue/GameDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pacman.modele.Fantome;
import pacman.modele.Level;
import pacman.modele.Pacman;
import pacman.modele.lang.Direction;

public class GameDrawer extends JPanel implements ActionListener{
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -71,13 +72,13 @@ private void dessinerPacman(Graphics2D g2){
int angleDepart = Pacman.ANGLE_BOUCHE;
int angle = 270;
switch(pacman.getOrientation()){
case Pacman.NS:
case NS:
angleDepart=Pacman.ANGLE_BOUCHE+270;
break;
case Pacman.EW:
case EW:
angleDepart=Pacman.ANGLE_BOUCHE+180;
break;
case Pacman.SN:
case SN:
angleDepart=Pacman.ANGLE_BOUCHE+90;
}

Expand Down Expand Up @@ -135,15 +136,19 @@ private void dessinerFantomes(Graphics2D g2){
int yPupilles = y+quart+blanc/4;

if(!fantome.getBurstMode() || !fantome.estHabille()){
if(fantome.getOrientation() == Fantome.WE){
switch(fantome.getOrientation()){
case WE:
xPupilleDroite += pupille/2;
xPupilleGauche += pupille/2;
}else if(fantome.getOrientation() == Fantome.EW){
break;
case EW:
xPupilleDroite -= pupille/2;
xPupilleGauche -= pupille/2;
}else if(fantome.getOrientation() == Fantome.NS){
break;
case NS:
yPupilles += pupille/2;
}else if(fantome.getOrientation() == Fantome.SN){
break;
case SN:
yPupilles -= pupille/2;
}
}
Expand Down Expand Up @@ -178,17 +183,17 @@ private void dessinerGommes(int x, int y, Graphics2D g){
public void corrigerBouchePacman(){
if(modifAngle <= 0 || modifAngle >= Pacman.ANGLE_BOUCHE)
valModifAngle *= -1;
modifAngle += valModifAngle;
modifAngle += valModifAngle;
}

public void resetBouchePacman(){
modifAngle = 0;
valModifAngle = -10;
valModifAngle = -10;
}

public void setClignotant(int delay){
tClignotant.setDelay(delay);
tClignotant.start();
tClignotant.restart();
clignotant = true;
}

Expand Down
2 changes: 1 addition & 1 deletion pacman/src/pacman/vue/Messager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Messager(Vue parent){
messages.add("<nom> n'a plus que ses yeux pour pleurer =D");
messages.add("Un petit bout de <nom> t'es resté entre les dents =/");
messages.add("<nom> a un petit goût de guimauve :P");
messages.add("<nom> retourne se rabiller xD");
messages.add("<nom> peut retourner se rabiller xD");
}

public Messager(Vue parent, boolean debug){
Expand Down
15 changes: 12 additions & 3 deletions pacman/src/pacman/vue/Vue.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pacman.controlleur.Controlleur;
import pacman.modele.Game;
import pacman.modele.Level;
import perso.utils.Debug;

public class Vue extends JFrame {

Expand All @@ -26,6 +27,7 @@ public class Vue extends JFrame {
private GameDrawer gameDrawer;
private Messager messager;
private LevelDrawer levelDrawer;
private Debug debugger;

public Vue(Controlleur controlleur){
this(controlleur, false);
Expand All @@ -34,6 +36,7 @@ public Vue(Controlleur controlleur){
public Vue(Controlleur controlleur, boolean debug){
this.controlleur = controlleur;

setTitle("Pacman java");
// this.setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
Expand All @@ -51,10 +54,12 @@ public Vue(Controlleur controlleur, boolean debug){
gameDrawer = new GameDrawer(this);
levelDrawer = new LevelDrawer(this);
messager = new Messager(this, debug);
debugger = new Debug(200, 200);

this.getLayeredPane().add(gameDrawer, new Integer(-2));
this.getLayeredPane().add(levelDrawer, new Integer(-3));
this.getLayeredPane().add(messager, new Integer(-1));
this.getLayeredPane().add(debugger, new Integer(-10));
this.getLayeredPane().add(gameDrawer, new Integer(-100));
this.getLayeredPane().add(levelDrawer, new Integer(-200));
this.getLayeredPane().add(messager, new Integer(-50));
}

public Game getGame(){
Expand All @@ -76,4 +81,8 @@ public Messager getMessager() {
public LevelDrawer getLevelDrawer() {
return levelDrawer;
}

public Debug getDebugger(){
return debugger;
}
}

0 comments on commit e4f0dd3

Please sign in to comment.