-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectile.c
More file actions
110 lines (99 loc) · 2.46 KB
/
projectile.c
File metadata and controls
110 lines (99 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "projectile.h"
#include <raylib.h>
#include "game.h"
#include <stdlib.h>
#include <raymath.h>
#include "helpers.h"
#include "enemy.h"
#include "sounds.h"
extern game_t *pgame;
Projectile_t *ga_pprojectiles[MAX_PROJECTILES];
unsigned long long g_numberOfProjectiles = 0;
void projectileTick(Projectile_t *pprojec)
{
//projectile lifespan
if (pprojec->m_tick > 200)
{
distroyProjectile(pprojec->m_ID);
return;
}
//movement restriction
if(pprojec->m_position.x > GAMEWORLD_SIZE)
{
distroyProjectile(pprojec->m_ID);
return;
}
if(pprojec->m_position.x < -GAMEWORLD_SIZE)
{
distroyProjectile(pprojec->m_ID);
return;
}
if(pprojec->m_position.y > GAMEWORLD_SIZE)
{
distroyProjectile(pprojec->m_ID);
return;
}
if(pprojec->m_position.y < -GAMEWORLD_SIZE)
{
distroyProjectile(pprojec->m_ID);
return;
}
//check collition againt everything o_0
for(int i = 0; i < MAX_ENEMIES; i++)
{
if(getEnemyByID(i) == NULL)continue;
if(CheckCollisionCircles(pprojec->m_position, pprojec->m_radios, getEnemyByID(i)->m_position, getEnemyByID(i)->m_radios))
{
getEnemyByID(i)->m_HP -= pprojec->m_damage;
distroyProjectile(pprojec->m_ID);
return;
}
}
pprojec->m_position = Vector2Add(pprojec->m_position, pprojec->m_velocity);
++pprojec->m_tick;
}
Projectile_t *createProjectile(Vector2 pos, Vector2 vel, float angle)
{
Projectile_t *pprojec = malloc(sizeof(Projectile_t));
for(unsigned long i = 0; i < MAX_PROJECTILES; i++)
{
if(ga_pprojectiles[i] != NULL)continue;
ga_pprojectiles[i] = pprojec;
pprojec->m_ID = i;
break;
}
pprojec->m_velocity = Vector2Rotate((Vector2){0,-10}, angle);
pprojec->m_position = pos;
pprojec->m_color = GetRandomColorNoAlpha();
pprojec->m_radios = GetRandomValue(5, 10);
pprojec->m_damage = pprojec->m_radios*2;
pprojec->m_tick = 0;
++g_numberOfProjectiles;
playGameSound(SOUND_SHOOT, (Vector2){0,0}, MASK_GLOBAL);
return pprojec;
}
Projectile_t *getProjectileByID(int ID)
{
return ga_pprojectiles[ID];
}
void distroyProjectile(int ID)
{
if(ID == -1)
{
for(int i = 0; i < MAX_PROJECTILES; i++)
{
if(ga_pprojectiles[i] == NULL)continue;
free(ga_pprojectiles[i]);
ga_pprojectiles[i] = NULL;
}
g_numberOfProjectiles = 0;
return;
}
free(ga_pprojectiles[ID]);
ga_pprojectiles[ID] = NULL;
--g_numberOfProjectiles;
}
unsigned long long getNumberOfProjectiles()
{
return g_numberOfProjectiles;
}