-
Notifications
You must be signed in to change notification settings - Fork 9
/
DrawableEntity.cpp
80 lines (75 loc) · 1.67 KB
/
DrawableEntity.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
#include "DrawableEntity.h"
#include "ResourceController.h"
DrawableEntity::DrawableEntity()
{
x = 0;
y = 0;
targetRect = new SDL_Rect();
entityTex = NULL;
isDraggable = true;
}
DrawableEntity::DrawableEntity(GAME_TEX obj)
{
x = 0;
y = 0;
targetRect = new SDL_Rect();
SDL_Texture* t = ResourceController::getResource(obj);
entityTex = t;
tex = obj;
isDraggable = true;
}
DrawableEntity::DrawableEntity(int x, int y, GAME_TEX obj)
{
this->x = x;
this->y = y;
targetRect = new SDL_Rect();
calculateRenderPositionFromCoordinate(x, y, targetRect);
SDL_Texture* t = ResourceController::getResource(obj);
entityTex = t;
tex = obj;
isDraggable = true;
}
DrawableEntity::DrawableEntity(int x, int y, GAME_TEX obj, bool isDraggable)
{
this->x = x;
this->y = y;
this->isDraggable = isDraggable;
targetRect = new SDL_Rect();
calculateRenderPositionFromCoordinate(x, y, targetRect);
SDL_Texture* t = ResourceController::getResource(obj);
entityTex = t;
tex = obj;
isDraggable = true;
}
void DrawableEntity::render(SDL_Renderer* renderer)
{
if (entityTex != NULL)
{
SDL_RenderCopyEx(renderer, entityTex, NULL, isDraggable ? targetRect : NULL, 0.0, NULL, SDL_FLIP_NONE);
}
}
SDL_Rect* const DrawableEntity::getTargetRect() const { return targetRect; }
void DrawableEntity::recalculatePosition()
{
calculateRenderPositionFromCoordinate(x, y, targetRect);
}
void DrawableEntity::setTargetRectW(int w)
{
targetRect->w = w;
}
void DrawableEntity::setTargetRectH(int h)
{
targetRect->h = h;
}
void DrawableEntity::setTargetRectX(int x){
if (targetRect != NULL)
{
targetRect->x = x;
}
}
void DrawableEntity::setTargetRectY(int y){
if (targetRect != NULL)
{
targetRect->y = y;
}
}