Compare commits

..

No commits in common. "eac8f75da85e3b9b895398328905d78a329aedb5" and "4ae6c3fdfbe00c170ca8c4b55ee393ed3fde5375" have entirely different histories.

10 changed files with 6 additions and 86 deletions

View File

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

View File

@ -11,7 +11,7 @@ typedef struct Bullet {
float angle; float angle;
} Bullet; } Bullet;
#define BULLET_MAX 5000 #define BULLET_MAX 500
Bullet bullets[BULLET_MAX] = {0}; Bullet bullets[BULLET_MAX] = {0};
@ -20,7 +20,6 @@ Texture textures[BULLET_COUNT];
void bullet_load() void bullet_load()
{ {
textures[BULLET_SHURIKEN] = LoadTexture("data/shuriken.png"); textures[BULLET_SHURIKEN] = LoadTexture("data/shuriken.png");
textures[BULLET_MINIGUN] = LoadTexture("data/bullet.png");
} }
void bullet_spawn(BulletType type, Vector2 pos, float angle) void bullet_spawn(BulletType type, Vector2 pos, float angle)
@ -48,12 +47,6 @@ void draw_bullets()
Vector2 toward = Vector2Normalize((Vector2) {cos(angle), sin(angle)}); Vector2 toward = Vector2Normalize((Vector2) {cos(angle), sin(angle)});
bullets[i].pos = Vector2Add(bullets[i].pos, Vector2Scale(toward, speed)); bullets[i].pos = Vector2Add(bullets[i].pos, Vector2Scale(toward, speed));
bullets[i].time -= GetFrameTime(); 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,7 +3,6 @@
typedef enum BulletType { typedef enum BulletType {
BULLET_SHURIKEN, BULLET_SHURIKEN,
BULLET_MINIGUN,
BULLET_COUNT, BULLET_COUNT,
} BulletType; } BulletType;

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 204 B

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 880 B

22
main.c
View File

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

View File

@ -1,40 +0,0 @@
#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);
}

View File

@ -1,12 +0,0 @@
#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