Advertisement
Guest User

Untitled

a guest
Sep 4th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.50 KB | None | 0 0
  1. public class Sprite {
  2.  
  3.     public final int SIZE;
  4.     private int x, y;
  5.     private int width, height;
  6.     public int[] pixels;
  7.     private SpriteSheet sheet;
  8.  
  9.     public static Sprite grass = new Sprite(16, 0, 0, SpriteSheet.tiles);
  10.     public static Sprite flower = new Sprite(16, 0, 1, SpriteSheet.tiles);
  11.     public static Sprite stone = new Sprite(16, 0, 2, SpriteSheet.tiles);
  12.     public static Sprite voidSprite = new Sprite(16, 0xff111111);
  13.  
  14.     // SpawnLevel Sprite here:
  15.     public static Sprite spawn_grass = new Sprite(16, 0, 0, SpriteSheet.spawnLevel);
  16.     public static Sprite spawn_stone = new Sprite(16, 0, 2, SpriteSheet.spawnLevel);
  17.     public static Sprite spawn_flower = new Sprite(16, 0, 1, SpriteSheet.spawnLevel);
  18.     public static Sprite spawn_water = new Sprite(16, 2, 0, SpriteSheet.spawnLevel);
  19.     public static Sprite spawn_wood = new Sprite(16, 1, 2, SpriteSheet.spawnLevel);
  20.     public static Sprite spawn_wall_1 = new Sprite(16, 2, 2, SpriteSheet.spawnLevel);
  21.     public static Sprite spawn_wall_2 = new Sprite(16, 2, 1, SpriteSheet.spawnLevel);
  22.     public static Sprite spawn_sand = new Sprite(16, 1, 1, SpriteSheet.spawnLevel);
  23.  
  24.     // projectile sprites here:
  25.     public static Sprite projectile_player = new Sprite(16, 0, 0, SpriteSheet.projectile_player);
  26.  
  27.     // Particles
  28.     public static Sprite particle_normal = new Sprite(3, 0xAAAAAA);
  29.    
  30.     // Zombie sprites here: 1:x , 2:y
  31.     public static Sprite zombie_forward = new Sprite(32, 2, 2, SpriteSheet.tiles);
  32.     public static Sprite zombie_back = new Sprite(32, 0, 2, SpriteSheet.tiles);
  33.     public static Sprite zombie_side = new Sprite(32, 1, 2, SpriteSheet.tiles);
  34.  
  35.     public static Sprite zombie_forward_1 = new Sprite(32, 2, 3, SpriteSheet.tiles);
  36.     public static Sprite zombie_forward_2 = new Sprite(32, 2, 4, SpriteSheet.tiles);
  37.     public static Sprite zombie_back_1 = new Sprite(32, 0, 3, SpriteSheet.tiles);
  38.     public static Sprite zombie_back_2 = new Sprite(32, 0, 4, SpriteSheet.tiles);
  39.     public static Sprite zombie_side_1 = new Sprite(32, 1, 3, SpriteSheet.tiles);
  40.     public static Sprite zombie_side_2 = new Sprite(32, 1, 4, SpriteSheet.tiles);
  41.  
  42.     // snake sprites here:
  43.     public static Sprite snake_forward = new Sprite(32, 3, 2, SpriteSheet.tiles);
  44.     public static Sprite snake_back = new Sprite(32, 5, 2, SpriteSheet.tiles);
  45.     public static Sprite snake_side = new Sprite(32, 4, 2, SpriteSheet.tiles);
  46.  
  47.     public static Sprite snake_forward_1 = new Sprite(32, 5, 2, SpriteSheet.tiles);
  48.     public static Sprite snake_forward_2 = new Sprite(32, 5, 3, SpriteSheet.tiles);
  49.     public static Sprite snake_back_1 = new Sprite(32, 3, 2, SpriteSheet.tiles);
  50.     public static Sprite snake_back_2 = new Sprite(32, 3, 3, SpriteSheet.tiles);
  51.     public static Sprite snake_side_1 = new Sprite(32, 4, 2, SpriteSheet.tiles);
  52.     public static Sprite snake_side_2 = new Sprite(32, 4, 3, SpriteSheet.tiles);
  53.  
  54.     // player Sprite here:
  55.     public static Sprite player_forward = new Sprite(32, 2, 5, SpriteSheet.tiles);
  56.     public static Sprite player_back = new Sprite(32, 0, 5, SpriteSheet.tiles);
  57.     public static Sprite player_side = new Sprite(32, 1, 5, SpriteSheet.tiles);
  58.  
  59.     public static Sprite player_forward_1 = new Sprite(32, 2, 6, SpriteSheet.tiles);
  60.     public static Sprite player_forward_2 = new Sprite(32, 2, 7, SpriteSheet.tiles);
  61.     public static Sprite player_back_1 = new Sprite(32, 0, 6, SpriteSheet.tiles);
  62.     public static Sprite player_back_2 = new Sprite(32, 0, 7, SpriteSheet.tiles);
  63.     public static Sprite player_side_1 = new Sprite(32, 1, 6, SpriteSheet.tiles);
  64.     public static Sprite player_side_2 = new Sprite(32, 1, 7, SpriteSheet.tiles);
  65.  
  66.     public Sprite(int size, int x, int y, SpriteSheet sheet) {
  67.         SIZE = size;
  68.         this.width = size;
  69.         this.height = size;
  70.         pixels = new int[SIZE * SIZE];
  71.         this.x = x * size;
  72.         this.y = y * size;
  73.         this.sheet = sheet;
  74.         load();
  75.  
  76.     }
  77.  
  78.     public Sprite(int width, int height, int colour) {
  79.         SIZE = -1;
  80.         this.width = width;
  81.         this.height = height;
  82.         pixels = new int[width * height];
  83.         setColour(colour);
  84.     }
  85.  
  86.     public Sprite(int size, int colour) {
  87.         SIZE = size;
  88.         this.width = size;
  89.         this.height = size;
  90.         pixels = new int[SIZE * SIZE];
  91.         setColour(colour);
  92.     }
  93.  
  94.     private void setColour(int colour) {
  95.         for (int i = 0; i < width * height; i++) {
  96.             pixels[i] = colour;
  97.         }
  98.     }
  99.  
  100.     public int getWidth() {
  101.         return width;
  102.     }
  103.  
  104.     public int getHeight() {
  105.         return height;
  106.     }
  107.  
  108.     private void load() {
  109.         for (int y = 0; y < SIZE; y++) {
  110.             for (int x = 0; x < SIZE; x++) {
  111.                 pixels[x + y * SIZE] = sheet.pixels[(x + this.x) + (y + this.y) * sheet.SIZE];
  112.             }
  113.         }
  114.     }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement