Compare commits
No commits in common. "7124b9b6f892d5c1c230f6170efa1b2d3f86be93" and "6aa5885a6e9e2549d6b2dc46fe97efe75212e1bb" have entirely different histories.
7124b9b6f8
...
6aa5885a6e
|
@ -1,5 +1,3 @@
|
||||||
build/
|
build/
|
||||||
.wakatime-project
|
.wakatime-project
|
||||||
voleur
|
voleur
|
||||||
voleur.exe
|
|
||||||
*.zip
|
|
||||||
|
|
20
Makefile
20
Makefile
|
@ -1,24 +1,8 @@
|
||||||
SRC=main.c ninja.c
|
|
||||||
EXE=voleur
|
|
||||||
CC=gcc
|
|
||||||
|
|
||||||
all:
|
all:
|
||||||
$(CC) -Wall -Wextra -ggdb $(SRC) -o $(EXE) /usr/local/lib/libraylib.a -lm
|
gcc -Wall -Wextra -ggdb main.c -o voleur /usr/local/lib/libraylib.a -lm
|
||||||
|
|
||||||
release:
|
release:
|
||||||
$(CC) -Wall -Wextra -O3 -DRELEASE $(SRC) -o $(EXE) /usr/local/lib/libraylib.a -lm
|
gcc -Wall -Wextra -O3 -DRELEASE main.c -o voleur /usr/local/lib/libraylib.a -lm
|
||||||
|
|
||||||
win:
|
|
||||||
x86_64-w64-mingw32-gcc -Wall -Wextra -O3 -DRELEASE $(SRC) -o $(EXE) /usr/local/lib/win-libraylib.a -I /usr/local/include -lm -lgdi32 -lwinmm
|
|
||||||
|
|
||||||
dist: release win
|
|
||||||
zip -r $(EXE)-linux data/ $(EXE)
|
|
||||||
zip -r $(EXE)-windows data/ $(EXE).exe
|
|
||||||
|
|
||||||
run: all
|
run: all
|
||||||
./voleur
|
./voleur
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f $(EXE) $(EXE).exe *.zip
|
|
||||||
|
|
||||||
.PHONY: all release win dist run clean
|
|
||||||
|
|
Binary file not shown.
BIN
data/ninja.png
BIN
data/ninja.png
Binary file not shown.
Before Width: | Height: | Size: 674 B |
66
main.c
66
main.c
|
@ -1,13 +1,13 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "raymath.h"
|
|
||||||
|
|
||||||
#include "ninja.h"
|
|
||||||
|
|
||||||
#define SCREEN_MIDDLE ((Vector2) {window_size.x/2, window_size.y/2})
|
#define SCREEN_MIDDLE ((Vector2) {window_size.x/2, window_size.y/2})
|
||||||
|
|
||||||
Vector2 window_size = { 800.0f, 600.0f };
|
typedef struct Player {
|
||||||
|
float radius;
|
||||||
|
Vector2 coord;
|
||||||
|
} Player;
|
||||||
|
|
||||||
typedef struct Map {
|
typedef struct Map {
|
||||||
const Texture texture;
|
const Texture texture;
|
||||||
|
@ -41,31 +41,17 @@ void change_layout_qwerty(int *keys)
|
||||||
keys[KC_RIGHT] = KEY_D;
|
keys[KC_RIGHT] = KEY_D;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 shake(int force)
|
Camera2D shake(Camera2D cam, int force)
|
||||||
{
|
{
|
||||||
Vector2 s;
|
cam.offset.x += GetRandomValue(-force/2, force/2);
|
||||||
s.x = GetRandomValue(-force/2, force/2);
|
cam.offset.y += GetRandomValue(-force/2, force/2);
|
||||||
s.y = GetRandomValue(-force/2, force/2);
|
return cam;
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void camera_bound(Camera2D *cam, Rectangle bound, float player_radius)
|
|
||||||
{
|
|
||||||
Vector2 coord = GetScreenToWorld2D(SCREEN_MIDDLE, *cam);
|
|
||||||
|
|
||||||
if (coord.x - player_radius < bound.x)
|
|
||||||
cam->target.x = bound.x + player_radius;
|
|
||||||
else if (coord.x + player_radius > bound.x + bound.width)
|
|
||||||
cam->target.x = bound.x + bound.width - player_radius;
|
|
||||||
|
|
||||||
if (coord.y - player_radius < bound.y)
|
|
||||||
cam->target.y = bound.y + player_radius;
|
|
||||||
else if (coord.y + player_radius > bound.y + bound.height)
|
|
||||||
cam->target.y = bound.y + bound.height - player_radius;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
Vector2 window_size = { 800.0f, 600.0f };
|
||||||
|
|
||||||
Camera2D camera = {
|
Camera2D camera = {
|
||||||
.target = {0},
|
.target = {0},
|
||||||
.offset = SCREEN_MIDDLE,
|
.offset = SCREEN_MIDDLE,
|
||||||
|
@ -73,6 +59,10 @@ int main(void)
|
||||||
.zoom = 1.0f,
|
.zoom = 1.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Player player = {
|
||||||
|
.radius = 25.0f,
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef RELEASE
|
#ifdef RELEASE
|
||||||
SetTraceLogLevel(LOG_FATAL);
|
SetTraceLogLevel(LOG_FATAL);
|
||||||
#endif
|
#endif
|
||||||
|
@ -99,8 +89,6 @@ int main(void)
|
||||||
keys[KC_FREECAM] = KEY_F;
|
keys[KC_FREECAM] = KEY_F;
|
||||||
change_layout_azerty(keys);
|
change_layout_azerty(keys);
|
||||||
|
|
||||||
load_ninja();
|
|
||||||
|
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
float DT = GetFrameTime();
|
float DT = GetFrameTime();
|
||||||
if (IsWindowResized()) {
|
if (IsWindowResized()) {
|
||||||
|
@ -123,24 +111,38 @@ int main(void)
|
||||||
if (IsKeyDown(keys[KC_UP]))
|
if (IsKeyDown(keys[KC_UP]))
|
||||||
camera.target.y += movement_speed ;
|
camera.target.y += movement_speed ;
|
||||||
|
|
||||||
camera_bound(&camera, map.box, ninja_radius());
|
if (IsKeyReleased(keys[KC_FREECAM]))
|
||||||
|
camera.target = player.coord;
|
||||||
|
if (!IsKeyDown(keys[KC_FREECAM])) {
|
||||||
|
player.coord = GetScreenToWorld2D(SCREEN_MIDDLE, camera);
|
||||||
|
|
||||||
Vector2 cam_shake = {0};
|
if (player.coord.x - player.radius < map.box.x)
|
||||||
|
camera.target.x = map.box.x + player.radius;
|
||||||
|
else if (player.coord.x + player.radius > map.box.x + map.box.width)
|
||||||
|
camera.target.x = map.box.x + map.box.width - player.radius;
|
||||||
|
|
||||||
|
if (player.coord.y - player.radius < map.box.y)
|
||||||
|
camera.target.y = map.box.y + player.radius;
|
||||||
|
else if (player.coord.y + player.radius > map.box.y + map.box.height)
|
||||||
|
camera.target.y = map.box.y + map.box.height - player.radius;
|
||||||
|
|
||||||
|
player.coord = GetScreenToWorld2D(SCREEN_MIDDLE, camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera2D effect_camera = camera;
|
||||||
if (IsMouseButtonDown(keys[KC_SHOOT]))
|
if (IsMouseButtonDown(keys[KC_SHOOT]))
|
||||||
cam_shake = shake(12);
|
effect_camera = shake(camera, 12);
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
{
|
{
|
||||||
ClearBackground(LIME);
|
ClearBackground(LIME);
|
||||||
|
|
||||||
Camera2D effect_camera = camera;
|
|
||||||
effect_camera.offset = Vector2Add(effect_camera.offset, cam_shake);
|
|
||||||
BeginMode2D(effect_camera);
|
BeginMode2D(effect_camera);
|
||||||
{
|
{
|
||||||
DrawTexture(map.texture, map.box.x, map.box.y, WHITE);
|
DrawTexture(map.texture, map.box.x, map.box.y, WHITE);
|
||||||
|
DrawCircle(player.coord.x, player.coord.y, player.radius, RED);
|
||||||
}
|
}
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
draw_ninja(Vector2Add(SCREEN_MIDDLE, cam_shake));
|
|
||||||
}
|
}
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
29
ninja.c
29
ninja.c
|
@ -1,29 +0,0 @@
|
||||||
#include "raylib.h"
|
|
||||||
#include "raymath.h"
|
|
||||||
#include "stdio.h"
|
|
||||||
|
|
||||||
Texture ninja_texture;
|
|
||||||
|
|
||||||
void load_ninja()
|
|
||||||
{
|
|
||||||
ninja_texture = LoadTexture("data/ninja.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
float ninja_radius()
|
|
||||||
{
|
|
||||||
return fmax(ninja_texture.width, ninja_texture.height)/2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw_ninja(Vector2 pos)
|
|
||||||
{
|
|
||||||
Texture n = ninja_texture;
|
|
||||||
// DrawTexture(n, pos.x - n.width/2, pos.y - n.height/2, WHITE);
|
|
||||||
|
|
||||||
Rectangle source = {0, 0, n.width, n.height};
|
|
||||||
Rectangle dest = {pos.x, pos.y, n.width, n.height};
|
|
||||||
Vector2 origin = {n.width/2, n.height/2};
|
|
||||||
float angle = -Vector2LineAngle(pos, GetMousePosition());
|
|
||||||
angle *= 180/PI;
|
|
||||||
angle += 90;
|
|
||||||
DrawTexturePro(n, source, dest, origin, angle, WHITE);
|
|
||||||
}
|
|
Loading…
Reference in New Issue