Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 15:40:11, viewed 270 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
 

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

The first screenshot will be displayed as a thumbnail.

ctomni231 (36 views)
2014-07-18 06:55:21

Zero Volt (34 views)
2014-07-17 23:47:54

danieldean (27 views)
2014-07-17 23:41:23

MustardPeter (30 views)
2014-07-16 23:30:00

Cero (44 views)
2014-07-16 00:42:17

Riven (46 views)
2014-07-14 18:02:53

OpenGLShaders (35 views)
2014-07-14 16:23:47

Riven (35 views)
2014-07-14 11:51:35

quew8 (31 views)
2014-07-13 13:57:52

SHC (67 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!