abstractsprite.java

来自「1) 图像的基本操作; 2) ImageObserver接口、ImagePro」· Java 代码 · 共 73 行

JAVA
73
字号
package tankgame611;

import java.awt.Graphics;


public abstract class AbstractSprite {
  int X, Y;
  int width, height;
  boolean visible, active;
  abstract public void drawSprite(Graphics g);

  abstract public void drawSprite(Graphics g, int SpriteDirection);

  abstract public void updatePos(int SpriteDirection);

  public int getX() {
    return X;
  }

  public int getY() {
    return Y;
  }

  public int getWidth() {
    return width;
  }

  public int getHeight() {
    return height;
  }

  public boolean getVisible() {
    return visible;
  }

  public boolean getActive() {
    return active;
  }

  public void setPos(int X, int Y) {
    this.X = X;
    this.Y = Y;
  }

  public void setWidthHeight(int width, int height) {
    this.width = width;
    this.height = height;
  }

  public void setVisible(boolean visible) {
    this.visible = visible;
  }

  public void setActive(boolean active) {
    this.active = active;
  }
  public boolean isCollided(AbstractSprite target){
boolean collided=false;
if(this.visible==true&&target.visible==true){
  int cX=(this.getX()+this.getWidth()/2)-(target.getX()+target.getWidth()/2);
  int cW=(this.getWidth()+target.getWidth())/2;
  int cY=(this.getY()+this.getHeight()/2)-(target.getY()+target.getHeight()/2);
  int cH=(this.getHeight()+target.getHeight())/2;
  if((java.lang.Math.abs(cX)<java.lang.Math.abs(cW))&&(java.lang.Math.abs(cY)<java.lang.Math.abs(cH))){
    collided=true;
  }
}
return collided;

}

}

⌨️ 快捷键说明

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