Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nl.jorikoolstra.jLevel.Game;
- import nl.jorikoolstra.jLevel.Graphics.ScreenManager;
- import java.awt.*;
- import javax.swing.JFrame;
- public final class GameMain extends JFrame
- {
- public static final int FPS = 75;
- public static final int GENERATE_MAX_FPS = 0;
- public static final Font DEFAULT_FONT = new Font("Courier", Font.PLAIN, 24);
- private static ScreenManager screenManager;
- public static void main(String[] args)
- {
- if (args.length != 3)
- {
- System.exit(1);
- }
- new GameMain(args);
- }
- private GameMain(String[] args)
- {
- try
- {
- if (initializeGameEnvironment(args) == false)
- {
- this.dispose();
- System.exit(0);
- }
- gameLoop();
- }
- finally
- {
- screenManager.restoreScreen();
- }
- this.dispose();
- System.exit(0);
- }
- private void gameLoop()
- {
- while (true)
- {
- Graphics2D screenGraphics = screenManager.getGraphics();
- /* Update screen */
- draw(screenGraphics);
- screenGraphics.dispose();
- screenManager.updateGraphicsDisplay();
- if (FPS != GENERATE_MAX_FPS)
- {
- try
- {
- /* Render no more than FPS frames per second */
- Thread.sleep(1000 / FPS);
- }
- catch (InterruptedException ex) {}
- }
- }
- }
- private void draw(Graphics g)
- {
- /* Set default font */
- setFont(DEFAULT_FONT);
- /* Clear the screen */
- g.clearRect(0, 0, screenManager.getWidth(), screenManager.getHeight());
- g.drawString("This is just a test string too see the flickering...", 100, 100);
- }
- private boolean initializeGameEnvironment(String[] args)
- {
- /* ------ Initialize graphics environment ------ */
- DisplayMode displayMode = new DisplayMode(Integer.parseInt(args[0]) /* width */,
- Integer.parseInt(args[1]) /* heigth */,
- Integer.parseInt(args[2]) /* bit depth */,
- DisplayMode.REFRESH_RATE_UNKNOWN /* refresh rate */);
- screenManager = new ScreenManager();
- screenManager.setFullScreen(displayMode, this);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement