-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWeapon.cpp
120 lines (96 loc) · 2.63 KB
/
Weapon.cpp
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
#include "Weapon.h"
//=============================================================================
Weapon::Weapon()
{
onHitTime = 0;
damage = 10;
range = 0;
speed = 0;
canHit = false;
used = false;
X = 0;
Y = 0;
Type = ENTITY_TYPE_WEAPON;
Flags = ENTITY_FLAG_MAPONLY | ENTITY_FLAG_GRAVITY;
hitTimer = 100;
}
Weapon::~Weapon()
{
OnCleanup();
}
//=============================================================================
//bool Weapon::OnLoad(char* File, int Width, int Height, int MaxFrames)
bool Weapon::OnLoad(char* File, int Width, int Height)
{
if(CEntity::OnLoad(File, Width, Height, 1) == false)
{
return false;
}
this->Width = Width;
this->Height = Height;
range = Width;
speed = 2;
return true;
}
//-----------------------------------------------------------------------------
void Weapon::OnLoop(float playerX, float playerY)
{
if(used)
{
Flags = ENTITY_FLAG_GHOST;
if(SDL_GetTicks() - onHitTime > hitTimer)
{
canHit = false;
}
}
CEntity::OnLoop(X, Y);
}
//-----------------------------------------------------------------------------
void Weapon::OnRender(SDL_Surface* Surf_Display)
{
if(Surf_Entity == NULL || Surf_Display == NULL) return;
CSurface::OnDraw(Surf_Display, Surf_Entity, X - CCamera::CameraControl.GetX(), Y - CCamera::CameraControl.GetY(), CurrentFrameCol * Width, CurrentFrameRow * Height, Width, Height);
}
//------------------------------------------------------------------------------
void Weapon::OnCleanup()
{
CEntity::OnCleanup();
}
//------------------------------------------------------------------------------
void Weapon::OnAnimate()
{
CEntity::OnAnimate();
}
//------------------------------------------------------------------------------
bool Weapon::OnCollision(CEntity* Entity)
{
if((canHit == true) && Owner != Entity)
{
Entity->health -= damage;
Entity->KnockBack();
Flags = ENTITY_FLAG_MAPONLY;
canHit = false;
}
return true;
}
//------------------------------------------------------------------------------
void Weapon::DoDamage()
{
canHit = true;
Flags = ENTITY_FLAG_MAPONLY;
onHitTime = SDL_GetTicks();
}
//------------------------------------------------------------------------------
void Weapon::SetOwner(CEntity* Entity)
{
Owner = Entity;
used = true;
}
//------------------------------------------------------------------------------
void Weapon::OnDrop()
{
Owner = NULL;
used = false;
Flags = ENTITY_FLAG_GRAVITY | ENTITY_FLAG_MAPONLY;
//KnockBack();
}