Advertisement
Guest User

Screen

a guest
May 29th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Screen {
  2.  
  3. public int width, height;
  4. public int[] pixels;
  5. public final int MAP_SIZE = 64;
  6. public final int MAP_SIZE_MASK = MAP_SIZE - 1;
  7. public int xOffset, yOffset;
  8. public int[] tiles = new int[64 * 64];
  9. private Random random = new Random();
  10.  
  11. public Screen(int width,int height) {
  12. this.width = width;
  13. this.height = height;
  14. pixels = new int[width * height]; // 50,400
  15.  
  16. for (int i =0; i < MAP_SIZE * MAP_SIZE; i++) {
  17. tiles[i] = random.nextInt(0xffffff);
  18. }
  19. }
  20.  
  21. public void clear() {
  22. for(int i = 0; i < pixels.length; i++){
  23. pixels[i] = 0;
  24. }
  25. }
  26.  
  27. public void renderTile(int xp, int yp, Tile tile){
  28. xp -= xOffset;
  29. yp -= yOffset;
  30. for (int y = 0; y < tile.sprite.SIZE; y++){
  31. int ya = y + yp;
  32. for (int x = 0; x < tile.sprite.SIZE; x++){
  33. int xa = x + xp;
  34. if(xa < -tile.sprite.SIZE || xa >= width || ya < 0 || ya >= height) break;
  35. if(xa < 0) xa = 0;
  36. if(ya < 0) ya = 0;
  37. pixels[xa + ya * width] = tile.sprite.pixels[x + y * tile.sprite.SIZE];
  38. }
  39. }
  40. }
  41.  
  42. public void setOffset(int xOffset, int yOffset) {
  43. this.xOffset = xOffset;
  44. this.yOffset = yOffset;
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement