Compare commits

...

5 Commits

Author SHA1 Message Date
nemo eac8f75da8 make dist only png in data/ 2024-10-09 18:43:42 +02:00
nemo 1c37a00946 bullet shoot from middle player 2024-10-09 14:41:27 +02:00
nemo 629ac1a90d more minigun bullet + recule 2024-10-08 13:10:13 +02:00
nemo b0feeb2099 debug player 2024-10-08 10:48:20 +02:00
nemo 57eba3c089 minigun player 2024-10-08 10:41:21 +02:00
10 changed files with 86 additions and 6 deletions

View File

@ -1,4 +1,4 @@
SRC=main.c ninja.c keys.c bullet.c
SRC=main.c ninja.c keys.c bullet.c minigun.c
EXE=voleur
CC=gcc
@ -12,8 +12,8 @@ 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
zip -r $(EXE)-linux data/*.png $(EXE)
zip -r $(EXE)-windows data/*.png $(EXE).exe
run: all
./voleur

View File

@ -11,7 +11,7 @@ typedef struct Bullet {
float angle;
} Bullet;
#define BULLET_MAX 500
#define BULLET_MAX 5000
Bullet bullets[BULLET_MAX] = {0};
@ -20,6 +20,7 @@ Texture textures[BULLET_COUNT];
void bullet_load()
{
textures[BULLET_SHURIKEN] = LoadTexture("data/shuriken.png");
textures[BULLET_MINIGUN] = LoadTexture("data/bullet.png");
}
void bullet_spawn(BulletType type, Vector2 pos, float angle)
@ -47,6 +48,12 @@ void draw_bullets()
Vector2 toward = Vector2Normalize((Vector2) {cos(angle), sin(angle)});
bullets[i].pos = Vector2Add(bullets[i].pos, Vector2Scale(toward, speed));
bullets[i].time -= GetFrameTime();
DrawTexture(textures[bullets[i].type], bullets[i].pos.x, bullets[i].pos.y, WHITE);
Texture t = textures[bullets[i].type];
Rectangle source = {0, 0, t.width, t.height};
Rectangle dest = {bullets[i].pos.x + t.width/2, bullets[i].pos.y + t.height/2, t.width, t.height};
Vector2 origin = {t.width/2, t.height/2};
DrawTexturePro(t, source, dest, origin, bullets[i].angle + 90, WHITE);
}
}

View File

@ -3,6 +3,7 @@
typedef enum BulletType {
BULLET_SHURIKEN,
BULLET_MINIGUN,
BULLET_COUNT,
} BulletType;

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 215 B

After

Width:  |  Height:  |  Size: 204 B

BIN
data/minigun.aseprite Normal file

Binary file not shown.

BIN
data/minigun.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 880 B

22
main.c
View File

@ -6,6 +6,13 @@
#include "bullet.h"
#include "keys.h"
#include "ninja.h"
#include "minigun.h"
typedef enum PlayerType {
PLAYER_NINJA,
PLAYER_MINIGUN,
PLAYER_COUNT,
} PlayerType;
#define SCREEN_MIDDLE ((Vector2) {window_size.x/2, window_size.y/2})
@ -70,7 +77,11 @@ int main(void)
change_layout_azerty();
PlayerType player_type = PLAYER_MINIGUN;
load_ninja();
load_minigun();
bullet_load();
while (!WindowShouldClose()) {
@ -80,6 +91,12 @@ int main(void)
camera.offset = SCREEN_MIDDLE;
}
#ifndef RELEASE
if (IsKeyPressed(KEY_SPACE)) {
player_type = (player_type+1)%PLAYER_COUNT;
}
#endif
if (ninja_dash_time() <= EPSILON) {
float movement_speed = 10.0f * DT * 50;
if ((key_down(KC_UP) || key_down(KC_DOWN)) && (key_down(KC_LEFT) || key_down(KC_RIGHT)))
@ -114,7 +131,10 @@ int main(void)
draw_bullets();
}
EndMode2D();
draw_ninja(Vector2Add(SCREEN_MIDDLE, cam_shake), &camera);
if (player_type == PLAYER_NINJA)
draw_ninja(Vector2Add(SCREEN_MIDDLE, cam_shake), &camera);
else if (player_type == PLAYER_MINIGUN)
draw_minigun(Vector2Add(SCREEN_MIDDLE, cam_shake), &camera);
}
EndDrawing();
}

40
minigun.c Normal file
View File

@ -0,0 +1,40 @@
#include "raylib.h"
#include "raymath.h"
#include "keys.h"
#include "bullet.h"
Texture minigun_texture;
void load_minigun()
{
minigun_texture = LoadTexture("data/minigun.png");
}
float minigun_radius()
{
return fmax(minigun_texture.width, minigun_texture.height)/2;
}
void draw_minigun(Vector2 pos, Camera2D *cam)
{
Texture m = minigun_texture;
Rectangle source = {0, 0, m.width, m.height};
Rectangle dest = {pos.x, pos.y, m.width, m.height};
Vector2 origin = {m.width/2, m.height/2};
float angle = -Vector2LineAngle(pos, GetMousePosition());
angle *= 180/PI;
if (key_down(KC_SHOOT)) {
int speed = 5;
Vector2 world = GetScreenToWorld2D(pos, *cam);
Vector2 toward = Vector2Normalize((Vector2) {cos(angle * PI/180), sin(angle * PI/180)});
cam->target = Vector2Subtract(world, Vector2Scale(toward, speed));
bullet_spawn(BULLET_MINIGUN, Vector2Subtract(world, Vector2Scale(toward, speed*1.0)), angle);
bullet_spawn(BULLET_MINIGUN, Vector2Subtract(world, Vector2Scale(toward, speed*6.0)), angle);
}
DrawTexturePro(m, source, dest, origin, angle + 90, WHITE);
}

12
minigun.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef MINIGUN_H
#define MINIGUN_H
void load_minigun();
float minigun_radius();
void draw_minigun(Vector2 pos, Camera2D *cam);
float minigun_dash_time();
#endif // MINIGUN_H