Repository navigation
Expand file tree
/
Copy pathbullet.c
More file actions
57 lines (46 loc) · 1.39 KB
/
Copy pathbullet.c
File metadata and controls
57 lines (46 loc) · 1.39 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
/*
* Handles bullet movements, creation, and destruction
*/
#include <math.h>
#include <stdio.h>
#include "display.h"
#include "bullet.h"
int bulletIndex = 0;
//create a new bullet and store in the bullets container
void createBullet(double pSpeed, double pHeading, double* pLocation)
{
//printf("adding bullet at index %d\n", bulletIndex);
//Bullet bullet = bullets[bulletIndex];
//bulletIndex = (bulletIndex + 1) % MAX_BULLETS;
Bullet bullet;
bullet.alive = 1;
bullet.speed = pSpeed;
bullet.heading = pHeading;
bullet.location[0] = pLocation[0];
bullet.location[1] = pLocation[1];
bullet.location[2] = pLocation[2];
bullets[bulletIndex] = bullet;
bulletIndex = (bulletIndex + 1) % MAX_BULLETS;
//printf("bullet created\n");
}
//move the bullet according to its heading
void moveBullet(int id)
{
//printf("moving bullet\n");
bullets[id].location[0] += sin(bullets[id].heading) * bullets[id].speed;
bullets[id].location[2] -= cos(bullets[id].heading) * bullets[id].speed;
//printf("%f, %f\n", bullets[id].location[0], bullets[id].location[2]);
if(bullets[id].location[0] > ROOM_SIZE || bullets[id].location[0] < (ROOM_SIZE * -1))
{
destroyBullet(id);
}
if(bullets[id].location[2] > ROOM_SIZE || bullets[id].location[2] < (ROOM_SIZE * -1))
{
destroyBullet(id);
}
}
//destroy the bullet if it leaves the room or hits a zombie
void destroyBullet(int id)
{
bullets[id].alive = 0;
}