diff options
author | kartofen <mladenovnasko0@gmail.com> | 2023-04-09 02:02:51 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2023-04-09 02:02:51 +0300 |
commit | fc027f7d214028086178a7328926c9b14ead464d (patch) | |
tree | d2972055a06565f26a19626ac3fb26ead84e0766 /src/main.c |
map loading done
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..8b5aa40 --- /dev/null +++ b/src/main.c @@ -0,0 +1,97 @@ +#include <stdio.h> +#include <stdbool.h> +#include <SDL2/SDL.h> +#include "sector.h" +#include "common.h" + +int SW = 1200; +int SH = 800; +char *name = "Thingy"; + +SDL_Surface *surface = NULL; + +void vline(int x, int y1, int y2, uint32_t col) +{ + y1 = clamp(y1, 0, SH-1); + y2 = clamp(y2, 0, SH-1); + + uint32_t *pixels = (uint32_t*)surface->pixels; + for(int y = min(y1, y2); y <= max(y1, y2); y++) { + pixels[y * SW + x] = SDL_MapRGB(surface->format, color(col)); + } +} + +int main(void) +{ + // set logging priority +#ifdef DEBUG + SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG); +#else + SDL_LogSetAllPriority(SDL_LOG_PRIORITY_ERROR); +#endif + + map_t m; + if(map_load(&m, "files/map_clear.txt")) + return 1; + map_print(&m); + map_unload(&m); + + return 0; + + // ----------------- START SDL ----------------- // + int ret = 1; + SDL_Window *window = NULL; + + if(SDL_Init(SDL_INIT_VIDEO) != 0) { + log_critical(LOG_VIDEO, "SDL_Init: %s", SDL_GetError()); + goto exit; + } + + window = SDL_CreateWindow(name, + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + SW, SH, 0); + if(window == NULL) { + log_critical(LOG_VIDEO, "SDL_CreateWindow: %s", SDL_GetError()); + goto exit; + } + + surface = SDL_GetWindowSurface(window); + if(surface == NULL) { + log_critical(LOG_VIDEO, "SDL_GetWindowSurface %s", SDL_GetError()); + goto exit; + } + // --------------------------------------------- // + + + bool quit = false; + while(!quit) { + // ----------------- GAME LOOP ----------------- // + for(int i = 0; i < SW; i++) + vline(i, 0, SH-1, COLOR_LIGHTWHITE); + // --------------------------------------------- // + + SDL_Event event; + while(SDL_PollEvent(&event)) { + // ----------------- EVENTS ----------------- // + switch(event.type) { + case SDL_QUIT: + quit = true; + break; + default: + log_debug(LOG_APPLICATION, "event: %d", event.type); + break; + } + // ------------------------------------------ // + } + + if(SDL_UpdateWindowSurface(window) != 0) { + log_error(LOG_VIDEO, "SDL_UpdateWindowSurface: %s", SDL_GetError()); + } + } + + ret = 0; +exit: + if(window != NULL) SDL_DestroyWindow(window); + SDL_Quit(); + return ret; +} |