1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| public void verifierTouches(){
SDLEvent e = null;
try{
e = SDLEvent.pollEvent();
}catch(Exception ee){
System.out.println(ee);
}
if (e!=null){
if (e.getType()==SDLEvent.SDL_KEYDOWN){
SDLKeyboardEvent e2 = (SDLKeyboardEvent)e;
String s = e.getKeyName(e2.getSym());
if (lesTouchesJoueur1.containsValue(s)) {
if (lesTouchesJoueur1.get("UP").equals(s)) persoJoueur1.action("GO","UP");
if (lesTouchesJoueur1.get("RIGHT").equals(s)) persoJoueur1.action("GO","RIGHT");
if (lesTouchesJoueur1.get("DOWN").equals(s)) persoJoueur1.action("GO","DOWN");
if (lesTouchesJoueur1.get("LEFT").equals(s)) persoJoueur1.action("GO","LEFT");
}
}
if (e.getType()==SDLEvent.SDL_JOYBUTTONDOWN){
SDLJoyButtonEvent e2 = (SDLJoyButtonEvent)e;
if (e2.getWhich()==0) {
if (e2.getButton()==0) persoJoueur1.action("GO","UP");
if (e2.getButton()==1) persoJoueur1.action("GO","RIGHT");
if (e2.getButton()==2) persoJoueur1.action("GO","DOWN");
if (e2.getButton()==3) persoJoueur1.action("GO","LEFT");
}
}
if (e.getType()==SDLEvent.SDL_KEYUP){
SDLKeyboardEvent e2 = (SDLKeyboardEvent)e;
String s = e.getKeyName(e2.getSym());
if (lesTouchesJoueur1.containsValue(s)) {
if (lesTouchesJoueur1.get("UP").equals(s)) persoJoueur1.action("STOP","UP");
if (lesTouchesJoueur1.get("RIGHT").equals(s)) persoJoueur1.action("STOP","RIGHT");
if (lesTouchesJoueur1.get("DOWN").equals(s)) persoJoueur1.action("STOP","DOWN");
if (lesTouchesJoueur1.get("LEFT").equals(s)) persoJoueur1.action("STOP","LEFT");
}
}
if (e.getType()==SDLEvent.SDL_JOYBUTTONUP){
SDLJoyButtonEvent e2 = (SDLJoyButtonEvent)e;
if (e2.getWhich()==0) {
if (e2.getButton()==9) finJeu=true;
if (e2.getButton()==0) persoJoueur1.action("STOP","UP");
if (e2.getButton()==1) persoJoueur1.action("STOP","RIGHT");
if (e2.getButton()==2) persoJoueur1.action("STOP","DOWN");
if (e2.getButton()==3) persoJoueur1.action("STOP","LEFT");
}
}
if (e.getType()==SDLEvent.SDL_JOYAXISMOTION){
SDLJoyAxisEvent e2 = (SDLJoyAxisEvent)e;
if (e2.getWhich()==0) {
if (e2.getAxis() == 1 && e2.getValue() > -5000) persoJoueur1.action("STOP","UP");
if (e2.getAxis() == 0 && e2.getValue() < 5000) persoJoueur1.action("STOP","RIGHT");
if (e2.getAxis() == 1 && e2.getValue() < 5000) persoJoueur1.action("STOP","DOWN");
if (e2.getAxis() == 0 && e2.getValue() > -5000) persoJoueur1.action("STOP","LEFT");
if (!persoJoueur1.isMoving("UP")) if (e2.getAxis() == 1 && e2.getValue() < -5000) persoJoueur1.action("GO","UP");
if (!persoJoueur1.isMoving("RIGHT")) if (e2.getAxis() == 0 && e2.getValue() > 5000) persoJoueur1.action("GO","RIGHT");
if (!persoJoueur1.isMoving("DOWN")) if (e2.getAxis() == 1 && e2.getValue() > 5000) persoJoueur1.action("GO","DOWN");
if (!persoJoueur1.isMoving("LEFT")) if (e2.getAxis() == 0 && e2.getValue() < -5000) persoJoueur1.action("GO","LEFT");
}
}
}
} |
Partager