-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObject.cpp
More file actions
75 lines (53 loc) · 1.49 KB
/
Copy pathGameObject.cpp
File metadata and controls
75 lines (53 loc) · 1.49 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
#include "GameObject.h"
#include "TextureManager.h"
GameObject::GameObject(const char* textureSheet, SDL_Renderer* rend, Vector2D vec, int srcW, int srcH, int scale, std::string n) {
renderer = rend;
objTexture = TextureManager::loadTexture(textureSheet, rend);
pos = vec;
dimensions.x = srcW * scale;
dimensions.y = srcH * scale;
srcRect.w = srcW;
srcRect.h = srcH;
srcRect.x = srcRect.y = 0;
dstRect.w = srcRect.w * scale;
dstRect.h = srcRect.h * scale;
name = n;
//std::cout << "GameObject " << name << " created" << std::endl;
}
GameObject::GameObject(const char* textureSheet, SDL_Renderer* rend, int xpos, int ypos, int srcW, int srcH, int scale, std::string n) {
renderer = rend;
objTexture = TextureManager::loadTexture(textureSheet, rend);
pos.x = xpos;
pos.y = ypos;
dimensions.x = srcW * scale;
dimensions.y = srcH * scale;
srcRect.w = srcW;
srcRect.h = srcH;
srcRect.x = srcRect.y = 0;
dstRect.w = srcRect.w * scale;
dstRect.h = srcRect.h * scale;
name = n;
//std::cout << "GameObject " << name << " created" << std::endl;
}
GameObject::~GameObject() {
SDL_DestroyTexture(objTexture);
}
void GameObject::setPos(Vector2D newPos) {
pos = newPos;
}
Vector2D GameObject::getPos() {
return pos;
}
Vector2D GameObject::getDimensions() {
return dimensions;
}
void GameObject::update() {
dstRect.x = pos.x;
dstRect.y = pos.y;
}
void GameObject::render() {
SDL_RenderCopy(renderer, objTexture, &srcRect, &dstRect);
}
std::string GameObject::getName() {
return name;
}