Guest User

Sprite.java

a guest
Mar 22nd, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package com.doamax.game.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, 0xFFFFFF);
  12.    
  13.     public static Sprite player0 = new Sprite(16, 0, 10, SpriteSheet.tiles);
  14.     public static Sprite player1 = new Sprite(16, 1, 10, SpriteSheet.tiles);
  15.     public static Sprite player2 = new Sprite(16, 0, 11, SpriteSheet.tiles);
  16.     public static Sprite player3 = new Sprite(16, 1, 11, SpriteSheet.tiles);
  17.    
  18.     public Sprite(int size, int x, int y, SpriteSheet sheet){
  19.         SIZE = size;
  20.         pixels = new int[SIZE * SIZE];
  21.         this.x = x * size;
  22.         this.y = y * size; 
  23.         this.sheet = sheet;
  24.         load();
  25.     }
  26.    
  27.     public Sprite(int size, int color){
  28.         SIZE = size;
  29.         pixels = new int[SIZE*SIZE];
  30.         setColor(color);
  31.     }
  32.    
  33.     private void setColor(int color) {
  34.         for (int i = 0; i < SIZE*SIZE; i++){
  35.             pixels[i] = color;
  36.         }
  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