⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doordrawable.java

📁 Vyger offers a D & D and Rogue-like environment in a graphical online roleplay game.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * Light And Shadow. A Persistent Universe based on Robert Jordan's Wheel of Time Books.
 * Copyright (C) 2001-2002 WOTLAS Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

package wotlas.libs.graphics2D.drawable;

import wotlas.libs.graphics2D.*;

import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;

/** The DoorDrawable will represent the action of closing and opening a door.
 *  4 style of doors are considered.
 *
 *  This drawable can have an owner ( use the getOwner/setOwner methods ).
 *
 * @author MasterBob, Aldiss
 */

public class DoorDrawable extends Drawable implements DrawableOwner {

 /*------------------------------------------------------------------------------------*/

   /**
    * The anchor point for the rotation will depent of the type of the door
    */

    /** Door's Rotation set to     *
     *                           |---|
     *                           |   |
     *                           |   |
     *                           |   |
     *                           |---|
     */
     public final static byte VERTICAL_TOP_PIVOT = 0;

   /** Door's Rotation set to    |---|
     *                           |   |
     *                           |   |
     *                           |   |
     *                           |---|
     *                             *
     */
     public final static byte VERTICAL_BOTTOM_PIVOT = 1;

   /** Door's Rotation set to    |-----------------|
    *                           *|                 |
    *                            |-----------------|
    */
     public final static byte HORIZONTAL_LEFT_PIVOT = 2;

   /** Door's Rotation set to    |-----------------|
     *                           |                 |*
     *                           |-----------------|
     */
     public final static byte HORIZONTAL_RIGHT_PIVOT = 3;


 /*------------------------------------------------------------------------------------*/

  /** Owner of this door drawable.
   */
     private Object owner;

  /** Current Image Identifier.
   */
     private ImageIdentifier image;

  /** the initial angle if needed to represent a closing door
   */
     private float iniAngle = 0f;

  /** the variationAngle
   */
     private float variationAngle = 0f;

  /** the current angle
   *  we don't take into account the iniAngle to define the currentAngle
   *  we will just do the correction due to the iniAngle on the paint method
   */
     private float currentAngle = 0f;

  /** Door's type
   */
     private byte doorType;

  /** indicate if we are opening the door
   */
    private boolean isOpening = false;

  /** indicate if we are closing the door
   */
    private boolean isClosing = false;

  /** our current Rectangle when the door is closed.
   */
    private Rectangle rDoorClosed;

  /** Rectangle representing the door opened.
   */
    private Rectangle rDoorOpened;

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

  /** Constructor with doorType mode ( see public static fields ).
   *
   * @param positionX x position of the top-left corner of the door 
   * @param positionY y position of the top-left corner of the door 
   * @param iniAngle optional initial angle
   * @param variationAngle variation angle for the door (in radians, ex: +pi/2, -pi/2 );
   * @param doorType type of the door
   * @param image door image
   * @param priority sprite's priority
   */
    public DoorDrawable( int positionX, int positionY, float iniAngle, float variationAngle,
                         byte doorType, ImageIdentifier image, short priority) {
    	super();

        rDoorClosed = new Rectangle();
        rDoorOpened = new Rectangle();

        rDoorClosed.x = positionX;
        rDoorClosed.y = positionY;
        r = rDoorClosed;

        this.priority = priority;
        this.iniAngle = iniAngle;
        this.variationAngle = variationAngle;
        this.doorType = doorType;
        this.image = image;
    }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

  /** To initialize this drawable with the ImageLibrary. Don't call it yourself ! it's
   *  done automatically when you call addDrawable on the GraphicsDirector.
   *
   *  IF you need the ImageLib for some special inits just extend this method and don't
   *  forget to call a super.init(imageLib) !
   *
   *  @param imagelib ImageLibrary where you can take the images to display.
   */
     protected void init( ImageLibrary imageLib ) {
     	super.init(imageLib);

      // Compute rectangle for door closed
        rDoorClosed.width = getImageLibrary().getWidth( image );
        rDoorClosed.height = getImageLibrary().getHeight( image );
        
      // Compute rectangle for door opened
         if( iniAngle<=1.0 && Math.abs(variationAngle)>=1.55 /*Math.PI/2*/ ) {
            switch( doorType ) {
             //default:
               case HORIZONTAL_LEFT_PIVOT:
                       rDoorOpened.x = rDoorClosed.x;

                       if( variationAngle>0 )
                           rDoorOpened.y = rDoorClosed.y;
                       else
                           rDoorOpened.y = rDoorClosed.y - rDoorClosed.width +rDoorClosed.height;
                       break;

                  case HORIZONTAL_RIGHT_PIVOT:
                       rDoorOpened.x = rDoorClosed.x +rDoorClosed.width-rDoorClosed.height;

                       if( variationAngle>0 )
                           rDoorOpened.y = rDoorClosed.y - rDoorClosed.width + rDoorClosed.height;
                       else
                           rDoorOpened.y = rDoorClosed.y;
                       break;

                  case VERTICAL_BOTTOM_PIVOT:
                       rDoorOpened.y = rDoorClosed.y + rDoorClosed.height - rDoorClosed.width;

                       if( variationAngle>0 )
                           rDoorOpened.x = rDoorClosed.x;
                       else
                           rDoorOpened.x = rDoorClosed.x - rDoorClosed.height +rDoorClosed.width;
                       break;

                  case VERTICAL_TOP_PIVOT:
                       rDoorOpened.y = rDoorClosed.y;

                       if( variationAngle>0 )
                           rDoorOpened.x = rDoorClosed.x - rDoorClosed.height +rDoorClosed.width;
                       else
                           rDoorOpened.x = rDoorClosed.x;
                       break;
            }

            rDoorOpened.width = rDoorClosed.height;
            rDoorOpened.height = rDoorClosed.width;
         }
         else {
           // we create a general rectangle
            switch( doorType ) {
             //default:
               case HORIZONTAL_LEFT_PIVOT:
                       rDoorOpened.x = rDoorClosed.x;
                       rDoorOpened.y = rDoorClosed.y - rDoorClosed.width;
                       rDoorOpened.width = rDoorClosed.width;
                       rDoorOpened.height = rDoorClosed.height+2*rDoorClosed.width;
                       break;

                  case HORIZONTAL_RIGHT_PIVOT:
                       rDoorOpened.x = rDoorClosed.x;
                       rDoorOpened.y = rDoorClosed.y - rDoorClosed.width;
                       rDoorOpened.width = rDoorClosed.width;
                       rDoorOpened.height = rDoorClosed.height+2*rDoorClosed.width;
                       break;

                  case VERTICAL_BOTTOM_PIVOT:
                       rDoorOpened.x = rDoorClosed.x-rDoorClosed.height;
                       rDoorOpened.y = rDoorClosed.y;
                       rDoorOpened.width = rDoorClosed.width+2*rDoorClosed.height;
                       rDoorOpened.height = rDoorClosed.height;
                       break;

                  case VERTICAL_TOP_PIVOT:
                       rDoorOpened.x = rDoorClosed.x-rDoorClosed.height;
                       rDoorOpened.y = rDoorClosed.y;
                       rDoorOpened.width = rDoorClosed.width+2*rDoorClosed.height;
                       rDoorOpened.height = rDoorClosed.height;
                       break;
            }
         }
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

  /** To get the real door rectangle, not its influence zone.
   * @return strict rectangle representing the door CLOSED.
   */
    public Rectangle getRealDoorRectangle() {
    	  return new Rectangle(rDoorClosed);
    }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

  /** To get the current angle of the doorDrawable

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -