diff --git a/Makefile b/Makefile index 7deb548..7c304ad 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ $(shell mkdir -p build) all: - gcc main.c -o build/main -lraylib + gcc main.c -o build/main -lraylib -lm release: - gcc -O3 -DRELEASE main.c -o build/main -lraylib + gcc -O3 -DRELEASE main.c -o build/main -lraylib -m run: all ./build/main diff --git a/main.c b/main.c index fa42dcb..2241ae7 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,5 @@ #include +#include #include "raylib.h" @@ -72,11 +73,19 @@ int move_player_inside_trap(Vec2i *player, Rectangle trap, { int step = speed * delta_time * 100; - player->x -= step * IsKeyDown(KEY_A); - player->x += step * IsKeyDown(KEY_D); + int w = IsKeyDown(KEY_W); + int a = IsKeyDown(KEY_A); + int s = IsKeyDown(KEY_S); + int d = IsKeyDown(KEY_D); - player->y -= step * IsKeyDown(KEY_W); - player->y += step * IsKeyDown(KEY_S); + if (w + a + s + d >= 2) + step *= sin(45); + + player->x -= step * a; + player->x += step * d; + + player->y -= step * w; + player->y += step * s; return point_rec_collision(*player, trap); }