Advertisement
TheKing1337

Sprite.java

Jun 8th, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. package tk.sketchistgames.graphics;
  2.  
  3. public class Sprite {
  4. public final int SIZE;
  5. private int x, y;
  6. public int[] pixels;
  7. private SpriteSheet sheet;
  8.  
  9.  
  10. public int getSize(){
  11. return SIZE;
  12. }
  13.  
  14. public static SpriteSheet sprites = new SpriteSheet("/textures/spritesheet.png", 256);
  15.  
  16. public static Sprite grass = new Sprite(16, 0, 0, sprites);
  17. public static Sprite voidSprite = new Sprite(16, 0 , 1, sprites);
  18.  
  19.  
  20. public Sprite(int size, int x, int y, SpriteSheet sheet) {
  21. SIZE = size;
  22. pixels = new int[SIZE * SIZE];
  23. this.x = x * size;
  24. this.y = y * size;
  25. this.sheet = sheet;
  26. load();
  27. }
  28. public Sprite(int size, int color){
  29. SIZE = size;
  30. pixels = new int[SIZE * SIZE];
  31. setColor(color);
  32. }
  33.  
  34. private void setColor(int color) {
  35. for (int i = 0; i < SIZE * SIZE; i++){
  36. pixels[i] = color;
  37. }
  38. }
  39. private void load() {
  40. for(int y = 0; y < SIZE; y++){
  41. for (int x = 0; x < SIZE; x++){
  42. pixels[x+y*SIZE] = sheet.pixels[(x + this.x) + (y + this.y) *sheet.SIZE];
  43. }
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement