📄 doordrawable.java
字号:
*/
public float getCurrentAngle() {
return this.currentAngle;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set the angle of variation of the doorDrawable
* @param varAngle the angle of the variation of the rotation
*/
public void setVariationAngle (float varAngle) {
this.variationAngle = varAngle;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the variationAngle of the doorDrawable
*/
public float getVariationAngle() {
return this.variationAngle;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set the current angle of the doorDrawable
* @param angle the angle of the rotation
*/
public void setCurrentAngle(float angle) {
this.currentAngle = angle;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/**
* set/stop the action of closing door
*/
private void setClosing( boolean closing ) {
this.isClosing = closing;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/**
* set/stop the action of opening door
*/
private void setOpening( boolean opening ) {
this.isOpening = opening;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/**
* return true if the door is opening
*/
public boolean isOpening() {
return this.isOpening;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/**
* return true if the door is closing
*/
public boolean isClosing() {
return this.isClosing;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/**
* set the door to a stable closed view
*/
public void setClosed() {
this.isOpening = false;
this.isClosing = false;
this.currentAngle = this.iniAngle;
r = rDoorClosed;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/**
* set the door to a stable open view
*/
public void setOpened() {
this.isOpening = false;
this.isClosing = false;
this.currentAngle = this.iniAngle + this.variationAngle;
r = rDoorOpened;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/**
* return true if the door is in a stable closed view
*/
public boolean isClosed() {
if(this.isOpening == false && this.isClosing == false
&& this.currentAngle == this.iniAngle )
return true;
else
return false;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/**
* return true if the door is in a stable opened view
*/
public boolean isOpened() {
if( (this.isOpening == false) && (this.isClosing == false)
&& (this.currentAngle == this.iniAngle + this.variationAngle) )
return true;
else
return false;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To open the door
*/
public void open() {
setClosing(false);
setOpening(true);
r = rDoorOpened;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To close the door
*/
public void close() {
setOpening(false);
setClosing(true);
r = rDoorClosed;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Paint method called by the GraphicsDirector. The specified rectangle represents
* the displayed screen in background cordinates ( see GraphicsDirector ).
*
* @param gc graphics 2D use for display (double buffering is handled by the
* GraphicsDirector)
* @param screen display zone of the graphicsDirector, in background coordinates.
*/
public void paint( Graphics2D gc, Rectangle screen ) {
// 1 - Need to display this sprite ?
if( !r.intersects(screen) )
return;
// 2 - any affine transform ?
AffineTransform affTr = null;
//calcul de la rotation eventuelle
float rotation = iniAngle + currentAngle;
if( rotation !=0.0 ) {
// Rotation Transformation
affTr = new AffineTransform();
int anchorX=0, anchorY=0;
switch( doorType ) {
//default:
case HORIZONTAL_LEFT_PIVOT:
anchorX = rDoorClosed.x+rDoorClosed.height/2;
anchorY = rDoorClosed.y + rDoorClosed.height/2;
break;
case HORIZONTAL_RIGHT_PIVOT:
anchorX = rDoorClosed.x + rDoorClosed.width - rDoorClosed.height/2;
anchorY = rDoorClosed.y + rDoorClosed.height/2;
break;
case VERTICAL_BOTTOM_PIVOT:
anchorX = rDoorClosed.x + rDoorClosed.width/2;
anchorY = rDoorClosed.y + rDoorClosed.height -rDoorClosed.width/2;
break;
case VERTICAL_TOP_PIVOT:
anchorX = rDoorClosed.x + rDoorClosed.width/2;
anchorY = rDoorClosed.y + rDoorClosed.width/2;
break;
}
affTr.rotate( rotation, anchorX-screen.x, anchorY-screen.y );
}
// 3 - image display
BufferedImage bufIm = getImageLibrary().getImage( image );
if( affTr==null )
gc.drawImage( bufIm, rDoorClosed.x-screen.x, rDoorClosed.y-screen.y, null );
else {
affTr.translate( rDoorClosed.x-screen.x, rDoorClosed.y-screen.y );
gc.drawImage( bufIm, affTr, null );
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** Tick method called by the GraphicsDirector. This tick method has a returned value
* that indicates if the drawable is still living or must be deleted. Some Drawables
* always return "still living", it is then the task of the program that uses
* the GraphicsDirector to manage the destruction of drawables.
*
* @return true if the drawable is "live", false if it must be deleted.
*/
public boolean tick() {
if(isOpening) {
currentAngle += variationAngle/10;
if( Math.abs(currentAngle) >= Math.abs(variationAngle))
setOpened();
}
if(isClosing) {
currentAngle -= variationAngle/10;
if( Math.abs(currentAngle-variationAngle) >= Math.abs(variationAngle) )
setClosed();
}
return true; // no update needed and a DoorDrawable is always "live" by default.
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To get the owner of this drawable. By 'owner' we mean the object which this
* Drawable is the graphical representation.
*
* @return Object owner of this drawable.
*/
public Object getOwner() {
return owner;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/** To set the owner of this drawable. By 'owner' we mean the object which this
* Drawable is the graphical representation.
*
* @param object owner of this drawable.
*/
public void setOwner( Object owner ) {
this.owner = owner;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -