ninjaaaaa
This commit is contained in:
parent
523d2fb9b0
commit
7124b9b6f8
|
@ -2,3 +2,4 @@ build/
|
||||||
.wakatime-project
|
.wakatime-project
|
||||||
voleur
|
voleur
|
||||||
voleur.exe
|
voleur.exe
|
||||||
|
*.zip
|
||||||
|
|
Binary file not shown.
Binary file not shown.
After 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})
|
||||||
|
|
||||||
typedef struct Player {
|
Vector2 window_size = { 800.0f, 600.0f };
|
||||||
float radius;
|
|
||||||
Vector2 coord;
|
|
||||||
} Player;
|
|
||||||
|
|
||||||
typedef struct Map {
|
typedef struct Map {
|
||||||
const Texture texture;
|
const Texture texture;
|
||||||
|
@ -41,17 +41,31 @@ void change_layout_qwerty(int *keys)
|
||||||
keys[KC_RIGHT] = KEY_D;
|
keys[KC_RIGHT] = KEY_D;
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera2D shake(Camera2D cam, int force)
|
Vector2 shake(int force)
|
||||||
{
|
{
|
||||||
cam.offset.x += GetRandomValue(-force/2, force/2);
|
Vector2 s;
|
||||||
cam.offset.y += GetRandomValue(-force/2, force/2);
|
s.x = GetRandomValue(-force/2, force/2);
|
||||||
return cam;
|
s.y = GetRandomValue(-force/2, force/2);
|
||||||
|
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,
|
||||||
|
@ -59,10 +73,6 @@ 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
|
||||||
|
@ -89,6 +99,8 @@ 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()) {
|
||||||
|
@ -111,38 +123,24 @@ int main(void)
|
||||||
if (IsKeyDown(keys[KC_UP]))
|
if (IsKeyDown(keys[KC_UP]))
|
||||||
camera.target.y += movement_speed ;
|
camera.target.y += movement_speed ;
|
||||||
|
|
||||||
if (IsKeyReleased(keys[KC_FREECAM]))
|
camera_bound(&camera, map.box, ninja_radius());
|
||||||
camera.target = player.coord;
|
|
||||||
if (!IsKeyDown(keys[KC_FREECAM])) {
|
|
||||||
player.coord = GetScreenToWorld2D(SCREEN_MIDDLE, camera);
|
|
||||||
|
|
||||||
if (player.coord.x - player.radius < map.box.x)
|
Vector2 cam_shake = {0};
|
||||||
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]))
|
||||||
effect_camera = shake(camera, 12);
|
cam_shake = shake(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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
#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