move diag same len
This commit is contained in:
parent
484fb46367
commit
71f835ea7b
4
Makefile
4
Makefile
|
@ -1,10 +1,10 @@
|
||||||
$(shell mkdir -p build)
|
$(shell mkdir -p build)
|
||||||
|
|
||||||
all:
|
all:
|
||||||
gcc main.c -o build/main -lraylib
|
gcc main.c -o build/main -lraylib -lm
|
||||||
|
|
||||||
release:
|
release:
|
||||||
gcc -O3 -DRELEASE main.c -o build/main -lraylib
|
gcc -O3 -DRELEASE main.c -o build/main -lraylib -m
|
||||||
|
|
||||||
run: all
|
run: all
|
||||||
./build/main
|
./build/main
|
||||||
|
|
17
main.c
17
main.c
|
@ -1,4 +1,5 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
|
@ -72,11 +73,19 @@ int move_player_inside_trap(Vec2i *player, Rectangle trap,
|
||||||
{
|
{
|
||||||
int step = speed * delta_time * 100;
|
int step = speed * delta_time * 100;
|
||||||
|
|
||||||
player->x -= step * IsKeyDown(KEY_A);
|
int w = IsKeyDown(KEY_W);
|
||||||
player->x += step * IsKeyDown(KEY_D);
|
int a = IsKeyDown(KEY_A);
|
||||||
|
int s = IsKeyDown(KEY_S);
|
||||||
|
int d = IsKeyDown(KEY_D);
|
||||||
|
|
||||||
player->y -= step * IsKeyDown(KEY_W);
|
if (w + a + s + d >= 2)
|
||||||
player->y += step * IsKeyDown(KEY_S);
|
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);
|
return point_rec_collision(*player, trap);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue