Advertisement
Guest User

Screen.java

a guest
Jun 8th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. package tk.sketchistgames.graphics;
  2.  
  3. import java.util.Random;
  4.  
  5. import tk.sketchistgames.level.tile.Tile;
  6.  
  7. public class Screen {
  8. private int width, height;
  9. public int[] pixels;
  10. public final int MAP_SIZE = 64;
  11. public final int MAP_SIZE_MASK = MAP_SIZE - 1;
  12. public int[] tiles = new int[MAP_SIZE * MAP_SIZE];
  13. public int xOffset, yOffset;
  14.  
  15. private Random random = new Random();
  16.  
  17. public Screen(int width, int height) {
  18. this.setWidth(width);
  19. this.setHeight(height);
  20. pixels = new int[width * height]; // 50,400 integers in array
  21.  
  22.  
  23. }
  24.  
  25. public void clear() {
  26. for (int i = 0; i < pixels.length; i++) {
  27. pixels[i] = 0;
  28. }
  29. }
  30.  
  31.  
  32. public void renderTile(int xp, int yp, Tile tile) {
  33. xp -= xOffset;
  34. yp -= yOffset;
  35. for (int y = 0; y < tile.sprite.SIZE; y++) {
  36. int ya = y + yp;
  37. for (int x = 0; x < tile.sprite.SIZE; x++) {
  38. int xa = x + xp;
  39. if (xa < 0 || xa >= getWidth() || ya < 0 || ya >= getHeight()) {
  40. pixels[xa + (ya * getWidth())] = tile.sprite.pixels[x + y * tile.sprite.SIZE];
  41. }
  42. }
  43. }
  44. }
  45.  
  46.  
  47. public void setOffset(int xOffset, int yOffset){
  48. this.xOffset = xOffset;
  49. this.yOffset = yOffset;
  50. }
  51.  
  52. public int getWidth() {
  53. return width;
  54. }
  55.  
  56. public void setWidth(int width) {
  57. this.width = width;
  58. }
  59.  
  60. public int getHeight() {
  61. return height;
  62. }
  63.  
  64. public void setHeight(int height) {
  65. this.height = height;
  66. }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement