-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.h
70 lines (55 loc) · 1.77 KB
/
player.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
/**********************************************************************
Module: player.h
Author: Junseok Lee
Purpose: Manages the player's ship for invaders
**********************************************************************/
#ifndef PLAYER_H
#define PLAYER_H
#include "console.h"
#include "globals.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 of player's state */
typedef enum playerState_enum
{
GAME, //game running
DEAD, //player dead
GAMEOVER, //game over
WIN //player win, game end
} playerState;
/* Represents a player */
typedef struct player_struct
{
int startCol; //starting column of player
int startRow; //starting row of player
playerState state; //player's current state: GAME,DEAD,GAMEOVER,WIN
bool running; //current player is running
int lives; //lives the player has
int row; //the player's current row
int col; //the player's current column
int prevRow; //the player's previous row
int prevCol; //the player's previous column
int animTile; //the player animation tile
pthread_t thread; //the player thread
pthread_mutex_t mutex; //the player mutex
} player;
/* The thread runs as the player */
void *runPlayerT(void *data);
/* Spawns the player for the first time, called externally
returns the newly spawned player*/
player* spawnPlayer(int startRow, int startCol, int lives);
/* Moves player to the destination row & column*/
void playerMove(player *f, int dRow, int dCol);
/* removes a life, ends the game if all lives gone */
void killPlayer(player* p);
/* specifies left,right,up,down to playerMove*/
void keyMove(player * p, char direction);
/* Points to the player object*/
player * playerPtr;
#endif