-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathEnemy.h
124 lines (101 loc) · 3.76 KB
/
Enemy.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
#ifndef Enemy_H
#define Enemy_H
#include <iostream>
#include <string>
#include <vector>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include "bullet.h"
#include <vector>
using std::vector;
class Enemy
{
public:
SDL_Texture* loadImage(std::string fname, SDL_Renderer *gRenderer);
//Initializes the variables, Constructor
Enemy(int x, int y, int w, int h, int xvel, int yvel, int diff, SDL_Renderer *gRenderer);
~Enemy();
void initializeSprites(SDL_Renderer *gRenderer);
//Shows the enemy
void renderEnemy(SDL_Renderer* gRenderer);
//Moves the enemy
void move(int playerX, int playerY, std::vector<int> bulletX, std::vector<int> bulletY, std::vector<int> bulletVelX, std::vector<int> bulletVelY, std::vector<int> stalagmX, std::vector<int> stalagmH, std::vector<int> stalagtX, std::vector<int> stalagtH, std::vector<int> turretX, std::vector<int> turretH, std::vector<int> turretBottom, int kamiX, int kamiY, int cave_y);
bool checkCollide(int x, int y, int pWidth, int pHeight, int xTwo, int yTwo, int pTwoWidth, int pTwoHeight);
bool checkCollision(int x, int y, int w, int h);
void hit(int d);
//Position, dimensions, and velocity accessors
int getX();
int getY();
int getWidth();
int getHeight();
int getHealth();
void setyVelo(int y);
void setxVelo(int x);
void setPosX(int x);
void setPosY(int y);
// Methods that can be used to undo the enemy's moves when dealing with collisions
void undoXMove();
void undoYMove();
void redoXMove();
void redoYMove();
SDL_Rect* getHitbox();
Bullet* handleFiring();
int chooseDirection();
void calculateRiskscores(int playerX, int playerY, std::vector<int> bulletX, std::vector<int> bulletY, std::vector<int> bulletVelX, std::vector<int> bulletVelY, int kamiX, int kamiY, std::vector<int> stalagmX, std::vector<int> stalagmH, std::vector<int> stalagtX, std::vector<int> stalagtH, std::vector<int> turretX, std::vector<int> turretH, std::vector<int> turretBottom);
void moveLeft();
// Sprites for the enemy
SDL_Texture* sprite1;
SDL_Texture* sprite2;
// Sounds
Mix_Chunk *hit_sound;
private:
// Animation and shooting frequencies of the enemy
static const int ANIMATION_FREQ = 100;
static const int FIRING_FREQ = 1000;
static const int FLICKER_FREQ = 50;
static const int FLICKER_TIME = 500;
static const int SPAWN_FREQ = 3000;
// Limits on where the enemy can go
static const int MIN_X = 0;
static const int MAX_X = 500;
static const int MIN_Y = 110;
static const int MAX_Y = 610;
// Variables for squares and their corresponding risk scores
static const int SQUARE_WIDTH = 100;
static const int NUM_HORIZONTAL_SQUARES = (MAX_X - MIN_X) / SQUARE_WIDTH;
static const int NUM_VERTICAL_SQUARES = (MAX_Y - MIN_Y) / SQUARE_WIDTH;
double riskScores[NUM_HORIZONTAL_SQUARES][NUM_VERTICAL_SQUARES];
//Position and size of the enemy sprite on screen
double xPos;
double yPos;
int current_x_square;
int current_y_square;
int width;
int height;
int prev_direction;
//Velocity of the enemy
int maxXVelo;
int maxYVelo;
int xVelo;
int yVelo;
double tiltAngle;
//defines the enemy asset
SDL_Rect enemy_sprite;
//defines the hitbox of the enemy
SDL_Rect enemy_hitbox;
// Move times, used for handling framerate-independent movement
int time_since_move;
int last_move;
// Shooting times, used for handling framerate-independent firing rate
int time_since_shoot;
int last_shot;
// Game difficulty
int diff;
//health variables for the enemy
int time_hit;
int time_destroyed;
int health;
bool is_destroyed;
};
#endif