Advertisement
Guest User

Level

a guest
Jun 13th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package com.thecherno.rain.level;
  2.  
  3. import com.thecherno.rain.graphics.Screen;
  4. import com.thecherno.rain.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.         createRandomLevel();
  16.     }
  17.    
  18.     public Level(String path) {
  19.         loadLevel(path);
  20.     }
  21.    
  22.  
  23.     protected void createRandomLevel() {
  24.     }
  25.    
  26.     private void loadLevel(String path) {
  27.        
  28.     }
  29.    
  30.     public void update() {
  31.     }
  32.    
  33.     private void time() {
  34.     }
  35.    
  36.     public void render(int xScroll, int yScroll, Screen screen) {
  37.         screen.setOffset(xScroll, yScroll);
  38.         int x0 = xScroll / 16;
  39.         int x1 = (xScroll + screen.width + 16) / 16;
  40.         int y0 = yScroll / 16;
  41.         int y1 = (yScroll + screen.height + 16) / 16;
  42.        
  43.         for (int y = y0; y < y1; y++) {
  44.             for(int x = x0; x < x1; x++) {
  45.                 getTile(x, y).render(x, y, screen);
  46.             }
  47.         }
  48.     }
  49.    
  50.     public Tile getTile(int x, int y) {
  51.         if (x < 0 || y < 0 || x >= width || y >= height) return Tile.voidTile;
  52.         if (tiles[x+y*width] == 0) return Tile.grass;
  53.         return Tile.voidTile;
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement