about summary refs log tree commit diff stats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rw-r--r--src/com/fourisland/frigidearth/Functions.java18
-rw-r--r--src/com/fourisland/frigidearth/MapViewGameState.java50
-rw-r--r--src/com/fourisland/frigidearth/Mob.java3
-rw-r--r--src/com/fourisland/frigidearth/mobs/Mouse.java10
-rw-r--r--src/com/fourisland/frigidearth/mobs/Rat.java10
-rw-r--r--src/com/fourisland/frigidearth/mobs/Spider.java54
6 files changed, 134 insertions, 11 deletions
diff --git a/src/com/fourisland/frigidearth/Functions.java b/src/com/fourisland/frigidearth/Functions.java index 32943ce..f01f3a0 100644 --- a/src/com/fourisland/frigidearth/Functions.java +++ b/src/com/fourisland/frigidearth/Functions.java
@@ -30,4 +30,22 @@ public class Functions
30 30
31 return result; 31 return result;
32 } 32 }
33
34 public static String padLeft(String str, int length, char pad)
35 {
36 int padding = length - str.length();
37 if (str.length() > length)
38 {
39 return str;
40 }
41
42 StringBuilder sb = new StringBuilder();
43 for (int i=0; i<padding; i++)
44 {
45 sb.append(pad);
46 }
47
48 sb.append(str);
49 return sb.toString();
50 }
33} 51}
diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index 9bee398..b77803b 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java
@@ -6,6 +6,7 @@ package com.fourisland.frigidearth;
6 6
7import com.fourisland.frigidearth.mobs.Mouse; 7import com.fourisland.frigidearth.mobs.Mouse;
8import com.fourisland.frigidearth.mobs.Rat; 8import com.fourisland.frigidearth.mobs.Rat;
9import com.fourisland.frigidearth.mobs.Spider;
9import java.awt.Color; 10import java.awt.Color;
10import java.awt.Graphics2D; 11import java.awt.Graphics2D;
11import java.awt.Point; 12import java.awt.Point;
@@ -54,6 +55,8 @@ public class MapViewGameState implements GameState
54 private int heartbeat = 0; 55 private int heartbeat = 0;
55 private int floor; 56 private int floor;
56 private int spawnTimer = 0; 57 private int spawnTimer = 0;
58 private int level = 1;
59 private int experience = 0;
57 60
58 public MapViewGameState(int floor) 61 public MapViewGameState(int floor)
59 { 62 {
@@ -737,11 +740,30 @@ public class MapViewGameState implements GameState
737 740
738 g.drawImage(SystemFont.getCharacter((char) 5, Color.GRAY), (healthText.length()+3)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null); 741 g.drawImage(SystemFont.getCharacter((char) 5, Color.GRAY), (healthText.length()+3)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null);
739 int b = healthText.length()+4; 742 int b = healthText.length()+4;
740 String defenseText = Integer.toBinaryString(defense); 743 String defenseText = Integer.toString(defense);
741 for (int i=0; i<defenseText.length(); i++) 744 for (int i=0; i<defenseText.length(); i++)
742 { 745 {
743 g.drawImage(SystemFont.getCharacter(defenseText.charAt(i), Color.WHITE), (i+b)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null); 746 g.drawImage(SystemFont.getCharacter(defenseText.charAt(i), Color.WHITE), (i+b)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null);
744 } 747 }
748
749 b+=defenseText.length()+1;
750 g.drawImage(SystemFont.getCharacter('E', Color.WHITE), (b)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null);
751 g.drawImage(SystemFont.getCharacter('X', Color.WHITE), (b+1)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null);
752 g.drawImage(SystemFont.getCharacter('P', Color.WHITE), (b+2)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null);
753 b+=3;
754 String expText = Functions.padLeft(Integer.toString(experience), 3, '0');
755 for (int i=0; i<expText.length(); i++)
756 {
757 g.drawImage(SystemFont.getCharacter(expText.charAt(i), Color.WHITE), (i+b)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null);
758 }
759 b+=expText.length();
760 g.drawImage(SystemFont.getCharacter(':', Color.WHITE), (b)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null);
761 b++;
762 String levelText = Integer.toString(level);
763 for (int i=0; i<levelText.length(); i++)
764 {
765 g.drawImage(SystemFont.getCharacter(levelText.charAt(i), Color.WHITE), (i+b)*TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT, null);
766 }
745 } 767 }
746 768
747 public void processInput(KeyEvent e) 769 public void processInput(KeyEvent e)
@@ -765,12 +787,21 @@ public class MapViewGameState implements GameState
765 if (mob.getPosition().equals(to)) 787 if (mob.getPosition().equals(to))
766 { 788 {
767 printMessage("You hit the " + mob.getName().toLowerCase()); 789 printMessage("You hit the " + mob.getName().toLowerCase());
768 mob.health--; 790 mob.health -= level;
769 791
770 if (mob.health <= 0) 792 if (mob.health <= 0)
771 { 793 {
772 printMessage("You killed the " + mob.getName().toLowerCase() + "!"); 794 printMessage("You killed the " + mob.getName().toLowerCase() + "!");
795 experience += (mob.getBaseExperience()/level);
773 mobs.remove(mob); 796 mobs.remove(mob);
797
798 if (experience > 1000)
799 {
800 level++;
801 experience -= 1000;
802
803 printMessage("You grow to level " + level + "!");
804 }
774 } 805 }
775 806
776 foundMob = true; 807 foundMob = true;
@@ -827,10 +858,10 @@ public class MapViewGameState implements GameState
827 // Also, if it is adjacent to the player, it should attack 858 // Also, if it is adjacent to the player, it should attack
828 if ((mob.hostile) && (canSeePlayer(mob.x, mob.y))) 859 if ((mob.hostile) && (canSeePlayer(mob.x, mob.y)))
829 { 860 {
830 if (arePointsAdjacent(playerx, playery, mob.x, mob.y)) 861 if (arePointsAdjacent(playerx, playery, mob.x, mob.y, false))
831 { 862 {
832 // Attack! 863 // Attack!
833 health -= (mob.power - defense); 864 health -= (mob.getAttackPower() - defense);
834 printMessage(mob.getBattleMessage()); 865 printMessage(mob.getBattleMessage());
835 } else { 866 } else {
836 List<Direction> path = findPath(mob.getPosition(), new Point(playerx, playery)); 867 List<Direction> path = findPath(mob.getPosition(), new Point(playerx, playery));
@@ -1095,22 +1126,22 @@ public class MapViewGameState implements GameState
1095 } 1126 }
1096 } 1127 }
1097 1128
1098 private boolean arePointsAdjacent(int px, int py, int mx, int my) 1129 private boolean arePointsAdjacent(int px, int py, int mx, int my, boolean includeDiagonals)
1099 { 1130 {
1100 if (mx == (px-1)) 1131 if (mx == (px-1))
1101 { 1132 {
1102 if (my == (py-1)) return true; 1133 if ((my == (py-1)) && (includeDiagonals)) return true;
1103 if (my == py) return true; 1134 if (my == py) return true;
1104 if (my == (py+1)) return true; 1135 if ((my == (py+1)) && (includeDiagonals)) return true;
1105 } else if (mx == px) 1136 } else if (mx == px)
1106 { 1137 {
1107 if (my == (py-1)) return true; 1138 if (my == (py-1)) return true;
1108 if (my == (py+1)) return true; 1139 if (my == (py+1)) return true;
1109 } else if (mx == (px+1)) 1140 } else if (mx == (px+1))
1110 { 1141 {
1111 if (my == (py-1)) return true; 1142 if ((my == (py-1)) && (includeDiagonals)) return true;
1112 if (my == py) return true; 1143 if (my == py) return true;
1113 if (my == (py+1)) return true; 1144 if ((my == (py+1)) && (includeDiagonals)) return true;
1114 } 1145 }
1115 1146
1116 return false; 1147 return false;
@@ -1228,6 +1259,7 @@ public class MapViewGameState implements GameState
1228 case 1: 1259 case 1:
1229 mobTypes.add(Mouse.class); 1260 mobTypes.add(Mouse.class);
1230 mobTypes.add(Rat.class); 1261 mobTypes.add(Rat.class);
1262 mobTypes.add(Spider.class);
1231 } 1263 }
1232 1264
1233 try 1265 try
diff --git a/src/com/fourisland/frigidearth/Mob.java b/src/com/fourisland/frigidearth/Mob.java index c35b276..f3bfe6a 100644 --- a/src/com/fourisland/frigidearth/Mob.java +++ b/src/com/fourisland/frigidearth/Mob.java
@@ -17,7 +17,6 @@ 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;
21 20
22 public Mob(int x, int y) 21 public Mob(int x, int y)
23 { 22 {
@@ -41,4 +40,6 @@ public abstract class Mob
41 public abstract Color getDisplayColor(); 40 public abstract Color getDisplayColor();
42 public abstract String getName(); 41 public abstract String getName();
43 public abstract String getBattleMessage(); 42 public abstract String getBattleMessage();
43 public abstract int getAttackPower();
44 public abstract int getBaseExperience();
44} 45}
diff --git a/src/com/fourisland/frigidearth/mobs/Mouse.java b/src/com/fourisland/frigidearth/mobs/Mouse.java index 17f5f94..6966764 100644 --- a/src/com/fourisland/frigidearth/mobs/Mouse.java +++ b/src/com/fourisland/frigidearth/mobs/Mouse.java
@@ -40,4 +40,14 @@ public class Mouse extends Mob
40 { 40 {
41 return "The mouse bites you"; 41 return "The mouse bites you";
42 } 42 }
43
44 public int getAttackPower()
45 {
46 return 0;
47 }
48
49 public int getBaseExperience()
50 {
51 return 50;
52 }
43} 53}
diff --git a/src/com/fourisland/frigidearth/mobs/Rat.java b/src/com/fourisland/frigidearth/mobs/Rat.java index 0603bb1..f7277c6 100644 --- a/src/com/fourisland/frigidearth/mobs/Rat.java +++ b/src/com/fourisland/frigidearth/mobs/Rat.java
@@ -20,7 +20,6 @@ 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;
24 } 23 }
25 24
26 public char getDisplayCharacter() 25 public char getDisplayCharacter()
@@ -43,4 +42,13 @@ public class Rat extends Mob
43 return "The rat bites you"; 42 return "The rat bites you";
44 } 43 }
45 44
45 public int getAttackPower()
46 {
47 return 1;
48 }
49
50 public int getBaseExperience()
51 {
52 return 100;
53 }
46} 54}
diff --git a/src/com/fourisland/frigidearth/mobs/Spider.java b/src/com/fourisland/frigidearth/mobs/Spider.java new file mode 100644 index 0000000..58a554b --- /dev/null +++ b/src/com/fourisland/frigidearth/mobs/Spider.java
@@ -0,0 +1,54 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package com.fourisland.frigidearth.mobs;
6
7import com.fourisland.frigidearth.Functions;
8import com.fourisland.frigidearth.Mob;
9import java.awt.Color;
10
11/**
12 *
13 * @author hatkirby
14 */
15public class Spider extends Mob
16{
17 public Spider(int x, int y)
18 {
19 super(x, y);
20
21 health = Functions.rollDice(2, 5);
22 hostile = true;
23 }
24
25 public char getDisplayCharacter()
26 {
27 return 's';
28 }
29
30 public Color getDisplayColor()
31 {
32 return Color.BLACK;
33 }
34
35 public String getName()
36 {
37 return "Spider";
38 }
39
40 public String getBattleMessage()
41 {
42 return "The spider bites you";
43 }
44
45 public int getAttackPower()
46 {
47 return 2;
48 }
49
50 public int getBaseExperience()
51 {
52 return 200;
53 }
54}