Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: davedes (posted 2013-01-02 21:40:11, viewed 205 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56  
//TYPE_INT_ARGB color table
public static final int[] TABLE = new int[] {
   0x0,   //transparent
   0xff1a1a1a,   //R=26, G=26, B=26, A=255
   0xffbfbfbf,   //R=191, G=191, B=191, A=255
   0xffa29446,   //R=162, G=148, B=70, A=255
   0xfff7e26b,   //R=247, G=226, B=107, A=255
   0xffc20000,   //R=194, G=0, B=0, A=255
   0xffff0000,   //R=255, G=0, B=0, A=255
   0xff9d9d9d,   //R=157, G=157, B=157, A=255
   0xff6f4417,   //R=111, G=68, B=23, A=255
   0xffa46422   //R=164, G=100, B=34, A=255
};

//sprite array properties
public static final int SPRITE_WIDTH = 11;
public static final int SPRITE_HEIGHT = 9;
public static final int SPRITE_COUNT = 6;
public static final int SPRITE_STRIDE = SPRITE_WIDTH * SPRITE_HEIGHT;
public static final int SPRITE_ARRAY_LEN = SPRITE_STRIDE * SPRITE_COUNT;

//offsets to different sprite indices
public static final int SPRITE_PIRATE1_ATTACK = 0;
public static final int SPRITE_PIRATE1_WALK1 = 1;
public static final int SPRITE_PIRATE1_WALK2 = 2;
public static final int SPRITE_PIRATE2_ATTACK = 3;
public static final int SPRITE_PIRATE2_WALK1 = 4;
public static final int SPRITE_PIRATE2_WALK2 = 5;

//////// ENCODING METHOD: Simple Indexed Color Encoding
public static final BufferedImage SPRITE_SHEET = new BufferedImage(SPRITE_WIDTH, SPRITE_HEIGHT * SPRITE_COUNT, BufferedImage.TYPE_INT_ARGB);
public static final int[] SPRITE_PIXELS = ((DataBufferInt)SPRITE_SHEET.getRaster().getDataBuffer()).getData();
public static final BufferedImage[] SPRITES = new BufferedImage[SPRITE_COUNT];

for (int i=0; i<SPRITE_ARRAY_LEN; i++) {
   SPRITE_PIXELS[i] = TABLE["000000000001111212000011111110000034141000000344430000255666502220411171400000888880000008000800000000000000001111212020011111110200034141002000344430200055666540000411171000000888880000008000800000111121202001111111020003414100200034443020005566654000041117100000088888000000888880000008000800000000000000006066600000006666600000634141000000344430000288999802220411171400000888880000008000800000000000000006066600020006666600200634141002000344430200088999840000411171000000888880000008000800000606660002000666660020063414100200034443020008899984000041117100000088888000000888880000008000800000".charAt(i)-48];
   if (i%SPRITE_STRIDE == SPRITE_STRIDE-1) {
      SPRITES[i/(SPRITE_WIDTH*SPRITE_HEIGHT)] = SPRITE_SHEET.getSubimage(
         0, i/(SPRITE_WIDTH*SPRITE_HEIGHT)*SPRITE_HEIGHT, 
         SPRITE_WIDTH, SPRITE_HEIGHT);
   }
}

//////// ENCODING METHOD: PNG Encoding
// You can remove the color table and some of the constants defined earlier
BufferedImage SPRITE_SHEET = null;
BufferedImage[] SPRITES = new BufferedImage[SPRITE_COUNT];
try {
   SPRITE_SHEET = ImageIO.read(new ByteArrayInputStream(DatatypeConverter.parseBase64Binary(
      "iVBORw0KGgoAAAANSUhEUgAAAAsAAAA2CAYAAAARSGNVAAAAvUlEQVR42mNgIAVISUn9R8b79++H0wQVI2Ospi+a4vb/+6NssAIYjdMpMMUwDOKjqwE76xADw38Q/o+EQXyYAhgG64BZC8Nz586FOwerM/JdxP+jY5xuRpfEq5hqkYISOYQiBSMm8UUKTsXokYKhEFekYA1nXJGCN5ypHymj4UxxOA9wTvkPzfbIoUFQAzrGqZA2xRcsqJakKMExLDSGRfFFKFIw0jS+SEFRTChSyM9WuCJlMBdfo+E8+IovAE/bY0jTK+k2AAAAAElFTkSuQmCC"
      )));
   for (int i=0; i<SPRITE_COUNT; i++) 
      SPRITES[i] = SPRITE_SHEET.getSubimage(0, i*SPRITE_HEIGHT, SPRITE_WIDTH, SPRITE_HEIGHT);
} catch (Exception e) {
   // TODO Auto-generated catch block
}





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (84 views)
2013-05-17 21:29:12

alaslipknot (92 views)
2013-05-16 21:24:48

gouessej (123 views)
2013-05-16 00:53:38

gouessej (115 views)
2013-05-16 00:17:58

theagentd (127 views)
2013-05-15 15:01:13

theagentd (114 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.172 seconds with 10 queries.