/** * updates all the drawn objects * * @param delta time since the last update */ @Override public void update(double delta) { for (Drawable2D drawable : drawList) { drawable.update(delta); // update the drawable if (!(drawable.equals(player))) { // if the drawable is not the player if (drawable.getClass().equals(Room2D.class)) { ExitDirection direction = ((Room2D) drawable).inExitBounds(player.getBounds()); if (direction != null) { // if the player is in the exit bounds Point newPlayerLocation = new Point(drawable.getBounds().width / 2, drawable.getBounds().height / 2); player.setLocation(newPlayerLocation); // set player to the middle of the room notifyInputListeners( new InputEvent2D(new Command(CommandWord.go, direction.toString()))); } continue; } // if the drawable is not the player and collides with the player if (collidingWithObject == null) { if (player.collidesWith(drawable)) { if (drawable.getClass().equals(Monster2D.class)) { // if player collides with a monster String monsterName = ((Monster2D) drawable).getName(); // send input messages if it does collide notifyInputListeners(new InputEvent2D(new Command(CommandWord.attack, monsterName))); collidingWithObject = drawable; if (characterWindow != null && characterWindow.isVisible()) { characterWindow(); } } else if (drawable .getClass() .equals(Item2D.class)) { // if player collides with an item String itemName = ((Item2D) drawable).getName(); notifyInputListeners(new InputEvent2D(new Command(CommandWord.take, itemName))); collidingWithObject = drawable; if (inventoryWin != null && inventoryWin.isVisible()) { inventoryWindow(); } } } } else { if (!player.collidesWith( collidingWithObject)) { // check if you move out of the colliding objects bounds collidingWithObject = null; // we are off the other object, set it to null } } } } SwingUtilities.invokeLater( new Runnable() { public void run() { drawArea.repaint(); mapArea.repaint(); textAreaPanel.repaint(); mainWindow.repaint(); mainWindow.validate(); } }); }