/** * Gets the direction to the door form inside a room. * * @param r The room. */ public int getDirection(Room r) { if (r.getOffsetY() < otherSideFrom(r).getOffsetY()) { return KeyEvent.VK_DOWN; } if (r.getOffsetY() > otherSideFrom(r).getOffsetY()) { return KeyEvent.VK_UP; } if (r.getOffsetX() < otherSideFrom(r).getOffsetX()) { return KeyEvent.VK_RIGHT; } if (r.getOffsetX() > otherSideFrom(r).getOffsetX()) { return KeyEvent.VK_LEFT; } return -1; }
/** * Draws the wall. * * @param g The graphics to draw into * @param r A room that is used to calculate were to draw the wall. */ public void paint(Graphics g, Room r) { Images images = Images.instance(); wallSize = (int) Math.round(Room.getSize() * 0.15); switch (direction) { case KeyEvent.VK_UP: g.drawImage( images.getWallUpImage(Room.getSize() - 2 * wallSize, wallSize), r.getOffsetX() + wallSize, r.getOffsetY(), null); break; case KeyEvent.VK_RIGHT: g.drawImage( images.getWallRightImage(wallSize, Room.getSize() - 2 * wallSize), r.getOffsetX() + Room.getSize() - wallSize, r.getOffsetY() + wallSize, null); break; case KeyEvent.VK_DOWN: g.drawImage( images.getWallDownImage(Room.getSize() - 2 * wallSize, wallSize), r.getOffsetX() + wallSize, r.getOffsetY() + Room.getSize() - wallSize, null); break; case KeyEvent.VK_LEFT: g.drawImage( images.getWallLeftImage(wallSize, Room.getSize() - 2 * wallSize), r.getOffsetX(), r.getOffsetY() + wallSize, null); break; } }
/** * Draws the door. * * @param g Graphics. * @param r The room that draws the door. */ public void paint(Graphics g, Room r) { if (r.getOffsetY() < otherSideFrom(r).getOffsetY()) { // Down g.drawImage( Images.instance() .getDoorHorizontalImage(Room.getSize() - 2 * wallSize, 2 * halfDoorSize, isOpen), r.getOffsetX() + wallSize, r.getOffsetY() + Room.getSize() - halfDoorSize, null); } if (r.getOffsetY() > otherSideFrom(r).getOffsetY()) { // Up g.drawImage( Images.instance() .getDoorHorizontalImage(Room.getSize() - 2 * wallSize, 2 * halfDoorSize, isOpen), r.getOffsetX() + wallSize, r.getOffsetY() - halfDoorSize, null); } if (r.getOffsetX() < otherSideFrom(r).getOffsetX()) { // Left g.drawImage( Images.instance() .getDoorVerticalImage(2 * halfDoorSize, Room.getSize() - 2 * wallSize, isOpen), r.getOffsetX() + Room.getSize() - halfDoorSize, r.getOffsetY() + wallSize, null); } if (r.getOffsetX() > otherSideFrom(r).getOffsetX()) { // Right g.drawImage( Images.instance() .getDoorVerticalImage(2 * halfDoorSize, Room.getSize() - 2 * wallSize, isOpen), r.getOffsetX() - halfDoorSize, r.getOffsetY() + wallSize, null); } }