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