52 lines
1.2 KiB
C
52 lines
1.2 KiB
C
|
#include <stdio.h>
|
||
|
#include "raylib.h"
|
||
|
#include "raymath.h"
|
||
|
|
||
|
#include "bullet.h"
|
||
|
|
||
|
typedef struct Bullet {
|
||
|
BulletType type;
|
||
|
Vector2 pos;
|
||
|
float time;
|
||
|
float angle;
|
||
|
} Bullet;
|
||
|
|
||
|
#define BULLET_MAX 500
|
||
|
|
||
|
Bullet bullets[BULLET_MAX] = {0};
|
||
|
|
||
|
Texture textures[BULLET_COUNT];
|
||
|
|
||
|
void bullet_load()
|
||
|
{
|
||
|
textures[BULLET_SHURIKEN] = LoadTexture("data/shuriken.png");
|
||
|
}
|
||
|
|
||
|
void bullet_spawn(BulletType type, Vector2 pos, float angle)
|
||
|
{
|
||
|
for (int i = 0; i < BULLET_MAX; i++) {
|
||
|
if (bullets[i].time >= EPSILON)
|
||
|
continue;
|
||
|
bullets[i].time = 5;
|
||
|
bullets[i].angle = angle;
|
||
|
bullets[i].pos.x = pos.x - textures[type].width/2;
|
||
|
bullets[i].pos.y = pos.y - textures[type].height/2;
|
||
|
bullets[i].type = type;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void draw_bullets(Camera2D *cam)
|
||
|
{
|
||
|
for (int i = 0; i < BULLET_MAX; i++) {
|
||
|
if (bullets[i].time <= EPSILON)
|
||
|
continue;
|
||
|
|
||
|
float angle = bullets[i].angle * PI/180;
|
||
|
Vector2 toward = Vector2Normalize((Vector2) {cos(angle), sin(angle)});
|
||
|
bullets[i].pos = Vector2Add(bullets[i].pos, Vector2Scale(toward, 50));
|
||
|
bullets[i].time -= GetFrameTime();
|
||
|
DrawTexture(textures[bullets[i].type], bullets[i].pos.x, bullets[i].pos.y, WHITE);
|
||
|
}
|
||
|
}
|