-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.h
87 lines (68 loc) · 2.53 KB
/
bullet.h
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
/**********************************************************************
Module: bullet.h
Author: Junseok Lee
Purpose: manages the player bullet thread. Moves the bullets and the
linked list that controls the player bullet.
**********************************************************************/
#ifndef BULLET_H
#define BULLET_H
#include "console.h"
#include "globals.h"
#include "enemy.h"
#include "llist.h"
#include "threadwrappers.h"
#include <pthread.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/select.h>
#include <curses.h>
#include <string.h>
/* Enum, Represents bullet state */
typedef enum bulletState_enum
{
TRANSIT, //bullet is in transit
COLLISION, //bullet colldies with player
DESTROY //bullet done, to be cleaned
} bulletState;
/* Represents player bullet */
typedef struct bullet_struct
{
int startCol; //bullet starting column at player position
int startRow; //bullet starting row at player position
bulletState state; //current state of bullet
bool running; //bullet in motion when true
int row; //bullet's current position (row)
int col; //bullet's current position (column)
int prevRow; //bullet's row in the previous tick
int prevCol; //bullet's column in the previous tick
pthread_t thread; //thread for each bullet
pthread_mutex_t mutex; //mutex for each bullet
struct bullet_struct * next; //next bullet linked list
} bullet;
/* Creates new player bullet. Changes state to TRANSIT,
rows to startRow, col to startCol */
void newPlayerBullet(bullet *b);
/* Moves bullet one tick. Checks if enemy has been hit
(using the enemyHit(enemy * e, bullet * b) method),
and checks if bullet is out of boundaries. */
void playerBulletMove(bullet *b);
/* Spawns player bullet in given row and column,
returns spawned bullet pointer. Initializes enemy bullet
mutex and connects list*/
bullet* spawnBullet(int startRow, int startCol); // player bulllet = 0, enemy bullet = 1
/* Runs bullet thread. Manages bullet state and
bullet movement. */
void *runBulletT(void *data);
/* Redraws the moved bullet. */
void bulletRedraw(bullet *b, bool lock);
/* Checks if enemy caterpillar is hit at
player bullet's current position. */
int enemyHit(enemy * e, bullet * b);
/* Clears bullet from the screen */
void killBullets();
/* Frees bullets from allocation */
void freeBullets(bullet * head);
struct bullet_struct *bulletHead; //Head of player bullet list
pthread_mutex_t bulletMutex; //Player bullet mutex
#endif