Advertisement
Guest User

Level.java

a guest
Jun 8th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. package tk.sketchistgames.level;
  2.  
  3.  
  4. import tk.sketchistgames.graphics.Screen;
  5. import tk.sketchistgames.level.tile.Tile;
  6.  
  7. public class Level {
  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.  
  26. private void loadLevel(String path) {
  27.  
  28. }
  29.  
  30. public void update() {
  31.  
  32. }
  33.  
  34. private void time() { // TODO Make Real Time day/night system. Day time irl
  35.  
  36. }
  37.  
  38. public void render(int xScroll, int yScroll, Screen screen) {
  39. screen.setOffset(xScroll, yScroll);
  40. int x0 = xScroll >> 4;// Left
  41. int x1 = (xScroll + screen.getWidth()) >> 4; // Right
  42. int y0 = yScroll >> 4; // Top
  43. int y1 = (yScroll + screen.getHeight()) >> 4; // Bottom
  44.  
  45. for (int y = y0; y < y1; y++) {
  46. for (int x = x0; x < x1; y++) {
  47. getTile(x , y).render(x, y, screen);
  48. }
  49. }
  50. }
  51.  
  52. public Tile getTile(int x, int y) {
  53. if(tiles[x + (y * width)] == 0) return Tile.grassTile;
  54. return Tile.voidTile;
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement