-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameEntity.cpp
More file actions
113 lines (93 loc) · 1.56 KB
/
GameEntity.cpp
File metadata and controls
113 lines (93 loc) · 1.56 KB
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
#include"GameEntity.h"
GameEntity::GameEntity()
{
texScale = 1.0f;
visible = true;
}
void GameEntity::setImage(SDL_Texture* texture)
{
this->texture = texture;
}
void GameEntity::setMove(float px, float py)
{
actSet = true;
if (speedX < 0.0f)
{
speedX *= -1.0f;
}
if (speedY < 0.0f)
{
speedY *= -1.0f;
}
distPosX = px;
distPosY = py;
if (distPosX - pos->x < 0.0f)
{
speedX *= -1.0f;
}
if (distPosY - pos->y < 0.0f)
{
speedY *= -1.0f;
}
}
bool GameEntity::actMove()
{
if (actSet)
{
float moveX, moveY;
if (abs(distPosX - pos->x) < abs(speedX))
{
moveX = 0;
}
else
{
moveX = speedX;
}
if (abs(distPosY - pos->y) < abs(speedY))
{
moveY = 0;
}
else
{
moveY = speedY;
}
setPos(pos->x + moveX, pos->y + moveY);
if (moveX == 0.0f && moveY == 0.0f)
{
actSet = false;
return true;
}
return false;
}
return true;
}
void GameEntity::setTexScale(float texScale)
{
this->texScale = texScale;
}
CollisionBox& GameEntity::getCollisionBox()
{
return collisionBox;
}
bool GameEntity::hitCheck(CollisionBox& oppCollisionBox)
{
return collisionBox.collisionCheck(oppCollisionBox);
}
void GameEntity::drawObjects(SDL_Renderer* gRenderer)
{
if (!visible)
{
return;
}
luaUpdate = actMove();
renderQuad = { (int)pos->x, (int)pos->y,
static_cast<int>(texWidth), static_cast<int>(texHeight)};
//Set clip rendering dimensions
if (clip != nullptr)
{
renderQuad.w = clip->w;
renderQuad.h = clip->h;
}
//Render to screen
SDL_RenderCopyEx(gRenderer, texture, clip, &renderQuad, angle, center, flip);
}