move diag same len

This commit is contained in:
_N3m0 2024-03-20 11:48:17 +01:00
parent 484fb46367
commit 71f835ea7b
2 changed files with 15 additions and 6 deletions

View File

@ -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

17
main.c
View File

@ -1,4 +1,5 @@
#include <stdio.h>
#include <math.h>
#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);
}