From de89b524f3f42c8d875b9fe432f46275c2819b94 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 3 Jun 2012 16:37:20 -0400 Subject: Added colored characters --- src/com/fourisland/frigidearth/MapViewGameState.java | 8 ++++---- src/com/fourisland/frigidearth/Mob.java | 2 ++ src/com/fourisland/frigidearth/SystemFont.java | 20 ++++++++++++-------- .../frigidearth/TransparentPixelFilter.java | 6 ++++-- src/com/fourisland/frigidearth/mobs/Mouse.java | 6 ++++++ 5 files changed, 28 insertions(+), 14 deletions(-) (limited to 'src/com') diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index 86fe437..08bb151 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java @@ -510,7 +510,7 @@ public class MapViewGameState implements GameState if (displayChar != ' ') { - g.drawImage(SystemFont.getCharacter(grid[x][y].getDisplayCharacter()), (x-viewportx)*TILE_WIDTH, (y-viewporty)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); + g.drawImage(SystemFont.getCharacter(grid[x][y].getDisplayCharacter(), Color.WHITE), (x-viewportx)*TILE_WIDTH, (y-viewporty)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); } } } @@ -521,12 +521,12 @@ public class MapViewGameState implements GameState { if ((gridLighting[mob.x][mob.y]) && (isInViewport(mob.x, mob.y))) { - g.drawImage(SystemFont.getCharacter(mob.getDisplayCharacter()), (mob.x-viewportx)*TILE_WIDTH, (mob.y-viewporty)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); + g.drawImage(SystemFont.getCharacter(mob.getDisplayCharacter(), mob.getDisplayColor()), (mob.x-viewportx)*TILE_WIDTH, (mob.y-viewporty)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); } } // Render player - g.drawImage(SystemFont.getCharacter('@'), (playerx-viewportx)*TILE_WIDTH, (playery-viewporty)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); + g.drawImage(SystemFont.getCharacter('@', Color.WHITE), (playerx-viewportx)*TILE_WIDTH, (playery-viewporty)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); // Render messages g.setColor(new Color(53, 63, 62)); @@ -538,7 +538,7 @@ public class MapViewGameState implements GameState { for (int j=0; j fontGraphic = new HashMap(); - public static void initalize() + public static void initalize(Color color) { try { @@ -32,21 +35,22 @@ public class SystemFont GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = env.getDefaultScreenDevice(); GraphicsConfiguration config = device.getDefaultConfiguration(); - fontGraphic = config.createCompatibleImage(temp.getWidth(), temp.getHeight(), Transparency.TRANSLUCENT); - fontGraphic.createGraphics().drawImage(Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(temp.getSource(), new TransparentPixelFilter(temp.getRGB(0, 0)))),0,0,null); + BufferedImage g = config.createCompatibleImage(temp.getWidth(), temp.getHeight(), Transparency.TRANSLUCENT); + g.createGraphics().drawImage(Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(temp.getSource(), new TransparentPixelFilter(temp.getRGB(0, 0), color.getRGB()))),0,0,null); + fontGraphic.put(color, g); } catch (IOException ex) { Logger.getLogger(SystemFont.class.getName()).log(Level.SEVERE, null, ex); } } - public static BufferedImage getCharacter(char c) + public static BufferedImage getCharacter(char c, Color color) { - if (fontGraphic == null) + if (!fontGraphic.containsKey(color)) { - initalize(); + initalize(color); } - return fontGraphic.getSubimage((c % 16) * 12, (c / 16) * 12, 12, 12); + return fontGraphic.get(color).getSubimage((c % 16) * 12, (c / 16) * 12, 12, 12); } } diff --git a/src/com/fourisland/frigidearth/TransparentPixelFilter.java b/src/com/fourisland/frigidearth/TransparentPixelFilter.java index 3f7e92b..6821caf 100644 --- a/src/com/fourisland/frigidearth/TransparentPixelFilter.java +++ b/src/com/fourisland/frigidearth/TransparentPixelFilter.java @@ -14,9 +14,11 @@ import java.awt.image.RGBImageFilter; public class TransparentPixelFilter extends RGBImageFilter { private int trans; - public TransparentPixelFilter(int i) + private int replace; + public TransparentPixelFilter(int i, int j) { trans = i; + replace = j; canFilterIndexColorModel = true; } @@ -28,7 +30,7 @@ public class TransparentPixelFilter extends RGBImageFilter { { return 0; } else { - return rgb; + return replace; } } diff --git a/src/com/fourisland/frigidearth/mobs/Mouse.java b/src/com/fourisland/frigidearth/mobs/Mouse.java index 5fdf7cd..af9fe44 100644 --- a/src/com/fourisland/frigidearth/mobs/Mouse.java +++ b/src/com/fourisland/frigidearth/mobs/Mouse.java @@ -5,6 +5,7 @@ package com.fourisland.frigidearth.mobs; import com.fourisland.frigidearth.Mob; +import java.awt.Color; /** * @@ -24,6 +25,11 @@ public class Mouse extends Mob return 'm'; } + public Color getDisplayColor() + { + return Color.GRAY; + } + public String getName() { return "Mouse"; -- cgit 1.4.1