-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.h
71 lines (61 loc) · 2.03 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
71
#ifndef ASTEROIDS_PLAYER
#define ASTEROIDS_PLAYER
#include "splashkit.h"
using namespace std;
#define PLAYER_SPEED .15
#define PLAYER_ROTATE_SPEED 5
#define PLAYER_LIVES 4
#define FREE_LIFE 5000
#define COOLDOWN_TIME 400
#define IMMUNITY_TIME 3000
#define SPAWN_DELAY 2500
/**
* The player data keeps track of all of the information related to the player.
*
* @field main_sprite The player's sprite - used to track position and movement
* @field score The current score for the player
* @field free_life_score Used to keep track of progress toward free life
* @field lives Lives left
* @field current_position Point 2d representing the players current position
* @field velocity Point 2d representing the players current velocity
* @field shoot_cooldown Timer to prevent player spamming bullets
* @field player_timer Dual use, used for both immunity and spawn delay
*/
struct player_data
{
sprite main_sprite;
int score;
int free_life_score;
int lives;
point_2d current_position;
point_2d velocity;
timer shoot_cooldown;
timer player_timer;
};
/**
* Creates a new player and sets up initial values and timers.
*
* @returns The new player data
**/
player_data new_player();
/**
* Creates the sprite, adds bitmap layers, places sprite either in the centre (new ship) or randomly (hyperspace)
*
* @field player Reference to the player
* @field centred Denotes whether the sprite should be placed centrally.
*
**/
void spawn_player(player_data &player, bool centred);
/**
* Draws the player to the screen.
*
* @field player_to_draw The player to draw to the screen
**/
void draw_player(const player_data &player_to_draw);
/**
* Updates the player using the existing position and velocity
*
* @field player_to_update The player being updated
**/
void update_player(player_data &player_to_update);
#endif