diff --git a/Makefile b/Makefile index 38b9291..89916cb 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/bullet.c b/bullet.c index 4d066f1..cc4b797 100644 --- a/bullet.c +++ b/bullet.c @@ -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, bullets[i].pos.y, t.width, t.height}; + Vector2 origin = {t.width/2, t.height/2}; + + DrawTexturePro(t, source, dest, origin, bullets[i].angle + 90, WHITE); } } diff --git a/bullet.h b/bullet.h index 2cb06c9..0d2445d 100644 --- a/bullet.h +++ b/bullet.h @@ -3,6 +3,7 @@ typedef enum BulletType { BULLET_SHURIKEN, + BULLET_MINIGUN, BULLET_COUNT, } BulletType; diff --git a/data/bullet.aseprite b/data/bullet.aseprite index a447085..dd2cbc3 100644 Binary files a/data/bullet.aseprite and b/data/bullet.aseprite differ diff --git a/data/bullet.png b/data/bullet.png index c7ec090..4394223 100644 Binary files a/data/bullet.png and b/data/bullet.png differ diff --git a/data/minigun.aseprite b/data/minigun.aseprite new file mode 100644 index 0000000..d248309 Binary files /dev/null and b/data/minigun.aseprite differ diff --git a/data/minigun.png b/data/minigun.png new file mode 100644 index 0000000..de32f67 Binary files /dev/null and b/data/minigun.png differ diff --git a/main.c b/main.c index 909f1ff..796e0ba 100644 --- a/main.c +++ b/main.c @@ -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,13 @@ int main(void) change_layout_azerty(); - load_ninja(); + PlayerType player_type = PLAYER_MINIGUN; + + if (player_type == PLAYER_NINJA) + load_ninja(); + else if (player_type == PLAYER_MINIGUN) + load_minigun(); + bullet_load(); while (!WindowShouldClose()) { @@ -114,7 +127,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(); } diff --git a/minigun.c b/minigun.c new file mode 100644 index 0000000..ae5b2c1 --- /dev/null +++ b/minigun.c @@ -0,0 +1,38 @@ +#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)) { + bullet_spawn(BULLET_MINIGUN, GetScreenToWorld2D(pos, *cam), angle); + + int speed = 5; + Vector2 toward = Vector2Normalize((Vector2) {cos(angle * PI/180), sin(angle * PI/180)}); + cam->target = Vector2Subtract(GetScreenToWorld2D(pos, *cam), Vector2Scale(toward, speed)); + } + + DrawTexturePro(m, source, dest, origin, angle + 90, WHITE); +} diff --git a/minigun.h b/minigun.h new file mode 100644 index 0000000..359bac3 --- /dev/null +++ b/minigun.h @@ -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