Advertisement
Guest User

World

a guest
Aug 22nd, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. import java.awt.Graphics;
  2. import java.awt.Graphics2D;
  3. import java.awt.Toolkit;
  4. import java.awt.event.KeyEvent;
  5. import java.awt.event.MouseEvent;
  6. import java.util.ArrayList;
  7.  
  8. /*
  9.  *
  10.  *
  11.  * @Author sp0wner 2012
  12.  *
  13.  * World.java
  14.  *
  15.  * World - Used to display the world of the game
  16.  *
  17.  *  -Initialises map
  18.  *  -Draws the map on the screen using the draw() function
  19.  *  -Draws elements on the map such as obstacles,trees etc
  20.  *
  21.  */
  22.  
  23. public class World {
  24.  
  25.     // holds the map object
  26.     private Map map;
  27.     private char[][] map2d;
  28.     // map size
  29.     private int mHeight = 100, mWidth = 100;
  30.  
  31.     // screen width and height
  32.     private int pWidth, pHeight;
  33.  
  34.     // How much to move when arrows are pressed
  35.     private int xStep = 30, yStep = 30;
  36.  
  37.  
  38.     private Floor floor; // holds the floor
  39.    
  40.     //private TiledSprite sprite;
  41.    
  42.  
  43.     /**
  44.      * @see Constructor of the World class
  45.      * @param pWidth
  46.      *            -panel Width
  47.      * @param pHeight
  48.      *            - panel Height
  49.      */
  50.     public World(int pWidth, int pHeight) {
  51.        
  52.         this.pWidth = pWidth;
  53.         this.pHeight = pHeight;
  54.        
  55.         initMap();
  56.         initFloor();
  57.         //initSprite();
  58.        
  59.     }// end of constructor
  60.    
  61.    
  62.    
  63.     public void initFloor(){
  64.         floor = new Floor(map2d,map.getWidth(),map.getHeight(),pWidth, pHeight);
  65.     }
  66.  
  67.     /**
  68.      * @see Initiates map object
  69.      */
  70.     public void initMap()
  71.     {
  72.         map = new Map(mHeight, mWidth);
  73.         map2d=map.getMap();
  74.     }
  75.  
  76.  
  77.    
  78.     public void draw(Graphics g){
  79.         floor.draw(g);
  80.         //sprite.draw(g);
  81.        
  82.     }
  83.  
  84.     boolean sthIsSelected=false;
  85.      public void mousePressed(MouseEvent e){
  86.          
  87.         if(e.getButton()==MouseEvent.BUTTON1){
  88.             //sprite.select(e.getX(), e.getY());
  89.             //if(sprite.getSelected())
  90.                 //sthIsSelected=true;
  91.         }
  92.        
  93.         if(e.getButton()==MouseEvent.BUTTON3 && sthIsSelected){
  94.             //sprite.moveTo(e.getX(),e.getY());
  95.         }
  96.          
  97.          
  98.          
  99.      }
  100.    
  101.    
  102.     /**
  103.      * @see This methods is responsible for moving the camera arroung
  104.      * @param keycode
  105.      *            - They key code of the button pressed
  106.      */
  107.     public void moveCamera(int keycode) {
  108.         floor.moveCamera(keycode,xStep,yStep);
  109.         //sprite.moveCamera(keycode,xStep,yStep);
  110.     }//end of moveCamera()
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement