diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/fourisland/frigidearth/MapViewGameState.java | 26 | ||||
-rw-r--r-- | src/com/fourisland/frigidearth/Mob.java | 2 | ||||
-rw-r--r-- | src/com/fourisland/frigidearth/mobs/Mouse.java | 5 | ||||
-rw-r--r-- | src/com/fourisland/frigidearth/mobs/Rat.java | 6 |
4 files changed, 38 insertions, 1 deletions
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 | |||
44 | private int viewportx = 0; | 44 | private int viewportx = 0; |
45 | private int viewporty = 0; | 45 | private int viewporty = 0; |
46 | private int health = 15; | 46 | private int health = 15; |
47 | private int maxHealth = 15; | ||
48 | private int defense = 0; | ||
47 | 49 | ||
48 | public MapViewGameState() | 50 | public MapViewGameState() |
49 | { | 51 | { |
@@ -555,10 +557,30 @@ public class MapViewGameState implements GameState | |||
555 | // Render status bar | 557 | // Render status bar |
556 | g.drawImage(SystemFont.getCharacter((char) 3, Color.RED), TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null); | 558 | g.drawImage(SystemFont.getCharacter((char) 3, Color.RED), TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null); |
557 | String healthText = Integer.toString(health); | 559 | String healthText = Integer.toString(health); |
560 | double healthPercentage = ((double) health) / ((double) maxHealth); | ||
561 | Color healthColor = Color.WHITE; | ||
562 | if (healthPercentage < 0.2) | ||
563 | { | ||
564 | healthColor = Color.RED; | ||
565 | } else if (healthPercentage < 0.55) | ||
566 | { | ||
567 | healthColor = Color.YELLOW; | ||
568 | } else if (healthPercentage < 1) | ||
569 | { | ||
570 | healthColor = Color.GREEN; | ||
571 | } | ||
558 | 572 | ||
559 | for (int i=0; i<healthText.length(); i++) | 573 | for (int i=0; i<healthText.length(); i++) |
560 | { | 574 | { |
561 | g.drawImage(SystemFont.getCharacter(healthText.charAt(i), Color.WHITE), (i+2)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null); | 575 | g.drawImage(SystemFont.getCharacter(healthText.charAt(i), healthColor), (i+2)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null); |
576 | } | ||
577 | |||
578 | g.drawImage(SystemFont.getCharacter((char) 5, Color.GRAY), (healthText.length()+3)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null); | ||
579 | int b = healthText.length()+4; | ||
580 | String defenseText = Integer.toBinaryString(defense); | ||
581 | for (int i=0; i<defenseText.length(); i++) | ||
582 | { | ||
583 | g.drawImage(SystemFont.getCharacter(defenseText.charAt(i), Color.WHITE), (i+b)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null); | ||
562 | } | 584 | } |
563 | } | 585 | } |
564 | 586 | ||
@@ -622,6 +644,8 @@ public class MapViewGameState implements GameState | |||
622 | if (arePointsAdjacent(playerx, playery, mob.x, mob.y)) | 644 | if (arePointsAdjacent(playerx, playery, mob.x, mob.y)) |
623 | { | 645 | { |
624 | // Attack! | 646 | // Attack! |
647 | health -= (mob.power - defense); | ||
648 | printMessage(mob.getBattleMessage()); | ||
625 | } else { | 649 | } else { |
626 | List<Direction> path = findPath(mob.getPosition(), new Point(playerx, playery)); | 650 | List<Direction> path = findPath(mob.getPosition(), new Point(playerx, playery)); |
627 | 651 | ||
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 | |||
17 | public int y; | 17 | public int y; |
18 | public int health; | 18 | public int health; |
19 | public boolean hostile; | 19 | public boolean hostile; |
20 | public int power; | ||
20 | 21 | ||
21 | public Mob(int x, int y) | 22 | public Mob(int x, int y) |
22 | { | 23 | { |
@@ -39,4 +40,5 @@ public abstract class Mob | |||
39 | public abstract char getDisplayCharacter(); | 40 | public abstract char getDisplayCharacter(); |
40 | public abstract Color getDisplayColor(); | 41 | public abstract Color getDisplayColor(); |
41 | public abstract String getName(); | 42 | public abstract String getName(); |
43 | public abstract String getBattleMessage(); | ||
42 | } | 44 | } |
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 | |||
35 | { | 35 | { |
36 | return "Mouse"; | 36 | return "Mouse"; |
37 | } | 37 | } |
38 | |||
39 | public String getBattleMessage() | ||
40 | { | ||
41 | return "The mouse bites you"; | ||
42 | } | ||
38 | } | 43 | } |
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 | |||
20 | 20 | ||
21 | health = Functions.rollDice(1, 4); | 21 | health = Functions.rollDice(1, 4); |
22 | hostile = true; | 22 | hostile = true; |
23 | power = 1; | ||
23 | } | 24 | } |
24 | 25 | ||
25 | public char getDisplayCharacter() | 26 | public char getDisplayCharacter() |
@@ -37,4 +38,9 @@ public class Rat extends Mob | |||
37 | return "Rat"; | 38 | return "Rat"; |
38 | } | 39 | } |
39 | 40 | ||
41 | public String getBattleMessage() | ||
42 | { | ||
43 | return "The rat bites you"; | ||
44 | } | ||
45 | |||
40 | } | 46 | } |