src/GameObj.java
/**
     * Determine whether the game object will hit another object in the next time step. If so,
     * return the direction of the other object in relation to this game object.
     * 
     * @param that The other object
     * @return Direction of impending object, null if all clear.
     */
Determine whether the game object will hit another object in the next time step. If so,
return the direction of the other object in relation to this game object.

@param that The other object
@return Direction of impending object, null if all clear.
Determine whether the game object will hit another object in the next time step . If so return the direction of the other object in relation to this game object . @param that The other object @return Direction of impending object null if all clear .
public Direction hitObj(GameObj that) {
        if (this.willIntersect(that)) {
            double dx = that.px + that.width / 2 - (this.px + this.width / 2);
            double dy = that.py + that.height / 2 - (this.py + this.height / 2);
            double theta = Math.acos(dx / (Math.sqrt(dx * dx + dy * dy)));
            double diagTheta = Math.atan2(this.height / 2, this.width / 2);
            if (theta <= diagTheta) {
                return Direction.RIGHT;
            } else if (theta > diagTheta && theta <= Math.PI - diagTheta) {
                if (dy > 0) {
                    return Direction.DOWN;
                } else {
                    return Direction.UP;
                }
            } else {
                return Direction.LEFT;
            }
        } else {
            return null;
        }
    }
public Direction hitObj ( GameObj that ) { if ( this . willIntersect ( that ) ) { double dx = that . px + that . width / 2 - ( this . px + this . width / 2 ) ; double dy = that . py + that . height / 2 - ( this . py + this . height / 2 ) ; double theta = Math . acos ( dx / ( Math . sqrt ( dx * dx + dy * dy ) ) ) ; double diagTheta = Math . atan2 ( this . height / 2 , this . width / 2 ) ; if ( theta <= diagTheta ) { return Direction . RIGHT ; } else if ( theta > diagTheta && theta <= Math . PI - diagTheta ) { if ( dy > 0 ) { return Direction . DOWN ; } else { return Direction . UP ; } } else { return Direction . LEFT ; } } else { return null ; } }
Determine whether the game object will hit another object in the next time step.
Determine whether the game object will hit another object in the next time step .
// Coordinate system for GUIs is switched