Advertisement
Guest User

Level.java

a guest
Oct 31st, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. package com.morgenmiddag.rain.level;
  2.  
  3. import com.morgenmiddag.rain.graphics.Screen;
  4. import com.morgenmiddag.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. generateLevel();
  16. }
  17.  
  18. public Level(String path) {
  19. loadLevel(path);
  20. }
  21.  
  22. protected void generateLevel() {
  23. }
  24.  
  25. private void loadLevel(String path) {
  26. }
  27.  
  28. public void update() {
  29. }
  30.  
  31. private void time() {
  32. }
  33.  
  34. public void render(int xScroll, int yScroll, Screen screen) {
  35. screen.setOffset(xScroll, yScroll);
  36. int x0 = xScroll >> 4;
  37. int x1 = (xScroll + screen.width) >> 4;
  38. int y0 = yScroll >> 4;
  39. int y1 = (yScroll + screen.height) >> 4;
  40.  
  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(tiles[x + y * width] == 0) return Tile.grass;
  50. return Tile.voidTile;
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement