Author: davedes (posted 2013-02-18 23:10:14, viewed 145 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
57
58
59
60
61
62
63
64
65
66
| import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ImgTiles {
static enum Tile {
GRASS(0xff00ff00), WATER(0xff0000ff), LAVA(0xffff0000);
public final int argb;
Tile(int argb) {
this.argb = argb;
}
public static Tile fromColor(int argb) {
for (Tile t : Tile.values())
if (t.argb == argb)
return t;
return null;
}
}
public static void main(String[] args) throws IOException {
BufferedImage img = ImageIO.read(ImgTiles.class.getResource("map.png"));
int width = img.getWidth();
int height = img.getHeight();
int[] pixels = img.getRGB(0, 0, width, height, null, 0, width);
Tile[][] map = new Tile[width][height];
for (int i=0; i<width * height; i++) {
int value = pixels[i];
Tile t = Tile.fromColor(value);
int y = i / width;
int x = i - width*y;
map[x][y] = t;
int a = ((value & 0xff000000) >>> 24);
int r = ((value & 0x00ff0000) >>> 16);
int g = ((value & 0x0000ff00) >>> 8);
int b = (value & 0x000000ff);
}
System.out.println(map[0][0]); }
} |
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 '~~~~'
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|