diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2012-06-02 18:46:15 -0400 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2012-06-02 18:46:15 -0400 |
commit | 7597ae93f38aaa32b099b19a3b65b96196f735e3 (patch) | |
tree | 3d1ff2346cfb2a51ecb3773b2c85140f6e8c0449 /src/com | |
parent | 5729344a510f662a01acc3def1f91c146af3b787 (diff) | |
download | frigidearth-7597ae93f38aaa32b099b19a3b65b96196f735e3.tar.gz frigidearth-7597ae93f38aaa32b099b19a3b65b96196f735e3.tar.bz2 frigidearth-7597ae93f38aaa32b099b19a3b65b96196f735e3.zip |
Fixed wonky characters
Instead of rendering a font, characters are now taken from a character map. Also, tick() was removed from GameState because it is only ever called after processInput() and so there's no real point in having separate methods.
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/fourisland/frigidearth/GameState.java | 2 | ||||
-rw-r--r-- | src/com/fourisland/frigidearth/Main.java | 3 | ||||
-rw-r--r-- | src/com/fourisland/frigidearth/MapViewGameState.java | 35 | ||||
-rw-r--r-- | src/com/fourisland/frigidearth/SystemFont.java | 52 | ||||
-rw-r--r-- | src/com/fourisland/frigidearth/TransparentPixelFilter.java | 35 | ||||
-rw-r--r-- | src/com/fourisland/frigidearth/resources/RMG2000.ttf | bin | 70260 -> 0 bytes | |||
-rw-r--r-- | src/com/fourisland/frigidearth/resources/font2.png | bin | 0 -> 5254 bytes |
7 files changed, 104 insertions, 23 deletions
diff --git a/src/com/fourisland/frigidearth/GameState.java b/src/com/fourisland/frigidearth/GameState.java index 08aa173..860411e 100644 --- a/src/com/fourisland/frigidearth/GameState.java +++ b/src/com/fourisland/frigidearth/GameState.java | |||
@@ -10,5 +10,5 @@ package com.fourisland.frigidearth; | |||
10 | */ | 10 | */ |
11 | public interface GameState extends Renderable, Inputable | 11 | public interface GameState extends Renderable, Inputable |
12 | { | 12 | { |
13 | public void tick(); | 13 | |
14 | } | 14 | } |
diff --git a/src/com/fourisland/frigidearth/Main.java b/src/com/fourisland/frigidearth/Main.java index fe936b0..ed35f9c 100644 --- a/src/com/fourisland/frigidearth/Main.java +++ b/src/com/fourisland/frigidearth/Main.java | |||
@@ -61,7 +61,6 @@ public class Main | |||
61 | public void keyPressed(KeyEvent ke) | 61 | public void keyPressed(KeyEvent ke) |
62 | { | 62 | { |
63 | inputables.peek().processInput(ke); | 63 | inputables.peek().processInput(ke); |
64 | gameState.tick(); | ||
65 | } | 64 | } |
66 | 65 | ||
67 | @Override | 66 | @Override |
@@ -77,8 +76,6 @@ public class Main | |||
77 | 76 | ||
78 | setGameState(new MapViewGameState()); | 77 | setGameState(new MapViewGameState()); |
79 | 78 | ||
80 | gameState.tick(); | ||
81 | |||
82 | long waitTime = System.nanoTime() + (1000000*FPS); | 79 | long waitTime = System.nanoTime() + (1000000*FPS); |
83 | for (;;) | 80 | for (;;) |
84 | { | 81 | { |
diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index 543ce0b..2ecaeb1 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java | |||
@@ -37,22 +37,6 @@ public class MapViewGameState implements GameState | |||
37 | } | 37 | } |
38 | } | 38 | } |
39 | } | 39 | } |
40 | |||
41 | public void tick() | ||
42 | { | ||
43 | Random r = new Random(); | ||
44 | |||
45 | if (r.nextBoolean()) | ||
46 | { | ||
47 | for (int x=0; x<GAME_WIDTH; x++) | ||
48 | { | ||
49 | for (int y=0; y<GAME_HEIGHT; y++) | ||
50 | { | ||
51 | grid[x][y] = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)); | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | 40 | ||
57 | public void render(Graphics2D g) | 41 | public void render(Graphics2D g) |
58 | { | 42 | { |
@@ -67,9 +51,7 @@ public class MapViewGameState implements GameState | |||
67 | } | 51 | } |
68 | 52 | ||
69 | // Render player | 53 | // Render player |
70 | g.setColor(Color.white); | 54 | g.drawImage(SystemFont.getCharacter('@'), playerx*TILE_WIDTH, playery*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); |
71 | g.setFont(new Font("Lucida Sans", Font.BOLD, 16)); | ||
72 | g.drawString("@", playerx*TILE_WIDTH+3, (playery+1)*TILE_HEIGHT); | ||
73 | } | 55 | } |
74 | 56 | ||
75 | public void processInput(KeyEvent e) | 57 | public void processInput(KeyEvent e) |
@@ -98,6 +80,21 @@ public class MapViewGameState implements GameState | |||
98 | { | 80 | { |
99 | playery++; | 81 | playery++; |
100 | } | 82 | } |
83 | } else { | ||
84 | return; | ||
85 | } | ||
86 | |||
87 | Random r = new Random(); | ||
88 | |||
89 | if (r.nextBoolean()) | ||
90 | { | ||
91 | for (int x=0; x<GAME_WIDTH; x++) | ||
92 | { | ||
93 | for (int y=0; y<GAME_HEIGHT; y++) | ||
94 | { | ||
95 | grid[x][y] = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)); | ||
96 | } | ||
97 | } | ||
101 | } | 98 | } |
102 | } | 99 | } |
103 | } | 100 | } |
diff --git a/src/com/fourisland/frigidearth/SystemFont.java b/src/com/fourisland/frigidearth/SystemFont.java new file mode 100644 index 0000000..2ea5057 --- /dev/null +++ b/src/com/fourisland/frigidearth/SystemFont.java | |||
@@ -0,0 +1,52 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | package com.fourisland.frigidearth; | ||
6 | |||
7 | import java.awt.GraphicsConfiguration; | ||
8 | import java.awt.GraphicsDevice; | ||
9 | import java.awt.GraphicsEnvironment; | ||
10 | import java.awt.Toolkit; | ||
11 | import java.awt.Transparency; | ||
12 | import java.awt.image.BufferedImage; | ||
13 | import java.awt.image.FilteredImageSource; | ||
14 | import java.io.IOException; | ||
15 | import java.util.logging.Level; | ||
16 | import java.util.logging.Logger; | ||
17 | import javax.imageio.ImageIO; | ||
18 | |||
19 | /** | ||
20 | * | ||
21 | * @author hatkirby | ||
22 | */ | ||
23 | public class SystemFont | ||
24 | { | ||
25 | private static BufferedImage fontGraphic = null; | ||
26 | |||
27 | public static void initalize() | ||
28 | { | ||
29 | try | ||
30 | { | ||
31 | BufferedImage temp = ImageIO.read(SystemFont.class.getResourceAsStream("resources/font2.png")); | ||
32 | GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); | ||
33 | GraphicsDevice device = env.getDefaultScreenDevice(); | ||
34 | GraphicsConfiguration config = device.getDefaultConfiguration(); | ||
35 | fontGraphic = config.createCompatibleImage(temp.getWidth(), temp.getHeight(), Transparency.TRANSLUCENT); | ||
36 | fontGraphic.createGraphics().drawImage(Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(temp.getSource(), new TransparentPixelFilter(temp.getRGB(0, 0)))),0,0,null); | ||
37 | } catch (IOException ex) | ||
38 | { | ||
39 | Logger.getLogger(SystemFont.class.getName()).log(Level.SEVERE, null, ex); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | public static BufferedImage getCharacter(char c) | ||
44 | { | ||
45 | if (fontGraphic == null) | ||
46 | { | ||
47 | initalize(); | ||
48 | } | ||
49 | |||
50 | return fontGraphic.getSubimage((c % 16) * 12, (c / 16) * 12, 12, 12); | ||
51 | } | ||
52 | } | ||
diff --git a/src/com/fourisland/frigidearth/TransparentPixelFilter.java b/src/com/fourisland/frigidearth/TransparentPixelFilter.java new file mode 100644 index 0000000..3f7e92b --- /dev/null +++ b/src/com/fourisland/frigidearth/TransparentPixelFilter.java | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.frigidearth; | ||
7 | |||
8 | import java.awt.image.RGBImageFilter; | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | * @author hatkirby | ||
13 | */ | ||
14 | public class TransparentPixelFilter extends RGBImageFilter { | ||
15 | |||
16 | private int trans; | ||
17 | public TransparentPixelFilter(int i) | ||
18 | { | ||
19 | trans = i; | ||
20 | |||
21 | canFilterIndexColorModel = true; | ||
22 | } | ||
23 | |||
24 | @Override | ||
25 | public int filterRGB(int x, int y, int rgb) | ||
26 | { | ||
27 | if (rgb == trans) | ||
28 | { | ||
29 | return 0; | ||
30 | } else { | ||
31 | return rgb; | ||
32 | } | ||
33 | } | ||
34 | |||
35 | } | ||
diff --git a/src/com/fourisland/frigidearth/resources/RMG2000.ttf b/src/com/fourisland/frigidearth/resources/RMG2000.ttf deleted file mode 100644 index 5012ff1..0000000 --- a/src/com/fourisland/frigidearth/resources/RMG2000.ttf +++ /dev/null | |||
Binary files differ | |||
diff --git a/src/com/fourisland/frigidearth/resources/font2.png b/src/com/fourisland/frigidearth/resources/font2.png new file mode 100644 index 0000000..540690c --- /dev/null +++ b/src/com/fourisland/frigidearth/resources/font2.png | |||
Binary files differ | |||