diff options
author | kartofen <mladenovnasko0@gmail.com> | 2023-04-10 22:23:26 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2023-04-10 22:23:26 +0300 |
commit | 685076399535d47e056eb2341baa18888d15482b (patch) | |
tree | d284bbbbd2d2f102520735dc7256e14d8911e749 /src/main.c | |
parent | 80ead50951c8b0d2c60c9fd57b8a4c943634b084 (diff) |
rendering one sector works
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 47 |
1 files changed, 16 insertions, 31 deletions
@@ -7,9 +7,10 @@ int SW = 1200; int SH = 800; char *name = "Thingy"; - SDL_Surface *surface = NULL; +#define CLEAR_SCREEN(c) for(int i = 0; i < SW-1; i++) vline(i, 0, SH-1, c); + void vline(int x, int y1, int y2, uint32_t col) { y1 = clamp(y1, 0, SH-1); @@ -59,33 +60,28 @@ int main(void) return 1; bool quit = false; - int wasd[4] = {0}; + bool wasd[4] = {0}; while(!quit) { SDL_Event event; while(SDL_PollEvent(&event)) { // ----------------- EVENTS ----------------- // + #define KEY_SWITCH(b) \ + switch(event.key.keysym.sym) { \ + case 'w': wasd[0] = b; break; \ + case 'a': wasd[1] = b; break; \ + case 's': wasd[2] = b; break; \ + case 'd': wasd[3] = b; break; } + switch(event.type) { case SDL_QUIT: quit = true; break; case SDL_KEYDOWN: - switch(event.key.keysym.sym) - { - case 'w': wasd[0] = 1; break; - case 'a': wasd[1] = 1; break; - case 's': wasd[2] = 1; break; - case 'd': wasd[3] = 1; break; - } + KEY_SWITCH(true); break; case SDL_KEYUP: - switch(event.key.keysym.sym) - { - case 'w': wasd[0] = 0; break; - case 'a': wasd[1] = 0; break; - case 's': wasd[2] = 0; break; - case 'd': wasd[3] = 0; break; - } + KEY_SWITCH(false); break; default: // log_debug(LOG_APPLICATION, "event: %d", event.type); @@ -95,26 +91,15 @@ int main(void) } // ----------------- GAME LOOP ----------------- // - int x,y; SDL_GetRelativeMouseState(&x,&y); - map.player.angle += x * 0.03f; - - float move_vec[2] = {0.f, 0.f}; - if(wasd[0]) { move_vec[0] += map.player.anglecos*0.2f; move_vec[1] += map.player.anglesin*0.2f; } - if(wasd[2]) { move_vec[0] -= map.player.anglecos*0.2f; move_vec[1] -= map.player.anglesin*0.2f; } - if(wasd[1]) { move_vec[0] += map.player.anglesin*0.2f; move_vec[1] -= map.player.anglecos*0.2f; } - if(wasd[3]) { move_vec[0] -= map.player.anglesin*0.2f; move_vec[1] += map.player.anglecos*0.2f; } - int pushing = wasd[0] || wasd[1] || wasd[2] || wasd[3]; - float acceleration = pushing ? 0.4 : 0.2; - - map.player.pos.x += move_vec[0] * acceleration; - map.player.pos.y += move_vec[1] * acceleration; + player_input(&map.player, wasd, x, y); + map_player_sector(&map); + // map_detect_collision(&map); player_update(&map.player); - for(int i = 0; i < SW-1; i++) - vline(i, 0, SH-1, COLOR_LIGHTWHITE); + CLEAR_SCREEN(COLOR_LIGHTWHITE); map_draw(&map, SW, SH); // --------------------------------------------- // |