Skip to content

Example: Falling rect

Amine B. Hassouna edited this page Nov 17, 2022 · 1 revision
void draw_rect(int x, int y, int w, int h, SDL_Color color)
{
    for (int i = x; i < x + w; ++i)
    {
        for (int j = y; j < y + h; ++j)
        {
            set_cell_color(i, j, color);
        }
    }
}

void draw(int x_cells, int y_cells)
{
    delay(1000);

    int rect_w = 2;
    int rect_h = 2;
    int rect_x = x_cells / 2 - rect_w / 2;
    int rect_y = 0;


    while(true)
    {
        set_grid_color(COLOR_WHITE);
        draw_rect(rect_x, rect_y, rect_w, rect_h, COLOR_RED);

        rect_y++;
        if (rect_y > y_cells)
        {
            rect_y = 0;
        }

        delay(200);
    }
}

Clone this wiki locally