sprite.java

来自「一款基于j2me技术的手机版游戏——飞机射击」· Java 代码 · 共 57 行

JAVA
57
字号

import javax.microedition.lcdui.*;
abstract class Sprite {
  protected  int x;
  protected  int y;
  protected  int width;
  protected  int height;
  protected  boolean isAlive=true;
  protected  boolean isHit  =false;
  protected  int tickCount  = 0;
  void setX(int x){
    this.x=x;
  }
  void setY(int y){
   this.y=y;
 }
int getX(){
  return x ;
}
int getY(){
  return y ;
}
int getwidth(){
  return width ;
}
int getheight(){
  return height ;
}
void setAlive(boolean isAlive){
  this.isAlive = isAlive ;
}
boolean isAlive(){
  return isAlive;
}
void setHit(boolean isHit){
  this.isHit = isHit ;
  tickCount = 0;
}
boolean isHit(){
  return isHit;
}
boolean isOverlaps(Sprite otherSprite){
  if( (otherSprite.getX()<=x &&
      otherSprite.getX()+otherSprite.getwidth()>=x) ||
      (otherSprite.getX()>=x &&
       otherSprite.getX()<= x+width) ){
    if( (otherSprite.getY()<= y && otherSprite.getY() + otherSprite.getheight()>=y)
        || (otherSprite.getY()>=y && otherSprite.getY()<= y+height)){
      return true ;
    }
  }
  return false;
}
  abstract void doMove();
  abstract void doDraw(Graphics g);
}

⌨️ 快捷键说明

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