From b9145887cb0c06781747b4e6d2c9e8d3b2604ff5 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 4 Jun 2012 18:14:46 -0400 Subject: Integrated key into item system --- src/com/fourisland/frigidearth/Item.java | 32 +++++++++- .../fourisland/frigidearth/MapViewGameState.java | 71 ++++++++++------------ src/com/fourisland/frigidearth/mobs/Spider.java | 2 +- 3 files changed, 64 insertions(+), 41 deletions(-) diff --git a/src/com/fourisland/frigidearth/Item.java b/src/com/fourisland/frigidearth/Item.java index 689d991..717d09c 100644 --- a/src/com/fourisland/frigidearth/Item.java +++ b/src/com/fourisland/frigidearth/Item.java @@ -38,7 +38,7 @@ public enum Item return ItemType.Scroll; } - public void useItem() + public boolean useItem() { Main.currentGame.health += 20; @@ -46,6 +46,34 @@ public enum Item { Main.currentGame.health = Main.currentGame.maxHealth; } + + return true; + } + }, + Key { + public String getItemName() + { + return "Key"; + } + + public char getDisplayCharacter() + { + return 'k'; + } + + public Color getDisplayColor() + { + return Color.YELLOW; + } + + public ItemType getItemType() + { + return ItemType.Special; + } + + public boolean useItem() + { + return false; } }; @@ -53,7 +81,7 @@ public enum Item public abstract char getDisplayCharacter(); public abstract Color getDisplayColor(); public abstract ItemType getItemType(); - public abstract void useItem(); + public abstract boolean useItem(); public static Item getWeightedRandomItem() { diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index cfb7690..793fae9 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java @@ -46,9 +46,6 @@ public class MapViewGameState implements GameState private int playery = 4; private int viewportx = 0; private int viewporty = 0; - private int keyx; - private int keyy; - private boolean haveKey = false; private boolean snowGrow = false; private int heartbeat = 0; private int floor; @@ -317,37 +314,41 @@ public class MapViewGameState implements GameState } } + ItemInstance key = new ItemInstance(); + key.item = Item.Key; + switch (keyRoomDirection) { case North: grid[room.getX()+room.getWidth()/2][room.getY()+room.getHeight()] = Tile.Door; grid[room.getX()+room.getWidth()/2][room.getY()+room.getHeight()-1] = Tile.DirtFloor; - keyx = room.getX()+3; - keyy = room.getY()+3; + key.x = room.getX()+3; + key.y = room.getY()+3; break; case East: grid[room.getX()-1][room.getY()+room.getHeight()/2] = Tile.Door; grid[room.getX()][room.getY()+room.getHeight()/2] = Tile.DirtFloor; - keyx = room.getX()+10; - keyy = room.getY()+3; + key.x = room.getX()+10; + key.y = room.getY()+3; break; case South: grid[room.getX()+room.getWidth()/2][room.getY()-1] = Tile.Door; grid[room.getX()+room.getWidth()/2][room.getY()] = Tile.DirtFloor; - keyx = room.getX()+3; - keyy = room.getY()+10; + key.x = room.getX()+3; + key.y = room.getY()+10; break; case West: grid[room.getX()+room.getWidth()][room.getY()+room.getHeight()/2] = Tile.Door; grid[room.getX()+room.getWidth()-1][room.getY()+room.getHeight()/2] = Tile.DirtFloor; - keyx = room.getX()+3; - keyy = room.getY()+3; + key.x = room.getX()+3; + key.y = room.getY()+3; break; } + items.add(key); rooms.add(room); adjustViewport(); @@ -710,12 +711,6 @@ public class MapViewGameState implements GameState } } - // Render key - if ((!haveKey) && (gridLighting[keyx][keyy])) - { - g.drawImage(SystemFont.getCharacter('k', Color.YELLOW), (keyx-viewportx)*TILE_WIDTH, (keyy-viewporty)*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT, null); - } - // Render items for (ItemInstance ii : items) { @@ -853,32 +848,31 @@ public class MapViewGameState implements GameState break; case KeyEvent.VK_G: - if ((playerx == keyx) && (playery == keyy) && (!haveKey)) + for (ItemInstance ii : items) { - haveKey = true; - printMessage("You get the key"); - printMessage("All the windows in the room shatter!"); - - for (int x=0; x