|
|
|
|
package Main;
|
|
|
|
|
//Importe
|
|
|
|
|
import org.newdawn.slick.AppGameContainer;
|
|
|
|
|
import org.newdawn.slick.BasicGame;
|
|
|
|
|
import org.newdawn.slick.GameContainer;
|
|
|
|
|
import org.newdawn.slick.Graphics;
|
|
|
|
|
import org.newdawn.slick.Input;//f<>r Tastennutzung
|
|
|
|
|
import org.newdawn.slick.SlickException;
|
|
|
|
|
|
|
|
|
|
public class JnP extends BasicGame {
|
|
|
|
|
|
|
|
|
|
//Main Klasse des Games
|
|
|
|
|
public JnP() {
|
|
|
|
|
super("Jump 'n' Pong");
|
|
|
|
|
}
|
|
|
|
|
//Objekterstellungen
|
|
|
|
|
Panel panel;
|
|
|
|
|
Level level;
|
|
|
|
|
UserInterface hud;
|
|
|
|
|
Invader invader;
|
|
|
|
|
Player protector;
|
|
|
|
|
State gameState;
|
|
|
|
|
Menu menu;
|
|
|
|
|
|
|
|
|
|
float waiter;//Zeit-Laufvariable
|
|
|
|
|
|
|
|
|
|
public void init(GameContainer gc) throws SlickException {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
//Objekterstellung (au<61>er Ball -> Erstellung in der Invader-Klasse
|
|
|
|
|
hud = new UserInterface();
|
|
|
|
|
invader = new Invader();
|
|
|
|
|
protector = new Player();
|
|
|
|
|
level = new Level();
|
|
|
|
|
gameState = new State();
|
|
|
|
|
menu = new Menu();
|
|
|
|
|
panel = new Panel();
|
|
|
|
|
|
|
|
|
|
//Initialisierung
|
|
|
|
|
gameState.init(gc);
|
|
|
|
|
menu.init(gc, gameState);
|
|
|
|
|
level.init(gc,invader,protector,hud,gameState,panel,waiter);//Initialisierung mit Vererbung aller Objekte
|
|
|
|
|
panel.init(gc,gameState,1);// Initialisierung + Angabe des Startlevels
|
|
|
|
|
hud.init(gc,gameState);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
waiter = 0; //Setzung der Zeit zu Begin
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
|
|
public void update(GameContainer gc, int delta) throws SlickException {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
float _delta = delta /1000f;
|
|
|
|
|
this.waiter += _delta; //Zeit l<>uft
|
|
|
|
|
|
|
|
|
|
//Menu exit
|
|
|
|
|
if(gc.getInput().isKeyDown(Input.KEY_ENTER) && (level.selectedString == 2||menu.selectedString == 2))
|
|
|
|
|
gc.exit();
|
|
|
|
|
|
|
|
|
|
// Press Enter start screen
|
|
|
|
|
if(gc.getInput().isKeyDown(Input.KEY_ENTER)&& (level.selectedString == 0)&& level.waiter >3 && gameState.stateId==0){
|
|
|
|
|
gameState.stateId = 4;level.waiter = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Menu startgame Option
|
|
|
|
|
if(gc.getInput().isKeyDown(Input.KEY_ENTER)&&level.waiter >0.3 && (menu.selectedString == 0) && gameState.stateId==4){
|
|
|
|
|
gameState.stateId = 6;level.waiter = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Pause Menu resume game Option
|
|
|
|
|
if(gc.getInput().isKeyDown(Input.KEY_ENTER)&&level.waiter >3 && (menu.selectedString == 0) && gameState.stateId==2){
|
|
|
|
|
gameState.stateId = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Control Instructions Screen Timer
|
|
|
|
|
if(gameState.stateId == 6 && level.waiter >10){
|
|
|
|
|
gameState.stateId = 5;
|
|
|
|
|
level.waiter = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Intro Screen Timer
|
|
|
|
|
if(gameState.stateId == 5 && level.waiter > 5){
|
|
|
|
|
panel.xPos = 350;
|
|
|
|
|
gameState.stateId = 1;
|
|
|
|
|
level.waiter = 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Win State Bedingung
|
|
|
|
|
if(gameState.stateId == 1 && level.currentLevel == 5 && hud.sbar_width >=100){
|
|
|
|
|
level.waiter = 0 ;
|
|
|
|
|
gameState.stateId = 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Win Screen Timer
|
|
|
|
|
if(gameState.stateId == 8 && level.waiter > 5){
|
|
|
|
|
gameState.stateId = 4;
|
|
|
|
|
level.currentLevel = 1;
|
|
|
|
|
|
|
|
|
|
//Initialisierung eines "Neuen Spiels"
|
|
|
|
|
panel.init(gc, gameState, 1);
|
|
|
|
|
hud.init(gc, gameState);
|
|
|
|
|
invader.init(gc, gameState);
|
|
|
|
|
protector.init(gc, gameState, 50);
|
|
|
|
|
level.init(gc, invader, protector, hud, gameState, panel, _delta);
|
|
|
|
|
menu.init(gc, gameState);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Pause Menu Aktivierung
|
|
|
|
|
if(gc.getInput().isKeyPressed(Input.KEY_P )&& (gameState.stateId == 1))
|
|
|
|
|
gameState.stateId = 2;
|
|
|
|
|
|
|
|
|
|
//Game Over Bedingung
|
|
|
|
|
if(hud.dbar_width<=0 && gameState.stateId==1){
|
|
|
|
|
level.waiter = 0;
|
|
|
|
|
gameState.stateId = 7;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Neues Game nach Game Over
|
|
|
|
|
if(gameState.stateId == 7 &&level.waiter > 10){
|
|
|
|
|
|
|
|
|
|
panel.init(gc, gameState, 1);
|
|
|
|
|
hud.init(gc, gameState);
|
|
|
|
|
invader.init(gc, gameState);
|
|
|
|
|
protector.init(gc, gameState, 50);
|
|
|
|
|
level.init(gc, invader, protector, hud, gameState, panel, _delta);
|
|
|
|
|
menu.init(gc, gameState);
|
|
|
|
|
level.currentLevel = 1;
|
|
|
|
|
gameState.stateId = 4;
|
|
|
|
|
}
|
|
|
|
|
//Update Aufrufe
|
|
|
|
|
gameState.update(gc, _delta);
|
|
|
|
|
level.update(gc, _delta);
|
|
|
|
|
menu.update(gc, _delta);
|
|
|
|
|
panel.update(gc, _delta);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void render(GameContainer gc, Graphics g) throws SlickException {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
//Renderaufrufe
|
|
|
|
|
gameState.render(gc, g);
|
|
|
|
|
level.render(gc, g);
|
|
|
|
|
|
|
|
|
|
menu.render(gc, g);
|
|
|
|
|
hud.render(gc, g);
|
|
|
|
|
|
|
|
|
|
//Titel screen Einblendung
|
|
|
|
|
if(gameState.stateId == 0 && waiter >3){
|
|
|
|
|
g.drawString("Press Enter", 350, 550);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Hauptmethode
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
try {//Apperstellung
|
|
|
|
|
AppGameContainer app = new AppGameContainer(new JnP());
|
|
|
|
|
app.setDisplayMode(800, 600, true);//Fullscreen 800x600
|
|
|
|
|
app.setTargetFrameRate(60);//Fl<46>ssige FPS von 60
|
|
|
|
|
app.setVSync(true);//VSinc um Renderprobleme bei schneller Objektbewegung zu verhindern
|
|
|
|
|
app.setShowFPS(false);
|
|
|
|
|
app.start();
|
|
|
|
|
}
|
|
|
|
|
catch (SlickException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|