阅读背景:

Java学习二(飞机大战项目)day09

来源:互联网 
day09

1.子弹与敌人的碰撞
    1)在超类中FlyingObject设计hit()实现敌人与子弹/英雄机得碰撞

    /** 成员方法:检测敌人与子弹/英雄机的碰撞
     *  this:敌人    other:子弹 */
    public boolean hit(FlyingObject other) {
        int x1 = this.x - other.width;
        int x2 = this.x + this.width;        
        int y1 = this.y - other.height;    
        int y2 = this.y + this.height;    
        int x = other.x;                                
        int y = other.y;                                
        return x>=x1 && x<=x2 && y>=y1 && y<=y2;    
    }

    在超类中FlyingObject设计goDead()实现飞行物去死的

    /** 成员方法:飞行物去死 */
    public void goDead() {
        state = DEAD;    //将当前状态修改为DEAD
    }day09

1.子弹与敌人的碰撞
    1)在超类中FlyingObject设计hit()



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: