SkyAphid

Tile map drawer

Apr 3rd, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. public void drawMap(Graphics g, int cameraX, int cameraY){
  2.     int tilesize = 16;
  3.    
  4.     int cameraOffsetX = 40; //Tiles to draw to left and right of camera.
  5.     int cameraOffsetY = 20; //Tiles to draw above and below the camera.
  6.    
  7.     int startingPointX = Math.max(cameraX - cameraOffsetX, 0);
  8.     int startingPointY = Math.max(cameraY - cameraOffsetY, 0);
  9.    
  10.     int stoppingPointX = Math.min(cameraX + cameraOffsetX, WIDTH);
  11.     int stoppingPointY = Math.min(cameraY + cameraOffsetY, HEIGHT);
  12.    
  13.     for (int x = startingPointX; x < stoppingPointX; x++){
  14.         for (int y = startingPointY; y < stoppingPointY; y++){
  15.             g.setColor(Color.green);
  16.             g.fillRect(x * tilesize, y * tilesize, tilesize, tilesize);
  17.         }
  18.     }      
  19. }
Advertisement
Add Comment
Please, Sign In to add comment