-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPlayer.h
164 lines (139 loc) · 4.27 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#ifndef Player_H
#define Player_H
#include <iostream>
#include <string>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include "bullet.h"
class Player
{
public:
static constexpr double PI = 3.14159265358979323846;
//The default dimensions of the player
static const int PLAYER_WIDTH = 125;
static const int PLAYER_HEIGHT = 53;
//The dimensions of the player's hurtbox
int player_hurt_width;
int player_hurt_height;
int s_player_hurt_width;
int s_player_hurt_height;
//Maximum axis velocity, animation frequency, and shot frequency of the player
static const int MAX_PLAYER_VEL = 300;
static const int MAX_SHOOT_HEAT = 100000;
static const int SHOOT_COST = 7000;
static const int RECOVERY_RATE = 10;
static const int COOLDOWN_TIME = 2000;
static const int INFINITE_TIME = 4000;
static const int INVINCE_TIME = 5000;
static const int AUTOFIRE_TIME = 4000;
static const int SMALL_TIME = 6000;
// Animation frequency, the frequency with which the player flickers when hit, and the amount of time the player flickers after being hit
static const int ANIMATION_FREQ = 100;
static const int FLICKER_FREQ = 50;
static const int FLICKER_TIME = 500;
//The dimensions of the player
int player_width;
int player_height;
// Move and shooting times, needed for framerate-independent movement and animation speeds
int time_since_move;
int time_since_f_shot;
int time_since_b_shot;
int last_move;
int fshot_heat;
int bshot_heat;
int fshot_max_time;
int bshot_max_time;
bool fshot_maxed;
bool bshot_maxed;
int time_since_inf;
int time_since_invincible;
int time_since_auto;
int time_since_small;
bool infiniteShooting;
bool invincePower;
bool autoFire;
bool small;
// Last time the player was hit, and their current health (out of 100)
int time_hit;
int health;
int barrel_heat;
int time_since_cool;
int last_cool;
double bg_X;
double tiltAngle;
bool moveUp;
bool moveDown;
bool moveForward;
bool moveBackward;
// Sprites for the player
SDL_Texture* sprite1;
SDL_Texture* sprite2;
int difficulty;
// Sounds
Mix_Chunk *bullet_shot;
Mix_Chunk *hit_sound;
// Used to load sprites
SDL_Texture* loadImage(std::string fname, SDL_Renderer *gRenderer);
void initializeSprites(int diff, SDL_Renderer *gRenderer);
//Initializes the variables
Player(int xPos, int yPos, int diff, SDL_Renderer *gRenderer);
~Player();
//Takes key presses and adjusts the player's velocity
void handleEvent(SDL_Event &e);
void handleMute();
//Moves the player
void acceleration(bool &increasing, bool &decreasing, double &accel, double &accelerate_by, double &deccelerate_factor, double &vel);
void move(int SCREEN_WIDTH, int SCREEN_HEIGHT, int LEVEL_HEIGHT, int camY);
//Shows the player on the screen relative to the camera
void render(SDL_Renderer *gRenderer, int SCREEN_WIDTH, int SCREEN_HEIGHT);
// Damages the player when they've been hit
void hit(int damage);
//heals player
void heal(int amount);
// Handle collisions
bool checkCollisionKami(int kamiX, int kamiY, int kamiW, int kamiH);
bool checkCollisionBullet(int bullX, int bullY, int bullW, int bullH);
bool checkCollide(int x, int y, int pWidth, int pHeight, int xTwo, int yTwo, int pTwoWidth, int pTwoHeight);
// Creates bullets when the player wants to fire forwards or backwards
Bullet* handleForwardFiring();
Bullet* handleBackwardFiring();
//Accessors
int getPosX();
int getPosY();
void setVelX(int vel_x);
void setVelY(int vel_y);
int getVelX();
int getVelY();
void setPosX(int x);
void setPosY(int y);
int getWidth();
int getHeight();
int getHitboxX();
int getHitboxY();
int getHurtWidth();
int getHurtHeight();
int getHealth();
int getFrontHeat();
int getBackHeat();
void setHealthMax();
void setInfiniteVal(bool);
void setInvinceVal (bool);
void setAutoFire(bool);
void setSmall(bool);
void resetHeatVals();
bool getAutoFire();
bool getSmall();
// Methods that can be used to undo the user's moves when dealing with collisions
void undoXMove();
void undoYMove();
void redoXMove();
void redoYMove();
private:
//The X and Y offsets of the player (ON SCREEN)
double x_pos, y_pos;
//The velocity of the player
double x_vel, y_vel;
double x_accel, y_accel;
};
#endif