From e5025a0037a08c70f653b079c30b46cef8956c4a Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Tue, 5 Jun 2012 12:10:13 -0400 Subject: Added basic equipping system (though equipped items have no worth yet) and added some new items --- src/com/fourisland/frigidearth/Game.java | 128 +++++++++++++++++++++ .../fourisland/frigidearth/InventoryOverlay.java | 4 +- src/com/fourisland/frigidearth/Item.java | 102 +++++++++++++++- src/com/fourisland/frigidearth/ItemType.java | 28 ++++- .../fourisland/frigidearth/MapViewGameState.java | 6 + src/com/fourisland/frigidearth/MessageOverlay.java | 67 +++++++++++ 6 files changed, 326 insertions(+), 9 deletions(-) create mode 100644 src/com/fourisland/frigidearth/MessageOverlay.java (limited to 'src') diff --git a/src/com/fourisland/frigidearth/Game.java b/src/com/fourisland/frigidearth/Game.java index 3487729..fdd4110 100644 --- a/src/com/fourisland/frigidearth/Game.java +++ b/src/com/fourisland/frigidearth/Game.java @@ -19,4 +19,132 @@ public class Game public int level = 1; public int experience = 0; public List inventory = new ArrayList(); + private Item helmet = null; + private Item sword = null; + private Item shield = null; + private Item ring = null; + private Item shoes = null; + + public boolean equipItem(final Item i) + { + if ((i.getItemType() != ItemType.Helmet) && (i.getItemType() != ItemType.Sword) && (i.getItemType() != ItemType.Shield) && (i.getItemType() != ItemType.Ring) && (i.getItemType() != ItemType.Shoes)) + { + throw new IllegalArgumentException("You can only equip helmets, swords, shields, rings and shoes."); + } + + boolean alreadyEquipped = false; + boolean alreadyEquippedSame = false; + Item equippedItem = null; + + switch (i.getItemType()) + { + case Helmet: + if (helmet != null) + { + alreadyEquipped = true; + equippedItem = helmet; + + if (helmet == i) + { + alreadyEquippedSame = true; + } + } + + break; + + case Sword: + if (sword != null) + { + alreadyEquipped = true; + equippedItem = sword; + + if (sword == i) + { + alreadyEquippedSame = true; + } + } + + break; + + case Shield: + if (shield != null) + { + alreadyEquipped = true; + equippedItem = shield; + + if (shield == i) + { + alreadyEquippedSame = true; + } + } + + break; + + case Ring: + if (ring != null) + { + alreadyEquipped = true; + equippedItem = ring; + + if (ring == i) + { + alreadyEquippedSame = true; + } + } + + break; + + case Shoes: + if (shoes != null) + { + alreadyEquipped = true; + equippedItem = shoes; + + if (shoes == i) + { + alreadyEquippedSame = true; + } + } + + break; + } + + if (alreadyEquippedSame) + { + ((MapViewGameState) Main.getGameState()).printMessage("You have already equipped " + i.getItemName().toLowerCase()); + + return false; + } else if (alreadyEquipped) + { + inventory.add(equippedItem); + ((MapViewGameState) Main.getGameState()).printMessage("You unequip your " + equippedItem.getItemName().toLowerCase() + " and equip " + i.getItemName().toLowerCase()); + } else { + ((MapViewGameState) Main.getGameState()).printMessage("You equip " + i.getItemName().toLowerCase()); + } + + switch (i.getItemType()) + { + case Helmet: + helmet = i; + break; + + case Sword: + sword = i; + break; + + case Shield: + shield = i; + break; + + case Ring: + ring = i; + break; + + case Shoes: + shoes = i; + break; + } + + return true; + } } diff --git a/src/com/fourisland/frigidearth/InventoryOverlay.java b/src/com/fourisland/frigidearth/InventoryOverlay.java index 0d7a5ba..70c42c4 100644 --- a/src/com/fourisland/frigidearth/InventoryOverlay.java +++ b/src/com/fourisland/frigidearth/InventoryOverlay.java @@ -108,10 +108,10 @@ public class InventoryOverlay implements Renderable, Inputable ((MapViewGameState) Main.getGameState()).tick(); Main.removeRenderable(this); Main.removeInputable(this); - - return; } + return; + case KeyEvent.VK_D: ((MapViewGameState) Main.getGameState()).dropItemAtPlayer(Main.currentGame.inventory.get(id)); Main.currentGame.inventory.remove(id); diff --git a/src/com/fourisland/frigidearth/Item.java b/src/com/fourisland/frigidearth/Item.java index 8881b6c..4527cbe 100644 --- a/src/com/fourisland/frigidearth/Item.java +++ b/src/com/fourisland/frigidearth/Item.java @@ -70,12 +70,89 @@ public enum Item { return ItemType.Helmet; } + }, + WoodenSword { + public String getItemName() + { + return "Wooden Sword"; + } - public boolean useItem() + public char getDisplayCharacter() { - // Nope not yet - - return true; + return '/'; + } + + public Color getDisplayColor() + { + return new Color(128, 42, 42); + } + + public ItemType getItemType() + { + return ItemType.Sword; + } + }, + WoodenShield { + public String getItemName() + { + return "Wooden Shield"; + } + + public char getDisplayCharacter() + { + return 'O'; + } + + public Color getDisplayColor() + { + return new Color(128, 42, 42); + } + + public ItemType getItemType() + { + return ItemType.Shield; + } + }, + RingOfRegeneration { + public String getItemName() + { + return "Ring of Regeneration"; + } + + public char getDisplayCharacter() + { + return 'o'; + } + + public Color getDisplayColor() + { + return Color.YELLOW; + } + + public ItemType getItemType() + { + return ItemType.Ring; + } + }, + Crocs { + public String getItemName() + { + return "Crocs"; + } + + public char getDisplayCharacter() + { + return 'd'; + } + + public Color getDisplayColor() + { + return new Color(128, 42, 42); + } + + public ItemType getItemType() + { + return ItemType.Shoes; } }, Key { @@ -111,7 +188,22 @@ public enum Item public abstract char getDisplayCharacter(); public abstract Color getDisplayColor(); public abstract ItemType getItemType(); - public abstract boolean useItem(); + + public boolean useItem() + { + switch (getItemType()) + { + case Helmet: + case Sword: + case Shield: + case Ring: + case Shoes: + return Main.currentGame.equipItem(this); + + default: + throw new java.lang.AbstractMethodError(); + } + } public static Item getWeightedRandomItem() { diff --git a/src/com/fourisland/frigidearth/ItemType.java b/src/com/fourisland/frigidearth/ItemType.java index f870fc6..0d925f5 100644 --- a/src/com/fourisland/frigidearth/ItemType.java +++ b/src/com/fourisland/frigidearth/ItemType.java @@ -13,15 +13,39 @@ public enum ItemType Helmet { public double getRarity() { - return 0.75; + return 0.2; } }, - Scroll { + Sword { + public double getRarity() + { + return 0.2; + } + }, + Shield { + public double getRarity() + { + return 0.2; + } + }, + Ring { + public double getRarity() + { + return 0.05; + } + }, + Shoes { public double getRarity() { return 0.25; } }, + Scroll { + public double getRarity() + { + return 0.1; + } + }, Special { public double getRarity() { diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index a61d0ee..71f803a 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java @@ -984,6 +984,12 @@ public class MapViewGameState implements GameState } } } + + // Snow weakens (but doesn't kill) mobs too! + if ((grid[mob.x][mob.y] == Tile.Snow) && (heartbeat % 2 == 0)) + { + mob.health--; + } } // Move snow diff --git a/src/com/fourisland/frigidearth/MessageOverlay.java b/src/com/fourisland/frigidearth/MessageOverlay.java new file mode 100644 index 0000000..2aec2f0 --- /dev/null +++ b/src/com/fourisland/frigidearth/MessageOverlay.java @@ -0,0 +1,67 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.fourisland.frigidearth; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author hatkirby + */ +public class MessageOverlay implements Renderable +{ + private final int TILE_WIDTH = 12; + private final int TILE_HEIGHT = 12; + + List message; + int x; + int y; + int width; + + public MessageOverlay(String msg, int x, int y, int width) + { + message = new ArrayList(); + this.x = x; + this.y = y; + this.width = width; + + String temp = msg; + + while (temp.length() > width) + { + String shortm = temp.substring(0, width); + + if ((temp.charAt(width) == ' ') || (shortm.endsWith(" "))) + { + message.add(shortm); + temp = temp.substring(width); + } else { + int lastSpace = shortm.lastIndexOf(" "); + message.add(shortm.substring(0, lastSpace)); + temp = temp.substring(lastSpace); + } + } + + message.add(temp); + } + + public void render(Graphics2D g) + { + g.setColor(Color.BLACK); + g.fillRect(x*TILE_WIDTH, y*TILE_HEIGHT, (x+width)*TILE_WIDTH, (y+message.size())*TILE_HEIGHT); + + for (int i=0; i