From 243e560a77e4ad2f18a419c0fe350d506d1a5f24 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 6 Jun 2012 08:38:55 -0400 Subject: Doors now start closed and can be opened or closed --- .../fourisland/frigidearth/MapViewGameState.java | 284 ++++++++++++--------- src/com/fourisland/frigidearth/Tile.java | 20 +- 2 files changed, 183 insertions(+), 121 deletions(-) (limited to 'src/com/fourisland') 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 private int heartbeat = 0; private int floor; private int spawnTimer = 0; + private boolean closingDoor = false; + private Renderable messageOverlay = null; public MapViewGameState(int floor) { @@ -144,16 +146,16 @@ public class MapViewGameState implements GameState if (validTile != null) { - if (grid[newx][newy+1] == Tile.Door) + if ((grid[newx][newy+1] == Tile.ClosedDoor) || (grid[newx][newy+1] == Tile.OpenDoor)) { validTile = null; - } else if (grid[newx-1][newy] == Tile.Door) + } else if ((grid[newx-1][newy] == Tile.ClosedDoor) || (grid[newx-1][newy] == Tile.OpenDoor)) { validTile = null; - } else if (grid[newx][newy-1] == Tile.Door) + } else if ((grid[newx][newy-1] == Tile.ClosedDoor) || (grid[newx][newy-1] == Tile.OpenDoor)) { validTile = null; - } else if (grid[newx+1][newy] == Tile.Door) + } else if ((grid[newx+1][newy] == Tile.ClosedDoor) || (grid[newx+1][newy] == Tile.OpenDoor)) { validTile = null; } @@ -173,14 +175,14 @@ public class MapViewGameState implements GameState if (makeRoom(newx+xmod, newy+ymod, validTile, legalBounds)) { currentFeatures++; - grid[newx][newy] = Tile.Door; + grid[newx][newy] = Tile.ClosedDoor; grid[newx+xmod][newy+ymod] = Tile.DirtFloor; } } else { if (makeCorridor(newx+xmod, newy+ymod, validTile)) { currentFeatures++; - grid[newx][newy] = Tile.Door; + grid[newx][newy] = Tile.ClosedDoor; } } } @@ -320,28 +322,28 @@ public class MapViewGameState implements GameState 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()] = Tile.ClosedDoor; grid[room.getX()+room.getWidth()/2][room.getY()+room.getHeight()-1] = Tile.DirtFloor; 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()-1][room.getY()+room.getHeight()/2] = Tile.ClosedDoor; grid[room.getX()][room.getY()+room.getHeight()/2] = Tile.DirtFloor; 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()-1] = Tile.ClosedDoor; grid[room.getX()+room.getWidth()/2][room.getY()] = Tile.DirtFloor; 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()][room.getY()+room.getHeight()/2] = Tile.ClosedDoor; grid[room.getX()+room.getWidth()-1][room.getY()+room.getHeight()/2] = Tile.DirtFloor; key.x = room.getX()+3; key.y = room.getY()+3; @@ -789,142 +791,186 @@ public class MapViewGameState implements GameState public void processInput(KeyEvent e) { - // Handle input - switch (e.getKeyCode()) + if (closingDoor) { - case KeyEvent.VK_LEFT: - case KeyEvent.VK_RIGHT: - case KeyEvent.VK_UP: - case KeyEvent.VK_DOWN: - Direction dir = Direction.fromKeyEvent(e); - Point to = dir.to(new Point(playerx, playery)); - - if ((isValidPosition(to.x,to.y)) && (!grid[to.x][to.y].isBlocked())) - { - // Check for mobs - boolean foundMob = false; - for (Mob mob : mobs) + switch (e.getKeyCode()) + { + case KeyEvent.VK_LEFT: + case KeyEvent.VK_RIGHT: + case KeyEvent.VK_UP: + case KeyEvent.VK_DOWN: + Direction dir = Direction.fromKeyEvent(e); + Point to = dir.to(new Point(playerx, playery)); + + if ((isValidPosition(to.x,to.y)) && (grid[to.x][to.y] == Tile.OpenDoor)) + { + grid[to.x][to.y] = Tile.ClosedDoor; + } else { + printMessage("There is no closed door in that direction"); + } + + case KeyEvent.VK_ESCAPE: + Main.removeRenderable(messageOverlay); + messageOverlay = null; + closingDoor = false; + + break; + + default: + return; + } + } else { + switch (e.getKeyCode()) + { + case KeyEvent.VK_LEFT: + case KeyEvent.VK_RIGHT: + case KeyEvent.VK_UP: + case KeyEvent.VK_DOWN: + Direction dir = Direction.fromKeyEvent(e); + Point to = dir.to(new Point(playerx, playery)); + + if ((isValidPosition(to.x,to.y)) && (!grid[to.x][to.y].isBlocked())) { - if (mob.getPosition().equals(to)) + // Check for mobs + boolean foundMob = false; + for (Mob mob : mobs) { - printMessage("You hit the " + mob.getName().toLowerCase()); - mob.health -= Main.currentGame.getAttackPower(); - - if (mob.health <= 0) + if (mob.getPosition().equals(to)) { - printMessage("You killed the " + mob.getName().toLowerCase() + "!"); - mobs.remove(mob); - - Main.currentGame.experience += (mob.getBaseExperience()/(Main.currentGame.level*Main.currentGame.level)); - if (Main.currentGame.experience >= 1000) - { - Main.currentGame.level++; - Main.currentGame.experience -= 1000; - - int hpGain = Functions.rollDice(6, 2) + 3; - Main.currentGame.health += hpGain; - Main.currentGame.maxHealth += hpGain; - - printMessage("You grow to level " + Main.currentGame.level + "!"); - } - - if (Functions.random(0, 1000) < (mob.getBaseExperience() / (floor*floor))) + printMessage("You hit the " + mob.getName().toLowerCase()); + mob.health -= Main.currentGame.getAttackPower(); + + if (mob.health <= 0) { - ItemInstance ii = new ItemInstance(); - ii.item = Item.getWeightedRandomItem(); - ii.x = mob.x; - ii.y = mob.y; - - items.add(ii); + printMessage("You killed the " + mob.getName().toLowerCase() + "!"); + mobs.remove(mob); + + Main.currentGame.experience += (mob.getBaseExperience()/(Main.currentGame.level*Main.currentGame.level)); + if (Main.currentGame.experience >= 1000) + { + Main.currentGame.level++; + Main.currentGame.experience -= 1000; + + int hpGain = Functions.rollDice(6, 2) + 3; + Main.currentGame.health += hpGain; + Main.currentGame.maxHealth += hpGain; + + printMessage("You grow to level " + Main.currentGame.level + "!"); + } + + if (Functions.random(0, 1000) < (mob.getBaseExperience() / (floor*floor))) + { + ItemInstance ii = new ItemInstance(); + ii.item = Item.getWeightedRandomItem(); + ii.x = mob.x; + ii.y = mob.y; + + items.add(ii); + } } + + foundMob = true; + break; } - - foundMob = true; - break; } - } - - if (!foundMob) + + if (!foundMob) + { + playerx = to.x; + playery = to.y; + } + } else if (grid[to.x][to.y] == Tile.ClosedDoor) { - playerx = to.x; - playery = to.y; + if (Functions.random(0, 99) < 50) + { + grid[to.x][to.y] = Tile.OpenDoor; + } else { + printMessage("You cannot quite get the door to open"); + } + } else { + printMessage("Blocked: " + dir.name()); + + return; } - } else { - printMessage("Blocked: " + dir.name()); - - return; - } - - break; - - case KeyEvent.VK_G: - for (ItemInstance ii : items) - { - if ((ii.x == playerx) && (ii.y == playery)) - { - printMessage("You get a " + ii.item.getItemName().toLowerCase()); - Main.currentGame.inventory.add(ii.item); - items.remove(ii); - if (ii.item == Item.Key) + break; + + case KeyEvent.VK_G: + for (ItemInstance ii : items) + { + if ((ii.x == playerx) && (ii.y == playery)) { - printMessage("All the windows in the room shatter!"); + printMessage("You get a " + ii.item.getItemName().toLowerCase()); + Main.currentGame.inventory.add(ii.item); + items.remove(ii); - for (int x=0; x