Advertisement
Guest User

skeleton1

a guest
Apr 14th, 2010
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.39 KB | None | 0 0
  1. import java.awt.Canvas;
  2. import java.awt.Dimension;
  3. import java.awt.Graphics2D;
  4. import java.awt.event.KeyAdapter;
  5. import java.awt.event.KeyEvent;
  6. import java.awt.event.WindowAdapter;
  7. import java.awt.event.WindowEvent;
  8. import java.awt.image.BufferStrategy;
  9.  
  10. import javax.swing.JFrame;
  11. import javax.swing.JPanel;
  12.  
  13. public class Main extends Canvas
  14. {
  15.     private static final long serialVersionUID = 1L;
  16.    
  17.     private int WIDTH = 1000;
  18.     private int HEIGHT = 500;
  19.     private int FPS = 10;
  20.    
  21.     private BufferStrategy strategy;
  22.    
  23.     public Main()
  24.     {
  25.         // create a frame to contain our game
  26.         JFrame container = new JFrame("Maple Story");
  27.        
  28.         // get hold the content of the frame and set up the resolution of the game
  29.         JPanel panel = (JPanel) container.getContentPane();
  30.         panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
  31.         panel.setLayout(null);
  32.        
  33.         // setup our canvas size and put it into the content of the frame
  34.         setBounds(0, 0, WIDTH, HEIGHT);
  35.         panel.add(this);
  36.        
  37.         // Tell AWT not to bother repainting our canvas since we're
  38.         // going to do that our self in accelerated mode
  39.         setIgnoreRepaint(true);
  40.        
  41.         // finally make the window visible
  42.         container.pack();
  43.         container.setResizable(false);
  44.         container.setVisible(true);
  45.        
  46.         // add a listener to respond to the user closing the window. If they
  47.         // do we'd like to exit the game
  48.         container.addWindowListener(new WindowAdapter()
  49.         {
  50.             public void windowClosing(WindowEvent e)
  51.             {
  52.                 System.exit(0);
  53.             }
  54.         });
  55.        
  56.         // add a key input system (defined below) to our canvas
  57.         // so we can respond to key pressed
  58.         addKeyListener(new KeyInputHandler());
  59.        
  60.         // request the focus so key events come to us
  61.         requestFocus();
  62.  
  63.         // create the buffering strategy which will allow AWT
  64.         // to manage our accelerated graphics
  65.         createBufferStrategy(2);
  66.         strategy = getBufferStrategy();
  67.        
  68.         // initialise the entities in our game so there's something
  69.         // to see at startup
  70.         setup();
  71.     }
  72.     /*
  73.      * Initialise all of your Objects in here
  74.      */
  75.     public void setup()
  76.     {
  77.        
  78.     }
  79.    
  80.     public void gameLoop()
  81.     {
  82.         while(true)
  83.         {
  84.             update();
  85.            
  86.             Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
  87.            
  88.             /*
  89.              * START PAINTING
  90.              * START PAINTING
  91.              * START PAINTING
  92.              * START PAINTING
  93.              * START PAINTING
  94.              * START PAINTING
  95.              * START PAINTING
  96.              */
  97.            
  98.            
  99.            
  100.             /*
  101.              * STOP PAINTING
  102.              * STOP PAINTING
  103.              * STOP PAINTING
  104.              * STOP PAINTING
  105.              * STOP PAINTING
  106.              * STOP PAINTING
  107.              * STOP PAINTING
  108.              */
  109.            
  110.             g.dispose();
  111.             strategy.show();
  112.            
  113.             try
  114.             {
  115.                 Thread.sleep(FPS);
  116.             }
  117.             catch (Exception e)
  118.             {
  119.                
  120.             }
  121.         }
  122.     }
  123.     /*
  124.      * Update all of the x and y coordinates in here
  125.      */
  126.     public void update()
  127.     {
  128.        
  129.     }
  130.     /*
  131.      * Keyboard Action listener
  132.      * Esc is set to close the window by default
  133.      */
  134.     private class KeyInputHandler extends KeyAdapter
  135.     {
  136.         public void keyPressed(KeyEvent e)
  137.         {
  138.             if(e.getKeyCode()==27)
  139.             {
  140.                 System.exit(0);
  141.             }
  142.         }
  143.        
  144.         public void keyReleased(KeyEvent e)
  145.         {
  146.            
  147.         }
  148.     }
  149.    
  150.     public static void main(String argv[])
  151.     {
  152.         Main g =new Main();
  153.  
  154.         // Start the main game loop, note: this method will not
  155.         // return until the game has finished running. Hence we are
  156.         // using the actual main thread to run the game.
  157.         g.gameLoop();
  158.     }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement