Advertisement
Guest User

Map

a guest
Dec 28th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  1. package main;
  2.  
  3. import org.newdawn.slick.GameContainer;
  4. import org.newdawn.slick.Graphics;
  5. import org.newdawn.slick.Image;
  6. import org.newdawn.slick.Input;
  7. import org.newdawn.slick.SlickException;
  8. import org.newdawn.slick.state.BasicGameState;
  9. import org.newdawn.slick.state.StateBasedGame;
  10. import user.Main;
  11.  
  12. public class Map extends BasicGameState {
  13.     private int id;
  14.    
  15.     public Map(int id){
  16.         this.id = id;
  17.     }
  18.  
  19.     @Override
  20.     public int getID() {
  21.         return id;
  22.     }
  23.  
  24.     @Override
  25.     public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
  26.     }
  27.  
  28.     @Override
  29.     public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
  30.         int GridX = Main.getInstance().getGrid().getX();
  31.         int GridY = Main.getInstance().getGrid().getY();
  32.         int ScreenX = Main.app.getWidth();
  33.         int ScreenY = Main.app.getHeight();
  34.        
  35.         if(ScreenX > ScreenY){
  36.             ScreenX = ScreenY;
  37.         } else{
  38.             ScreenY = ScreenX;
  39.         }
  40.        
  41.         int RatioX = ScreenX / GridX;
  42.         int RatioY = ScreenY / GridY;
  43.        
  44.         if(RatioX > RatioY){
  45.             RatioX = RatioY;
  46.         } else {
  47.             RatioY = RatioX;
  48.         }
  49.        
  50.         for (int i = 0; i < GridX; i++) {
  51.             for (int j = 0; j < GridY; j++) {
  52.                 boolean[] walls = Main.getInstance().getGrid().getBlock(i, j).getWalls();
  53.                 if (walls[0] == true) {
  54.                     g.drawLine(RatioX * (i + 1) - RatioX, RatioY * (j + 1) - RatioY, RatioX * (i + 1), RatioY * (j + 1) - RatioY);
  55.                 }
  56.                 if (walls[1] == true) {
  57.                     g.drawLine(RatioX * (i + 1) - RatioX, RatioY * (j + 1), RatioX * (i + 1), RatioY * (j + 1));
  58.                 }
  59.                 if (walls[2] == true) {
  60.                     g.drawLine(RatioX * (i + 1) - RatioX, RatioY * (j + 1) - RatioY, RatioX * (i + 1) - RatioX, RatioY * (j + 1));
  61.                 }
  62.                 if (walls[3] == true) {
  63.                     g.drawLine(RatioX * (i + 1), RatioY * (j + 1) - RatioY, RatioX * (i + 1), RatioY * (j + 1));
  64.                 }
  65.             }
  66.         }
  67.         g.drawImage(new Image("res/pin.png").getScaledCopy(RatioX, RatioY), Hero.getInstance().getBlockX() * RatioX, Hero.getInstance().getBlockY() * RatioY);
  68.     }
  69.  
  70.     @Override
  71.     public void update(GameContainer gc, StateBasedGame sbg, int i) throws SlickException {
  72.         Input input = gc.getInput();
  73.         if(!input.isKeyDown(Input.KEY_SPACE)){
  74.             Main.getInstance().enterState(Main.getInstance().getmyOwnCurrentState());
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement