From cf631e23e1d0e29edac2e13446bdd42235c111fc Mon Sep 17 00:00:00 2001 From: kartofen Date: Sat, 15 Apr 2023 18:27:29 +0300 Subject: collision and depth shading --- src/main.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 432d26f..f2d6944 100644 --- a/src/main.c +++ b/src/main.c @@ -11,6 +11,8 @@ SDL_Surface *surface = NULL; #define CLEAR_SCREEN(c) for(int i = 0; i < SW-1; i++) vline(i, 0, SH-1, c); +void print_message(void); + void vline(int x, int y1, int y2, uint32_t col) { y1 = clamp(y1, 0, SH-1); @@ -31,6 +33,8 @@ int main(void) SDL_LogSetAllPriority(SDL_LOG_PRIORITY_ERROR); #endif + print_message(); + // ----------------- START SDL ----------------- // int ret = 1; SDL_Window *window = NULL; @@ -61,19 +65,22 @@ int main(void) if(map_load(&map, "files/map_clear.txt")) return 1; + bool keys[6] = {0}; bool quit = false; - 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; } + #define KEY_SWITCH(b) \ + switch(event.key.keysym.sym) { \ + case 'w': keys[0] = b; break; \ + case 'a': keys[1] = b; break; \ + case 's': keys[2] = b; break; \ + case 'd': keys[3] = b; break; \ + case ' ': keys[4] = b; break; \ + case SDLK_LSHIFT: \ + case SDLK_RSHIFT: keys[5] = b; break; } switch(event.type) { case SDL_QUIT: @@ -85,9 +92,7 @@ int main(void) case SDL_KEYUP: KEY_SWITCH(false); break; - default: - // log_debug(LOG_APPLICATION, "event: %d", event.type); - break; + default: break; } // ------------------------------------------ // } @@ -96,9 +101,8 @@ int main(void) int x,y; SDL_GetRelativeMouseState(&x,&y); - player_input(&map.player, wasd, x, y); - map_player_sector(&map); - // map_detect_collision(&map); + player_input(&map.player, keys, x, y); + map_detect_collision(&map); player_update(&map.player); CLEAR_SCREEN(COLOR_LIGHTWHITE); @@ -117,3 +121,15 @@ exit: SDL_Quit(); return ret; } + +void print_message(void) +{ + puts("--------------- Instructions ---------------"); + puts("Use WASD to move"); + puts("Use the mouse to look"); + puts("Use SPACE to jump"); + puts("Use SHIFT to duck"); + puts(""); + puts("There is collision, but it is very buggy"); + puts("--------------------------------------------"); +} -- cgit v1.2.3