Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Canvas;
- import java.awt.Dimension;
- import java.awt.Graphics2D;
- import java.awt.event.KeyAdapter;
- import java.awt.event.KeyEvent;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.awt.image.BufferStrategy;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class Main extends Canvas
- {
- private static final long serialVersionUID = 1L;
- private int WIDTH = 1000;
- private int HEIGHT = 500;
- private int FPS = 10;
- private BufferStrategy strategy;
- public Main()
- {
- // create a frame to contain our game
- JFrame container = new JFrame("Maple Story");
- // get hold the content of the frame and set up the resolution of the game
- JPanel panel = (JPanel) container.getContentPane();
- panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
- panel.setLayout(null);
- // setup our canvas size and put it into the content of the frame
- setBounds(0, 0, WIDTH, HEIGHT);
- panel.add(this);
- // Tell AWT not to bother repainting our canvas since we're
- // going to do that our self in accelerated mode
- setIgnoreRepaint(true);
- // finally make the window visible
- container.pack();
- container.setResizable(false);
- container.setVisible(true);
- // add a listener to respond to the user closing the window. If they
- // do we'd like to exit the game
- container.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- System.exit(0);
- }
- });
- // add a key input system (defined below) to our canvas
- // so we can respond to key pressed
- addKeyListener(new KeyInputHandler());
- // request the focus so key events come to us
- requestFocus();
- // create the buffering strategy which will allow AWT
- // to manage our accelerated graphics
- createBufferStrategy(2);
- strategy = getBufferStrategy();
- // initialise the entities in our game so there's something
- // to see at startup
- setup();
- }
- /*
- * Initialise all of your Objects in here
- */
- public void setup()
- {
- }
- public void gameLoop()
- {
- while(true)
- {
- update();
- Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
- /*
- * START PAINTING
- * START PAINTING
- * START PAINTING
- * START PAINTING
- * START PAINTING
- * START PAINTING
- * START PAINTING
- */
- /*
- * STOP PAINTING
- * STOP PAINTING
- * STOP PAINTING
- * STOP PAINTING
- * STOP PAINTING
- * STOP PAINTING
- * STOP PAINTING
- */
- g.dispose();
- strategy.show();
- try
- {
- Thread.sleep(FPS);
- }
- catch (Exception e)
- {
- }
- }
- }
- /*
- * Update all of the x and y coordinates in here
- */
- public void update()
- {
- }
- /*
- * Keyboard Action listener
- * Esc is set to close the window by default
- */
- private class KeyInputHandler extends KeyAdapter
- {
- public void keyPressed(KeyEvent e)
- {
- if(e.getKeyCode()==27)
- {
- System.exit(0);
- }
- }
- public void keyReleased(KeyEvent e)
- {
- }
- }
- public static void main(String argv[])
- {
- Main g =new Main();
- // Start the main game loop, note: this method will not
- // return until the game has finished running. Hence we are
- // using the actual main thread to run the game.
- g.gameLoop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement