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

📄 shellsprite.java

📁 1) 图像的基本操作; 2) ImageObserver接口、ImageProducer接口的应用; 3) FilteredImageSource类、ImageFilter类、CropImageF
💻 JAVA
字号:
package tankgame611;

import java.applet.Applet;
import java.awt.Image;
import java.awt.*;
public class ShellSprite extends SpriteDrawing{
  int AppletWidth,AppletHeight;
  int shellWidth,shellHeight;
  int launchDirection;
  Image shellImg;
  Applet GameApplet;
  int speed;
  public ShellSprite(Image shellImg,int launchDirection,int speed,Applet GameApplet){
    super(0,0);
    this.shellImg=shellImg;
    this.launchDirection=launchDirection;
    this.GameApplet=GameApplet;
    this.speed=speed;
    AppletWidth=GameApplet.getWidth();
    AppletHeight=GameApplet.getHeight();
    setVisible(false);
    setActive(false);
  }
  public void updatePos(){
    shellWidth=shellImg.getWidth(GameApplet);
    shellHeight=shellImg.getHeight(GameApplet);
    switch(launchDirection){
      case 0:
        if(X<(-shellWidth)){
          setVisible(false);
          setActive(false);
        }
        else{
          X=this.getX()-speed;
        }
        break;
        case 1:
          if(X>(AppletWidth+shellWidth)){
            setVisible(false);
            setActive(false);
          }
          else{
            X=this.getX()+speed;
          }
          break;
          case 2:
            if(Y<(-shellHeight)){
              setVisible(false);
              setActive(false);
            }
            else{
              Y=this.getY()-speed;
            }
            break;
            case 3:
              if(Y>(AppletHeight+shellHeight)){
                setVisible(false);
                setActive(false);
              }
              else{
                Y=this.getY()+speed;
              }
              break;
    }
    this.setPos(X,Y);
  }
  public int getShellDirection(){
    return launchDirection;
  }
  public void setShellDirection(int direction){
    this.launchDirection=direction;
  }
  public void drawSprite(Graphics g){
    if(visible==true){
      g.drawImage(shellImg,X,Y,GameApplet);
    }
  }
}

⌨️ 快捷键说明

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