import java.util.ArrayList; import org.lwjgl.LWJGLException; import org.lwjgl.Sys; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; import org.lwjgl.opengl.GL11; import org.lwjgl.input.Mouse; /** * This is the main class of the game. This renders the game, handles input and output etc. * Important methods: update, renderGL * @author vanitas * */ public class Game{ long lastFrame, lastFPS; //Values to calibrate the framerate etc. int fps; public static final int frameSizeX = 800, frameSizeY = 600; //Resolution of the Window @SuppressWarnings("rawtypes") private ArrayList objects; //A ArrayList containing th following Lists private ArrayList metroids; //A List Containing all the metroids private ArrayList ships; //A List Containing all the ships etc private static ArrayList munition; //A List Containing all the active fired projectiles private ControlledShip playerShip; //The players ship private Menu menu; //The Menu-Display private boolean menuIsActive; //if menu is active this variable is true private boolean closeRequested = false; /** * Constructor */ @SuppressWarnings("rawtypes") public Game() { // //Initialize ship and Objects (Add Objects here and dont forget to add them to the ArrayLists as well;) playerShip = new ControlledShip(); Turret geschuetz = new Turret(playerShip.getX(),playerShip.getY()); geschuetz.setParent(playerShip); //Initialize ArrayLists objects = new ArrayList(); metroids = new ArrayList(); ships = new ArrayList(); munition = new ArrayList(); //Add Objects to Lists ships.add(playerShip); ships.add(geschuetz); //Pack Lists together objects.add(metroids); objects.add(ships); objects.add(munition); } /** * This method updates all the objects (moves them, captures keyboard and mouse input etc) * @param delta */ public void update(int delta) { //Handle Keyboard KeyPresses //Gas geben ;) if (Keyboard.isKeyDown(Keyboard.KEY_UP)) //Arrow up { playerShip.setVelocity(1f); //Set the velocity to 1 (Power on) } //rotation (Arrow right) if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) { playerShip.turnRight(delta); } //Arrow left if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) { playerShip.turnLeft(delta); } //When Arrow up is released, turn down the power. if(!Keyboard.isKeyDown(Keyboard.KEY_UP)) { playerShip.setVelocity(0f); } //If Spacebar is pressed and shotburnout is over, fire a projectile if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { playerShip.fire(delta); } if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { menuIsActive = true; } //Call an update (movements etc.) for every Object in the game updateObjects(delta); updateFPS(); // update FPS Counter } /** * Update (accelerate and move) all the Objects in the ArrayLists * @param delta */ public void updateObjects(float delta) { for(int i = 0; i l = objects.get(i); for(int j = 0; j l = objects.get(i); for(int j = 0; j 1000) { Display.setTitle("The best game in the world. FPS: " + fps); fps = 0; lastFPS += 1000; } fps++; } public ArrayList getObjects() { return objects; } public void setObjects(ArrayList objects) { this.objects = objects; } public ArrayList getMetroids() { return metroids; } public void setMetroids(ArrayList metroids) { this.metroids = metroids; } public ArrayList getShips() { return ships; } public void setShips(ArrayList ships) { this.ships = ships; } public static ArrayList getMunition() { return munition; } public void setMunition(ArrayList munition) { this.munition = munition; } }