private bool hits_brick(Context context, int nx, int ny,
                         ref int vx, ref int vy, breakout b, gamewindow g)
 {
     return(hits_brick0(context, nx - radius, ny - radius, ref vx, ref vy, b, g) ||
            hits_brick0(context, nx - radius, ny + radius, ref vx, ref vy, b, g) ||
            hits_brick0(context, nx + radius, ny - radius, ref vx, ref vy, b, g) ||
            hits_brick0(context, nx + radius, ny + radius, ref vx, ref vy, b, g));
 }
 void do_start()
 {
     current_level = 3;
     b             = new breakout();
     System.Console.WriteLine("inside main");
     current_level = b.load_level(current_level);
     if (current_level == 0)
     {
         current_state = game_state.finish_t;
     }
     else
     {
         current_state = game_state.play_t;
         init_board();
     }
 }
    private bool hits_brick0(Context context, int nx, int ny,
                             ref int vx, ref int vy, breakout b, gamewindow g)
    {
        int r = (ny * breakout.max_row) / breakout_definitions.y_res;
        int c = (nx * breakout.max_col) / breakout_definitions.x_res;

        if ((r < 0) || (c < 0) || (r >= breakout.max_row) || (c >= breakout.max_col))
        {
            return(false);
        }

        if (b.get_tile(r, c) == ' ')
        {
            return(false); // no brick present
        }
        int bx0    = (breakout_definitions.x_res * c) / breakout.max_col;
        int by0    = (breakout_definitions.y_res * r) / breakout.max_row;
        int width  = (breakout_definitions.x_res / breakout.max_col);
        int height = (breakout_definitions.y_res / breakout.max_row);


        if (in_range(nx, bx0, bx0 + width) && ((ny == by0) || (ny == by0 + height)))
        {
            // hit top of brick or bottom of brick
            vy = -vy;
            g.hit_brick(r, c);
            return(true);
        }
        if (in_range(ny, by0, by0 + height) && ((nx == bx0) || (nx == bx0 + width)))
        {
            // hit left or right of brick
            vx = -vx;
            g.hit_brick(r, c);
            return(true);
        }

        return(false);
    }
    public void move(Context context, moving paddle, breakout b, gamewindow g)
    {
        if ((vx != 0) || (vy != 0))
        {
            int nx = Math.Min(Math.Max(x + vx, 0), breakout_definitions.x_res);
            int ny = Math.Min(Math.Max(y + vy, 0), breakout_definitions.y_res);

            if (moving_type == moving_types.ball_t)
            {
                if (hits_paddle(paddle, nx, ny, ref vx, ref vy))
                {
                    ;
                }
                else if (hits_brick(context, nx, ny, ref vx, ref vy, b, g))
                {
                    ;
                }
                else if (hits_wall(nx, ny, ref vx, ref vy))
                {
                    ;
                }
                else if (falls_below(context, ny))
                {
                    ;
                }
                else
                {
                    draw_if_moved(context, nx, ny);
                }
            }
            else
            {
                draw_if_moved(context, nx, ny);
            }
        }
    }