about summary refs log tree commit diff stats
path: root/src/com
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2012-06-06 08:38:55 -0400
committerStarla Insigna <hatkirby@fourisland.com>2012-06-06 08:38:55 -0400
commit243e560a77e4ad2f18a419c0fe350d506d1a5f24 (patch)
treea02da3d48a6ac6c5b717dbf626fd580ef819bb46 /src/com
parent281676bfa6a06c379887e5c8bb6d28217394a3e2 (diff)
downloadfrigidearth-243e560a77e4ad2f18a419c0fe350d506d1a5f24.tar.gz
frigidearth-243e560a77e4ad2f18a419c0fe350d506d1a5f24.tar.bz2
frigidearth-243e560a77e4ad2f18a419c0fe350d506d1a5f24.zip
Doors now start closed and can be opened or closed
Diffstat (limited to 'src/com')
-rw-r--r--src/com/fourisland/frigidearth/MapViewGameState.java284
-rw-r--r--src/com/fourisland/frigidearth/Tile.java20
2 files changed, 183 insertions, 121 deletions
diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index bd3471f..367e340 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java
@@ -50,6 +50,8 @@ public class MapViewGameState implements GameState
50 private int heartbeat = 0; 50 private int heartbeat = 0;
51 private int floor; 51 private int floor;
52 private int spawnTimer = 0; 52 private int spawnTimer = 0;
53 private boolean closingDoor = false;
54 private Renderable messageOverlay = null;
53 55
54 public MapViewGameState(int floor) 56 public MapViewGameState(int floor)
55 { 57 {
@@ -144,16 +146,16 @@ public class MapViewGameState implements GameState
144 146
145 if (validTile != null) 147 if (validTile != null)
146 { 148 {
147 if (grid[newx][newy+1] == Tile.Door) 149 if ((grid[newx][newy+1] == Tile.ClosedDoor) || (grid[newx][newy+1] == Tile.OpenDoor))
148 { 150 {
149 validTile = null; 151 validTile = null;
150 } else if (grid[newx-1][newy] == Tile.Door) 152 } else if ((grid[newx-1][newy] == Tile.ClosedDoor) || (grid[newx-1][newy] == Tile.OpenDoor))
151 { 153 {
152 validTile = null; 154 validTile = null;
153 } else if (grid[newx][newy-1] == Tile.Door) 155 } else if ((grid[newx][newy-1] == Tile.ClosedDoor) || (grid[newx][newy-1] == Tile.OpenDoor))
154 { 156 {
155 validTile = null; 157 validTile = null;
156 } else if (grid[newx+1][newy] == Tile.Door) 158 } else if ((grid[newx+1][newy] == Tile.ClosedDoor) || (grid[newx+1][newy] == Tile.OpenDoor))
157 { 159 {
158 validTile = null; 160 validTile = null;
159 } 161 }
@@ -173,14 +175,14 @@ public class MapViewGameState implements GameState
173 if (makeRoom(newx+xmod, newy+ymod, validTile, legalBounds)) 175 if (makeRoom(newx+xmod, newy+ymod, validTile, legalBounds))
174 { 176 {
175 currentFeatures++; 177 currentFeatures++;
176 grid[newx][newy] = Tile.Door; 178 grid[newx][newy] = Tile.ClosedDoor;
177 grid[newx+xmod][newy+ymod] = Tile.DirtFloor; 179 grid[newx+xmod][newy+ymod] = Tile.DirtFloor;
178 } 180 }
179 } else { 181 } else {
180 if (makeCorridor(newx+xmod, newy+ymod, validTile)) 182 if (makeCorridor(newx+xmod, newy+ymod, validTile))
181 { 183 {
182 currentFeatures++; 184 currentFeatures++;
183 grid[newx][newy] = Tile.Door; 185 grid[newx][newy] = Tile.ClosedDoor;
184 } 186 }
185 } 187 }
186 } 188 }
@@ -320,28 +322,28 @@ public class MapViewGameState implements GameState
320 switch (keyRoomDirection) 322 switch (keyRoomDirection)
321 { 323 {
322 case North: 324 case North:
323 grid[room.getX()+room.getWidth()/2][room.getY()+room.getHeight()] = Tile.Door; 325 grid[room.getX()+room.getWidth()/2][room.getY()+room.getHeight()] = Tile.ClosedDoor;
324 grid[room.getX()+room.getWidth()/2][room.getY()+room.getHeight()-1] = Tile.DirtFloor; 326 grid[room.getX()+room.getWidth()/2][room.getY()+room.getHeight()-1] = Tile.DirtFloor;
325 key.x = room.getX()+3; 327 key.x = room.getX()+3;
326 key.y = room.getY()+3; 328 key.y = room.getY()+3;
327 break; 329 break;
328 330
329 case East: 331 case East:
330 grid[room.getX()-1][room.getY()+room.getHeight()/2] = Tile.Door; 332 grid[room.getX()-1][room.getY()+room.getHeight()/2] = Tile.ClosedDoor;
331 grid[room.getX()][room.getY()+room.getHeight()/2] = Tile.DirtFloor; 333 grid[room.getX()][room.getY()+room.getHeight()/2] = Tile.DirtFloor;
332 key.x = room.getX()+10; 334 key.x = room.getX()+10;
333 key.y = room.getY()+3; 335 key.y = room.getY()+3;
334 break; 336 break;
335 337
336 case South: 338 case South:
337 grid[room.getX()+room.getWidth()/2][room.getY()-1] = Tile.Door; 339 grid[room.getX()+room.getWidth()/2][room.getY()-1] = Tile.ClosedDoor;
338 grid[room.getX()+room.getWidth()/2][room.getY()] = Tile.DirtFloor; 340 grid[room.getX()+room.getWidth()/2][room.getY()] = Tile.DirtFloor;
339 key.x = room.getX()+3; 341 key.x = room.getX()+3;
340 key.y = room.getY()+10; 342 key.y = room.getY()+10;
341 break; 343 break;
342 344
343 case West: 345 case West:
344 grid[room.getX()+room.getWidth()][room.getY()+room.getHeight()/2] = Tile.Door; 346 grid[room.getX()+room.getWidth()][room.getY()+room.getHeight()/2] = Tile.ClosedDoor;
345 grid[room.getX()+room.getWidth()-1][room.getY()+room.getHeight()/2] = Tile.DirtFloor; 347 grid[room.getX()+room.getWidth()-1][room.getY()+room.getHeight()/2] = Tile.DirtFloor;
346 key.x = room.getX()+3; 348 key.x = room.getX()+3;
347 key.y = room.getY()+3; 349 key.y = room.getY()+3;
@@ -789,142 +791,186 @@ public class MapViewGameState implements GameState
789 791
790 public void processInput(KeyEvent e) 792 public void processInput(KeyEvent e)
791 { 793 {
792 // Handle input 794 if (closingDoor)
793 switch (e.getKeyCode())
794 { 795 {
795 case KeyEvent.VK_LEFT: 796 switch (e.getKeyCode())
796 case KeyEvent.VK_RIGHT: 797 {
797 case KeyEvent.VK_UP: 798 case KeyEvent.VK_LEFT:
798 case KeyEvent.VK_DOWN: 799 case KeyEvent.VK_RIGHT:
799 Direction dir = Direction.fromKeyEvent(e); 800 case KeyEvent.VK_UP:
800 Point to = dir.to(new Point(playerx, playery)); 801 case KeyEvent.VK_DOWN:
801 802 Direction dir = Direction.fromKeyEvent(e);
802 if ((isValidPosition(to.x,to.y)) && (!grid[to.x][to.y].isBlocked())) 803 Point to = dir.to(new Point(playerx, playery));
803 { 804
804 // Check for mobs 805 if ((isValidPosition(to.x,to.y)) && (grid[to.x][to.y] == Tile.OpenDoor))
805 boolean foundMob = false; 806 {
806 for (Mob mob : mobs) 807 grid[to.x][to.y] = Tile.ClosedDoor;
808 } else {
809 printMessage("There is no closed door in that direction");
810 }
811
812 case KeyEvent.VK_ESCAPE:
813 Main.removeRenderable(messageOverlay);
814 messageOverlay = null;
815 closingDoor = false;
816
817 break;
818
819 default:
820 return;
821 }
822 } else {
823 switch (e.getKeyCode())
824 {
825 case KeyEvent.VK_LEFT:
826 case KeyEvent.VK_RIGHT:
827 case KeyEvent.VK_UP:
828 case KeyEvent.VK_DOWN:
829 Direction dir = Direction.fromKeyEvent(e);
830 Point to = dir.to(new Point(playerx, playery));
831
832 if ((isValidPosition(to.x,to.y)) && (!grid[to.x][to.y].isBlocked()))
807 { 833 {
808 if (mob.getPosition().equals(to)) 834 // Check for mobs
835 boolean foundMob = false;
836 for (Mob mob : mobs)
809 { 837 {
810 printMessage("You hit the " + mob.getName().toLowerCase()); 838 if (mob.getPosition().equals(to))
811 mob.health -= Main.currentGame.getAttackPower();
812
813 if (mob.health <= 0)
814 { 839 {
815 printMessage("You killed the " + mob.getName().toLowerCase() + "!"); 840 printMessage("You hit the " + mob.getName().toLowerCase());
816 mobs.remove(mob); 841 mob.health -= Main.currentGame.getAttackPower();
817 842
818 Main.currentGame.experience += (mob.getBaseExperience()/(Main.currentGame.level*Main.currentGame.level)); 843 if (mob.health <= 0)
819 if (Main.currentGame.experience >= 1000)
820 {
821 Main.currentGame.level++;
822 Main.currentGame.experience -= 1000;
823
824 int hpGain = Functions.rollDice(6, 2) + 3;
825 Main.currentGame.health += hpGain;
826 Main.currentGame.maxHealth += hpGain;
827
828 printMessage("You grow to level " + Main.currentGame.level + "!");
829 }
830
831 if (Functions.random(0, 1000) < (mob.getBaseExperience() / (floor*floor)))
832 { 844 {
833 ItemInstance ii = new ItemInstance(); 845 printMessage("You killed the " + mob.getName().toLowerCase() + "!");
834 ii.item = Item.getWeightedRandomItem(); 846 mobs.remove(mob);
835 ii.x = mob.x; 847
836 ii.y = mob.y; 848 Main.currentGame.experience += (mob.getBaseExperience()/(Main.currentGame.level*Main.currentGame.level));
837 849 if (Main.currentGame.experience >= 1000)
838 items.add(ii); 850 {
851 Main.currentGame.level++;
852 Main.currentGame.experience -= 1000;
853
854 int hpGain = Functions.rollDice(6, 2) + 3;
855 Main.currentGame.health += hpGain;
856 Main.currentGame.maxHealth += hpGain;
857
858 printMessage("You grow to level " + Main.currentGame.level + "!");
859 }
860
861 if (Functions.random(0, 1000) < (mob.getBaseExperience() / (floor*floor)))
862 {
863 ItemInstance ii = new ItemInstance();
864 ii.item = Item.getWeightedRandomItem();
865 ii.x = mob.x;
866 ii.y = mob.y;
867
868 items.add(ii);
869 }
839 } 870 }
871
872 foundMob = true;
873 break;
840 } 874 }
841
842 foundMob = true;
843 break;
844 } 875 }
845 } 876
846 877 if (!foundMob)
847 if (!foundMob) 878 {
879 playerx = to.x;
880 playery = to.y;
881 }
882 } else if (grid[to.x][to.y] == Tile.ClosedDoor)
848 { 883 {
849 playerx = to.x; 884 if (Functions.random(0, 99) < 50)
850 playery = to.y; 885 {
886 grid[to.x][to.y] = Tile.OpenDoor;
887 } else {
888 printMessage("You cannot quite get the door to open");
889 }
890 } else {
891 printMessage("Blocked: " + dir.name());
892
893 return;
851 } 894 }
852 } else {
853 printMessage("Blocked: " + dir.name());
854
855 return;
856 }
857
858 break;
859
860 case KeyEvent.VK_G:
861 for (ItemInstance ii : items)
862 {
863 if ((ii.x == playerx) && (ii.y == playery))
864 {
865 printMessage("You get a " + ii.item.getItemName().toLowerCase());
866 Main.currentGame.inventory.add(ii.item);
867 items.remove(ii);
868 895
869 if (ii.item == Item.Key) 896 break;
897
898 case KeyEvent.VK_G:
899 for (ItemInstance ii : items)
900 {
901 if ((ii.x == playerx) && (ii.y == playery))
870 { 902 {
871 printMessage("All the windows in the room shatter!"); 903 printMessage("You get a " + ii.item.getItemName().toLowerCase());
904 Main.currentGame.inventory.add(ii.item);
905 items.remove(ii);
872 906
873 for (int x=0; x<mapWidth; x++) 907 if (ii.item == Item.Key)
874 { 908 {
875 for (int y=0; y<mapHeight; y++) 909 printMessage("All the windows in the room shatter!");
910
911 for (int x=0; x<mapWidth; x++)
876 { 912 {
877 if (grid[x][y] == Tile.Window) 913 for (int y=0; y<mapHeight; y++)
878 { 914 {
879 grid[x][y] = Tile.ShatteredWindow; 915 if (grid[x][y] == Tile.Window)
916 {
917 grid[x][y] = Tile.ShatteredWindow;
918 }
880 } 919 }
881 } 920 }
882 } 921 }
883 }
884 922
885 break; 923 break;
924 }
886 } 925 }
887 } 926
888 927 break;
889 break; 928
890 929 case KeyEvent.VK_W:
891 case KeyEvent.VK_W: 930 // Wait a turn
892 // Wait a turn 931 break;
893 break; 932
894 933 case KeyEvent.VK_PERIOD:
895 case KeyEvent.VK_PERIOD: 934 if (e.isShiftDown())
896 if (e.isShiftDown())
897 {
898 if (grid[playerx][playery] == Tile.UpStairs)
899 { 935 {
900 if (Main.currentGame.inventory.contains(Item.Key)) 936 if (grid[playerx][playery] == Tile.UpStairs)
901 { 937 {
902 Main.currentGame.inventory.remove(Item.Key); 938 if (Main.currentGame.inventory.contains(Item.Key))
903 Main.setGameState(new MapViewGameState(floor+1)); 939 {
904 940 Main.currentGame.inventory.remove(Item.Key);
905 return; 941 Main.setGameState(new MapViewGameState(floor+1));
906 } else { 942
907 printMessage("The stairs are locked! You need a key."); 943 return;
944 } else {
945 printMessage("The stairs are locked! You need a key.");
946 }
908 } 947 }
948
949 break;
909 } 950 }
910 951
911 break; 952 case KeyEvent.VK_I:
912 } 953 if (Main.currentGame.inventory.isEmpty())
913 954 {
914 case KeyEvent.VK_I: 955 printMessage("You have no items");
915 if (Main.currentGame.inventory.isEmpty()) 956 } else {
916 { 957 InventoryOverlay io = new InventoryOverlay();
917 printMessage("You have no items"); 958 Main.addRenderable(io);
918 } else { 959 Main.addInputable(io);
919 InventoryOverlay io = new InventoryOverlay(); 960
920 Main.addRenderable(io); 961 return;
921 Main.addInputable(io); 962 }
922 963
964 case KeyEvent.VK_C:
965 closingDoor = true;
966 messageOverlay = new MessageOverlay("Close door in what direction?", 1, 2, VIEWPORT_WIDTH-2);
967 Main.addRenderable(messageOverlay);
968
923 return; 969 return;
924 } 970
925 971 default:
926 default: 972 return;
927 return; 973 }
928 } 974 }
929 975
930 tick(); 976 tick();
diff --git a/src/com/fourisland/frigidearth/Tile.java b/src/com/fourisland/frigidearth/Tile.java index 8b11e50..7ae8a0d 100644 --- a/src/com/fourisland/frigidearth/Tile.java +++ b/src/com/fourisland/frigidearth/Tile.java
@@ -62,10 +62,10 @@ public enum Tile
62 return new Color(182, 175, 169); 62 return new Color(182, 175, 169);
63 } 63 }
64 }, 64 },
65 Door { 65 ClosedDoor {
66 public boolean isBlocked() 66 public boolean isBlocked()
67 { 67 {
68 return false; 68 return true;
69 } 69 }
70 70
71 public char getDisplayCharacter() 71 public char getDisplayCharacter()
@@ -78,6 +78,22 @@ public enum Tile
78 return new Color(0, 63, 135); 78 return new Color(0, 63, 135);
79 } 79 }
80 }, 80 },
81 OpenDoor {
82 public boolean isBlocked()
83 {
84 return false;
85 }
86
87 public char getDisplayCharacter()
88 {
89 return 'D';
90 }
91
92 public Color getBackgroundColor()
93 {
94 return new Color(162, 181, 205);
95 }
96 },
81 UpStairs { 97 UpStairs {
82 public boolean isBlocked() 98 public boolean isBlocked()
83 { 99 {