forked from ComputerGeek01/Random
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnits.hpp
156 lines (107 loc) · 3.34 KB
/
Units.hpp
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
#ifndef __UNITS__UNITS
#define __UNITS__UNITS
#include <iostream>
#include <vector>
#include <sstream>
#include <ctime>
#include <cmath>
#include <SFML/Graphics.hpp>
#define WIDTH 600
#define HEIGHT 400
#define SCALE .75
enum MODE{NORMAL, WAIT, CHASE, ATTACK, RUN};
enum TYPE{HUMAN, ZOMBIE, TER};
struct BASE
{
private:
public:
BASE() {}
virtual sf::Sprite* draw();
bool Hit(BASE* Obj);
std::string TYPE();
bool Test(sf::Vector2f A, sf::Vector2f B, sf::Vector2f RBA, sf::Vector2f RBB);
virtual std::string GetData();
int Type;
int LID; //Vector ID For Deletion And Looping
int PID; //Permanent ID
sf::Image* Img;
sf::Sprite Sprite; //Sprite Frame 1
sf::Sprite Sprite2; //Sprite Frame 2
sf::Vector2f Pos; //Position Of The Sprite
sf::Vector2f RB; //Right Bottom Of The Sprite
float Right;
float Bottom;
float Speed;
float scale;
MODE Mode;
bool Selected;
};
struct UNIT: BASE
{
private:
public:
UNIT(): Alive(true) {}
UNIT(sf::Image* img, int Z): Kills(0)
{
scale = SCALE;
LID = Id; //Id Is A Static Data Member
PID = Id;
Id++; //Increament Id Everytime Constructor Is Called
Alive = true;
Selected = false;
Mode = NORMAL;
Speed = 1;
Pos = sf::Vector2f(0,0);
Img = img; //Inherited From Base Class
Type = Z; //Inherited From Base Class
Time.Reset();
/////*Generate Units Position Until It Is Within The Bounds Of The Screen*/////
do
{
Pos.x = rand() % 200; //Start Somewhere between 0 and 200
Right = Pos.x + (25 * scale);
}while(Pos.x < 0 || Right > WIDTH);
do
{
Pos.y = rand() % HEIGHT;
Bottom = Pos.y + (50 * scale);
}while(Pos.y < 0 || Bottom > HEIGHT);
RB.x = Right;
RB.y = Bottom;
Sprite.SetImage(*Img);
Sprite.SetScale(scale, scale);
Sprite.SetSubRect(sf::IntRect(0, 0, 24, 50));
Sprite2.SetImage(*Img);
Sprite2.SetScale(scale, scale);
Sprite2.SetSubRect(sf::IntRect(25, 0, 50, 50));
Sprite.SetPosition(Pos);
Sprite2.SetPosition(Pos);
Dest = Pos;
}
void Set(float X, float Y);
int Hit(UNIT* Unit);
virtual void Die();
virtual void Update();
virtual int Attack(UNIT* Unit);
virtual void Click(float X, float Y, bool Shift);
virtual void Go(float X, float Y);
virtual void Zombify(sf::Image* zimg);
virtual bool RightClick(float X, float Y);
virtual void Hit();
bool Chase(UNIT* Unit);
void Move();
void MoveAway(UNIT* Unit);
void NewDest();
sf::Image* Health;
static int Id;
sf::Vector2f Dest;
sf::Vector2f TargetLoc;
sf::Shape TargetLine;
int Kills;
int Target;
int HP;
bool Alive;
float TRange;
sf::Clock Time;
};
#endif