Render grid
This commit is contained in:
45
src/main.c
45
src/main.c
@@ -33,7 +33,7 @@
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "game.h"
|
||||
|
||||
// Define screen dimensions
|
||||
#define SCREEN_WIDTH 800
|
||||
@@ -71,47 +71,8 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
// Declare rect of square
|
||||
SDL_Rect squareRect;
|
||||
|
||||
// Square dimensions: Half of the min(SCREEN_WIDTH, SCREEN_HEIGHT)
|
||||
squareRect.w = MIN(SCREEN_WIDTH, SCREEN_HEIGHT) / 2;
|
||||
squareRect.h = MIN(SCREEN_WIDTH, SCREEN_HEIGHT) / 2;
|
||||
|
||||
// Square position: In the middle of the screen
|
||||
squareRect.x = SCREEN_WIDTH / 2 - squareRect.w / 2;
|
||||
squareRect.y = SCREEN_HEIGHT / 2 - squareRect.h / 2;
|
||||
|
||||
|
||||
// Event loop exit flag
|
||||
bool quit = false;
|
||||
|
||||
// Event loop
|
||||
while(!quit)
|
||||
{
|
||||
SDL_Event e;
|
||||
|
||||
// Wait indefinitely for the next available event
|
||||
SDL_WaitEvent(&e);
|
||||
|
||||
// User requests quit
|
||||
if(e.type == SDL_QUIT)
|
||||
{
|
||||
quit = true;
|
||||
}
|
||||
|
||||
// Set backgroud color
|
||||
Utils_setBackgroundColor(renderer, COLOR_WHITE);
|
||||
|
||||
// Set renderer color red to draw the square
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
|
||||
|
||||
// Draw filled square
|
||||
SDL_RenderFillRect(renderer, &squareRect);
|
||||
|
||||
// Update screen
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
// Start the game
|
||||
Game_start(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
|
||||
// Destroy renderer
|
||||
SDL_DestroyRenderer(renderer);
|
||||
|
||||
Reference in New Issue
Block a user