sprite.java

来自「太空大战J2ME版本」· Java 代码 · 共 83 行

JAVA
83
字号
package game0925;

import javax.microedition.lcdui.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public abstract class Sprite {
    protected int x;
    protected int y;
    protected int width;
    protected int height;
    protected boolean isAlive;
    protected boolean isHit;
    public Sprite() {
    }

    void setX(int x) {
        this.x = x;
    }

    int getX() {
        return x;
    }

    void setY(int y) {
        this.y = y;
    }

    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;
    }

    boolean isHit() {
        return isHit;
    }

    boolean isOver(Sprite other) { //是否重复
        if (other.getX() <= x && other.getX() + other.getWidth() >= x ||
            other.getX() >= x && other.getX() <= x + width) {
            if (other.getY() <= y && other.getY() + other.getHeight() >= y ||
                other.getY() >= y && other.getY() <= y + height) {
                return true;
            }
        }
        return false;
    }

    abstract void doMove();

    abstract void paint(Graphics g);

}

⌨️ 快捷键说明

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