Esempio n. 1
0
    public virtual double distanceTo(GameShape other, double[] offset)
    {
        //double[] deltas = new double[offset.Length];
        double delta;
        double dist = 0;

        // offset in the x-dimension
        delta = Math.Abs(offset[0]);
        if (this.getType() == SHAPE.GAME_RECTANGLE)
        {
            delta -= this.getWidth() / 2;
        }
        if (other.getType() == SHAPE.GAME_RECTANGLE)
        {
            delta -= other.getWidth() / 2;
        }
        if (delta < 0)
        {
            delta = 0;
        }
        dist += delta * delta;
        // offset in the y-dimension
        delta = Math.Abs(offset[1]);
        if (this.getType() == SHAPE.GAME_RECTANGLE)
        {
            delta -= this.getWidth() / 2;
        }
        if (other.getType() == SHAPE.GAME_RECTANGLE)
        {
            delta -= other.getWidth() / 2;
        }
        if (delta < 0)
        {
            delta = 0;
        }
        dist += delta * delta;
        dist  = Math.Sqrt(dist);
        // subtract off the circular radius
        if (this.getType() == SHAPE.GAME_CIRCLE)
        {
            dist -= ((GameCircle)this).getRadius();
        }
        if (other.getType() == SHAPE.GAME_CIRCLE)
        {
            dist -= ((GameCircle)other).getRadius();
        }
        if (dist < 0)
        {
            dist = 0;
        }
        return(dist);
    }
Esempio n. 2
0
    public virtual bool intersects(GameShape other, double[] offset)
    {
        // figure out the class of the shape and call the correct function accordingly
        switch (other.getType())
        {
        case SHAPE.GAME_CIRCLE:
            return(this.intersects((GameCircle)other, offset));

        case SHAPE.GAME_RECTANGLE:
            return(this.intersects((GameRectangle)other, offset));

        default:
            return(false);
        }
    }
Esempio n. 3
0
    public virtual double[] moveTo(GameShape other, double[] offset, double[] move)
    {
        if (move[0] == 0 && move[1] == 0)
        {
            return(move);
        }
        // figure out the class of the shape and call the correct function accordingly
        switch (other.getType())
        {
        case SHAPE.GAME_CIRCLE:
            return(this.moveTo((GameCircle)other, offset, move));

        case SHAPE.GAME_RECTANGLE:
            return(this.moveTo((GameRectangle)other, offset, move));

        default:
            return(null);
        }
    }