package edu.stuy.starlorn.menu;

import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import edu.stuy.starlorn.display.Screen;

public class Menu {

    private Screen screen;
    private long lastFrame;

    private Button[] buttons;
    private Star[] stars;

    public Menu(Screen scr) {
        screen = scr;
    }

    public void setup() {
        int cx = screen.getWidth() / 2,
            cy = screen.getHeight() / 2;

        buttons = new Button[4];
        buttons[0] = new Button(cx - 150, cy + 20, 300, 120);
        buttons[1] = new Button(cx - 150, cy - 80, 300, 80);
        buttons[2] = new Button(cx - 150, cy - 180, 140, 80);
        buttons[3] = new Button(cx + 10, cy - 180, 140, 80);

        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        GL11.glOrtho(0, screen.getWidth(), 0, screen.getHeight(), 1, -1);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        stars = new Star[400];
        for (int i = 0; i < 400; i++)
            stars[i] = new Star(screen.getWidth(), screen.getHeight(), 0.3);
    }

    public void loop() {
        getDelta();
        while (screen.alive()) {
            if (Keyboard.isKeyDown(Keyboard.KEY_Q))
                break;
            update(getDelta());
            render();
            screen.tick();
        }
    }

    private void update(int delta) {
        for (Star star: stars)
            star.update(delta);
        for (Button button : buttons)
            button.update(delta);
    }

    /**
     * Calculate how many milliseconds have passed since last frame.
     *
     * @return milliseconds passed since last frame
     */
    private int getDelta() {
        long time = getTime();
        int delta = (int) (time - lastFrame);
        lastFrame = time;
        return delta;
    }

    /**
     * Get the accurate system time
     *
     * @return The system time in milliseconds
     */
    private long getTime() {
        return (Sys.getTime() * 1000) / Sys.getTimerResolution();
    }

    private void render() {
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        for (Rectangle x: stars)
            x.draw();
        for (Button button : buttons)
            button.draw();
    }
}

@@ -521,26 +521,26 @@
 Button(cx - 
-15
+20
 0, cy + 20, 
@@ -539,17 +539,17 @@
 y + 20, 
-3
+4
 00, 120)
@@ -579,34 +579,34 @@
 new Button(cx - 
-15
+20
 0, cy - 80, 300,
@@ -601,17 +601,17 @@
 y - 80, 
-3
+4
 00, 80);
@@ -652,10 +652,10 @@
 x - 
-15
+20
 0, c
@@ -656,33 +656,33 @@
 200, cy - 180, 1
-4
+9
 0, 80);%0A        
@@ -725,17 +725,17 @@
 - 180, 1
-4
+9
 0, 80);%0A

Make buttons wider?