From 4b31634a783ec039d2340cce7477f8e0969efb6a Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 3 Jun 2012 20:45:22 -0400 Subject: Added basic melee combat Rats can now hurt you, yaaaay. Your health counter changes color depending on how much HP you have, and there is now also a defense counter too, which will, at this point, always say zero. --- .../fourisland/frigidearth/MapViewGameState.java | 26 +++++++++++++++++++++- src/com/fourisland/frigidearth/Mob.java | 2 ++ src/com/fourisland/frigidearth/mobs/Mouse.java | 5 +++++ src/com/fourisland/frigidearth/mobs/Rat.java | 6 +++++ 4 files changed, 38 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index 0371c6a..5e16219 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java @@ -44,6 +44,8 @@ public class MapViewGameState implements GameState private int viewportx = 0; private int viewporty = 0; private int health = 15; + private int maxHealth = 15; + private int defense = 0; public MapViewGameState() { @@ -555,10 +557,30 @@ public class MapViewGameState implements GameState // Render status bar g.drawImage(SystemFont.getCharacter((char) 3, Color.RED), TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null); String healthText = Integer.toString(health); + double healthPercentage = ((double) health) / ((double) maxHealth); + Color healthColor = Color.WHITE; + if (healthPercentage < 0.2) + { + healthColor = Color.RED; + } else if (healthPercentage < 0.55) + { + healthColor = Color.YELLOW; + } else if (healthPercentage < 1) + { + healthColor = Color.GREEN; + } for (int i=0; i path = findPath(mob.getPosition(), new Point(playerx, playery)); diff --git a/src/com/fourisland/frigidearth/Mob.java b/src/com/fourisland/frigidearth/Mob.java index 412c11e..c35b276 100644 --- a/src/com/fourisland/frigidearth/Mob.java +++ b/src/com/fourisland/frigidearth/Mob.java @@ -17,6 +17,7 @@ public abstract class Mob public int y; public int health; public boolean hostile; + public int power; public Mob(int x, int y) { @@ -39,4 +40,5 @@ public abstract class Mob public abstract char getDisplayCharacter(); public abstract Color getDisplayColor(); public abstract String getName(); + public abstract String getBattleMessage(); } diff --git a/src/com/fourisland/frigidearth/mobs/Mouse.java b/src/com/fourisland/frigidearth/mobs/Mouse.java index 3430a00..17f5f94 100644 --- a/src/com/fourisland/frigidearth/mobs/Mouse.java +++ b/src/com/fourisland/frigidearth/mobs/Mouse.java @@ -35,4 +35,9 @@ public class Mouse extends Mob { return "Mouse"; } + + public String getBattleMessage() + { + return "The mouse bites you"; + } } diff --git a/src/com/fourisland/frigidearth/mobs/Rat.java b/src/com/fourisland/frigidearth/mobs/Rat.java index c2aecd4..0603bb1 100644 --- a/src/com/fourisland/frigidearth/mobs/Rat.java +++ b/src/com/fourisland/frigidearth/mobs/Rat.java @@ -20,6 +20,7 @@ public class Rat extends Mob health = Functions.rollDice(1, 4); hostile = true; + power = 1; } public char getDisplayCharacter() @@ -37,4 +38,9 @@ public class Rat extends Mob return "Rat"; } + public String getBattleMessage() + { + return "The rat bites you"; + } + } -- cgit 1.4.1