Android006SourceLaser

package org.yasrun.game.kafunwars.objects;

public class Laser extends FlyingObject {
    public int X1 = 0;
    public int Y1 = 0;
    public int X2 = 0;
    public int Y2 = 0;

    public Laser(int x1, int y1, int x2, int y2) {
        super(x1, y1, 0, 0);
        this.X1 = x1;
        this.Y1 = y1;
        this.X2 = x2;
        this.Y2 = y2;

        int vx = x2 - x1;
        int vy = y2 - y1;

        this.VX = vx;
        this.VY = vy;
    }

    public void move() {
        X1 += VX;
        Y1 += VY;
        X2 += VX;
        Y2 += VY;
    }

    public void judge() {
        if ((X1 < 0 || X1 > 320 || Y1 < 0 || Y1 > 480)
                && (X2 < 0 || X2 > 320 || Y2 < 0 || Y2 > 480)) {
            life = 0;
        }
    }

    public boolean isDead() {
        return life <= 0;
    }

    public boolean isInner(int x, int y) {
        boolean result = false;

        int x1 = X1 < X2 ? X1 : X2;
        int y1 = Y1 < Y2 ? Y1 : Y2;
        int x2 = X1 < X2 ? X2 : X1;
        int y2 = Y1 < Y2 ? Y2 : Y1;

        if (x >= x1 && x <= x2 && y >= y1 && y <= y2){
            result = true;
        }

        return result;
    }
}
最終更新:2011年03月09日 23:22