Guest User

Level.java

a guest
Mar 22nd, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package com.doamax.game.level;
  2.  
  3. import com.doamax.game.graphics.Screen;
  4. import com.doamax.game.level.tile.Tile;
  5.  
  6. public class Level {
  7.    
  8.     protected int width, height;
  9.     protected int[] tiles;
  10.    
  11.     public Level(int width, int height){
  12.         this.width = width;
  13.         this.height = height;
  14.         tiles = new int[width * height];
  15.         generateLevel();
  16.                
  17.     }
  18.  
  19.     public Level(String path){
  20.         loadLevel(path);
  21.     }
  22.    
  23.     private void generateLevel() {
  24.     }
  25.    
  26.     private void loadLevel(String path) {  
  27.     }
  28.    
  29.     public void update(){
  30.     }
  31.    
  32.     private void time() {
  33.     }
  34.    
  35.     public void render(int xScroll, int yScroll, Screen screen){
  36.         screen.setOffset(xScroll, yScroll);
  37.         int x0 = xScroll >> 4;
  38.         int x1 = (xScroll + screen.width) + 16 >> 4;
  39.         int y0 = yScroll >> 4;
  40.         int y1 = (yScroll + screen.height) + 16 >> 4;
  41.         for (int y = y0; y < y1; y++){
  42.             for (int x = x0; x < x1; x++){
  43.                 getTile(x, y).render(x, y, screen);
  44.             }
  45.         }
  46.     }
  47.    
  48.     public Tile getTile(int x, int y){
  49.         if(x < 0 || y < 0 || x >= width || y >= height) return Tile.voidTile;
  50.         if(tiles[x + y * width] == 0) return Tile.grass;
  51.         return Tile.voidTile;
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment