Advertisement
Guest User

Sprite.java

a guest
Oct 31st, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. package com.morgenmiddag.rain.graphics;
  2.  
  3. public class Sprite {
  4.  
  5. public final int SIZE;
  6. private int x, y;
  7. public int[] pixels;
  8. private SpriteSheet sheet;
  9.  
  10. public static Sprite grass = new Sprite(16, 0, 0, SpriteSheet.tiles);
  11. public static Sprite voidSprite = new Sprite(16, 0x274BB0);
  12.  
  13. public Sprite(int size, int x, int y, SpriteSheet sheet) {
  14. SIZE = size;
  15. pixels = new int[SIZE * SIZE];
  16. this.x = x * size;
  17. this.y = y * size;
  18. this.sheet = sheet;
  19. load();
  20. }
  21.  
  22. public Sprite(int size, int colour) {
  23. SIZE = size;
  24. pixels = new int [SIZE * SIZE];
  25. setColour(colour);
  26. }
  27.  
  28. private void setColour(int colour) {
  29. for (int i = 0; i < SIZE * SIZE; i++){
  30. pixels[i] = colour;
  31. }
  32. }
  33.  
  34. private void load(){
  35. for(int y = 0; y < SIZE; y++){
  36. for(int x = 0; x < SIZE; x++){
  37. pixels[x + y * SIZE] = sheet.pixels[(x + this.x) + (y + this.y) * sheet.SIZE];
  38. }
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement