Skip to content

Commit 7ef6c6a

Browse files
committed
Extract ZIP contents
1 parent 39a9394 commit 7ef6c6a

24 files changed

+1767
-0
lines changed

BASE.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#include "Building.hpp"
2+
3+
4+
sf::Sprite* BASE::draw()
5+
{
6+
if(Selected)
7+
{
8+
Sprite2.SetPosition(Pos);
9+
return &Sprite2;
10+
}
11+
12+
Sprite.SetPosition(Pos);
13+
return &Sprite;
14+
}
15+
16+
17+
18+
bool BASE::Hit(BASE* Obj)
19+
{
20+
if(Test(Pos, Obj->Pos, RB, Obj->RB))
21+
{
22+
return true;
23+
}
24+
25+
return false;
26+
}
27+
28+
29+
bool BASE::Test(sf::Vector2f A, sf::Vector2f B, sf::Vector2f RBA, sf::Vector2f RBB)
30+
{
31+
if((A.x > B.x) && (A.x < RBB.x) && (A.y > B.y) && (A.y < RBB.y))
32+
{
33+
/* if(A.x > B.x)
34+
{
35+
std::cout << " A.x Greater Then B.x\n";
36+
}
37+
if(A.x < RBB.x)
38+
{
39+
std::cout << " A.x Less Then RBB.x\n";
40+
}
41+
42+
if(A.y > B.y)
43+
{
44+
std::cout << " A.y Greater Then B.y\n";
45+
}
46+
if(A.y < RBB.y)
47+
{
48+
std::cout << " A.y Less Then RBB.y\n";
49+
} */
50+
51+
52+
return true;
53+
}
54+
55+
if((RBA.x > B.x) && (RBA.x < RBB.x) && (RBA.y > B.y) && (RBA.y < RBB.y))
56+
{
57+
/* if(RBA.x > B.x)
58+
{
59+
std::cout << " RBA.x Greter Then B.x\n";
60+
}
61+
if(RBA.x < RBB.x)
62+
{
63+
std::cout << " RBA.x Less Then RBB.x\n";
64+
}
65+
66+
if(RBA.y > B.y)
67+
{
68+
std::cout << " RBA.y Greater Then B.y\n";
69+
}
70+
if(RBA.y < RBB.y)
71+
{
72+
std::cout << " RBA.y Less Then RBB.y\n";
73+
} */
74+
75+
76+
return true;
77+
}
78+
79+
return false;
80+
}
81+
82+
83+
std::string BASE::GetData()
84+
{
85+
return "Hello";
86+
}
87+
88+
89+
std::string BASE::TYPE()
90+
{
91+
switch(Type)
92+
{
93+
case HUMAN:
94+
return " Human ";
95+
case ZOMBIE:
96+
return " Zombie ";
97+
case TER:
98+
return " Building ";
99+
default:
100+
return " NULL ";
101+
}
102+
}

Building.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "Building.hpp"

Building.hpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "Units.hpp"
2+
3+
#ifndef __BUILDING__BUILDING
4+
#define __BUILDING__BUILDING
5+
6+
struct BUILDING: BASE
7+
{
8+
private:
9+
10+
public:
11+
BUILDING(sf::Image* img, float X, float Y)
12+
{
13+
Img = img;
14+
Type = 3;
15+
16+
Pos.x = X;
17+
Pos.y = Y;
18+
19+
Right = Img->GetWidth();
20+
Bottom = Img->GetHeight();
21+
22+
RB.x = Right;
23+
RB.y = Bottom;
24+
25+
26+
Sprite.SetImage(*Img);
27+
28+
//std::cout << "X: " << Pos.x << " Y: " << Pos.y << " Right: " << Right << " Bottom: " << Bottom << "\n";
29+
Sprite.SetPosition(Pos);
30+
}
31+
32+
//bool Hit(sf::Vector2f Pos);
33+
34+
};
35+
36+
37+
38+
39+
#endif

Enemy.cpp

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#include "Enemy.hpp"
2+
3+
int ENEMY::Enemy = 0;
4+
5+
sf::Sprite* ENEMY::draw()
6+
{
7+
if(Selected)
8+
{
9+
Sprite2.SetPosition(Pos);
10+
return &Sprite2;
11+
}
12+
13+
return &Sprite;
14+
}
15+
16+
17+
std::string ENEMY::GetData()
18+
{
19+
if(!Alive)
20+
{
21+
return "DEAD";
22+
}
23+
24+
std::ostringstream Stream;
25+
Stream << "LID: " << LID << "\nHit Points: " << HP << "\nTarget: " << Target;
26+
27+
return Stream.str();
28+
}
29+
30+
31+
bool ENEMY::RightClick(float X, float Y)
32+
{
33+
if(X >= Pos.x && X <= Right && Y >= Pos.y && Y <= Bottom)
34+
{
35+
Targeted = true;
36+
return true;
37+
}
38+
else
39+
{
40+
Targeted = false;
41+
return false;
42+
}
43+
}
44+
45+
46+
47+
int ENEMY::Attack(UNIT* Unit)
48+
{
49+
if(!Alive)
50+
{
51+
return 0;
52+
}
53+
54+
if(!Unit->Alive)
55+
{
56+
if(Unit->LID == Target)
57+
{
58+
Target = -1;
59+
}
60+
61+
return 0;
62+
}
63+
64+
float NewRange = fabs(sqrt(pow(Unit->Pos.y, 2) + pow(Unit->Pos.x, 2)) - sqrt(pow(Pos.x, 2) + pow(Pos.y, 2)));
65+
TRange = fabs(sqrt((pow(TargetLoc.y, 2) + pow(TargetLoc.x, 2))) - sqrt(pow(Pos.x, 2) + pow(Pos.y, 2)));
66+
67+
if(Unit->Type == HUMAN)
68+
{
69+
if(Target == -1 && Unit->Alive == true) //If Enemy Has No Target AND The Unit Being Looked At Is Alive
70+
{
71+
Target = Unit->LID;
72+
}
73+
74+
if(Unit->LID == Target) //Chase Target
75+
{
76+
Dest = Unit->Pos;
77+
TargetLoc = Unit->Pos;
78+
}
79+
}
80+
81+
if(Test(Pos, Unit->Pos, RB, Unit->RB)) //Test For Impact With Target
82+
{
83+
if(Unit->Type == ZOMBIE)
84+
{
85+
MoveAway(Unit);
86+
return 0;
87+
}
88+
89+
std::cout << LID << " Is Attacking " << Unit->LID << std::endl;
90+
91+
int Roll = rand() % 4;
92+
switch(Roll)
93+
{
94+
case 1:
95+
Unit->Hit();
96+
Kills++;
97+
std::cout << LID << " Hit: " << Unit->LID << "\n";
98+
99+
//Target = -1;
100+
return 1;
101+
102+
case 2:
103+
//std::cout << "\nZombifying " << Id << "\n";
104+
//Target = -1;
105+
return 3;
106+
107+
default:
108+
//std::cout << Unit->ID << " Got Away From " << Id << std::endl;
109+
break;
110+
}
111+
}
112+
113+
return 0;
114+
}
115+
116+
117+
void ENEMY::Hit()
118+
{
119+
HP--;
120+
121+
if(HP <= 0)
122+
{
123+
Die();
124+
}
125+
}
126+
127+
128+
void ENEMY::Die()
129+
{
130+
Alive = false;
131+
Selected = false;
132+
Id--;
133+
Enemy--;
134+
}

Enemy.hpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include "Units.hpp"
2+
3+
struct ENEMY : UNIT
4+
{
5+
private:
6+
7+
public:
8+
ENEMY(sf::Image* img, int Z): Targeted(false)
9+
{
10+
scale = SCALE;
11+
12+
Enemy++;
13+
14+
HP = 2;
15+
16+
LID = Id; //Id Is A Static Data Member
17+
PID = Id;
18+
Id++; //Increament Id Everytime Constructor Is Called
19+
Alive = true;
20+
Selected = false;
21+
Mode = NORMAL;
22+
Speed = .5;
23+
24+
Kills = 0;
25+
26+
Pos = sf::Vector2f(0,0);
27+
28+
Img = img; //Inherited From Base Class
29+
Type = Z; //Inherited From Base Class
30+
31+
Time.Reset();
32+
Target = -1;
33+
34+
/////*Generate Units Position Until It Is Within The Bounds Of The Screen*/////
35+
do
36+
{
37+
Pos.x = rand() % 200; //Start Somewhere between 0 and 200
38+
Right = Pos.x + (25 * scale);
39+
}while(Pos.x < 0 || Right > WIDTH);
40+
41+
do
42+
{
43+
Pos.y = rand() % HEIGHT;
44+
Bottom = Pos.y + (50 * scale);
45+
}while(Pos.y < 0 || Bottom > HEIGHT);
46+
47+
RB.x = Right;
48+
RB.y = Bottom;
49+
50+
Sprite.SetImage(*Img);
51+
Sprite.SetScale(scale, scale);
52+
Sprite.SetSubRect(sf::IntRect(0, 0, 24, 50));
53+
54+
Sprite2.SetImage(*Img);
55+
Sprite2.SetScale(scale, scale);
56+
Sprite2.SetSubRect(sf::IntRect(25, 0, 50, 50));
57+
58+
Sprite3.SetImage(*Img);
59+
Sprite3.SetScale(scale, scale);
60+
Sprite3.SetSubRect(sf::IntRect(51, 0, 75, 50));
61+
62+
63+
Sprite.SetPosition(Pos);
64+
Sprite2.SetPosition(Pos);
65+
Sprite3.SetPosition(Pos);
66+
67+
Dest = Pos;
68+
}
69+
70+
sf::Sprite* draw();
71+
std::string GetData();
72+
bool RightClick(float X, float Y);
73+
int Attack(UNIT* Unit);
74+
void Hit();
75+
void Die();
76+
77+
bool Targeted;
78+
sf::Sprite Sprite3;
79+
80+
static int Enemy;
81+
};

0 commit comments

Comments
 (0)