diff --git a/src/main.c b/src/main.c index 2a65331..6eee2cc 100644 --- a/src/main.c +++ b/src/main.c @@ -9,9 +9,14 @@ #include #include #include +#include +#include "cell.h" const int SCREEN_WIDTH = 1280; const int SCREEN_HEIGHT = 720; +const int CELL_SIZE = 15; +const int MAX_X = SCREEN_WIDTH / CELL_SIZE - 1; +const int MAX_Y = SCREEN_HEIGHT / CELL_SIZE - 1; typedef struct { SDL_Window *window; @@ -23,6 +28,7 @@ App app; void Cleanup(void); void HandleInput(void); +int GetIndex(int x, int y, int columns); int main(int argc, char** argv) { memset(&app, 0, sizeof(app)); @@ -34,6 +40,18 @@ int main(int argc, char** argv) { return -1; } + if (TTF_Init() < 0) { + printf("Failed to init TTF: %s\n", TTF_GetError()); + return -1; + } + + app.font = TTF_OpenFont("/usr/share/fonts/TTF/Hack-Regular.ttf", 14); + + if (app.font == NULL) { + printf("Failed to load font\n"); + return -1; + } + app.window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if (app.window == NULL){ @@ -50,19 +68,43 @@ int main(int argc, char** argv) { return -1; } + SDL_Rect* rect = malloc(sizeof(SDL_Rect)); + rect->h = CELL_SIZE; + rect->w = CELL_SIZE; + rect->x = 0;//MAX_X * CELL_SIZE; + rect->y = 0;//MAX_Y * CELL_SIZE; + Cell* cell = CreateCell(*rect); + while(1){ HandleInput(); - SDL_Delay(16); + SDL_Delay(128); + + SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255); + + SDL_RenderClear(app.renderer); + + SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255); + + rect->x += CELL_SIZE; + rect->y += CELL_SIZE; + + if (rect->x / CELL_SIZE > MAX_X) rect->x = 0; + if (rect->y / CELL_SIZE > MAX_Y) rect->y = 0; + + SDL_RenderFillRect(app.renderer, rect); SDL_RenderPresent(app.renderer); } + + free(cell); } void Cleanup(void) { SDL_DestroyWindow(app.window); SDL_DestroyRenderer(app.renderer); + TTF_CloseFont(app.font); TTF_Quit(); SDL_Quit(); } @@ -81,4 +123,8 @@ void HandleInput(void) { break; } } +} + +int GetIndex(int x, int y, int columns) { + return x + y * columns; } \ No newline at end of file