-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorldObject.cpp
More file actions
57 lines (44 loc) · 1.38 KB
/
WorldObject.cpp
File metadata and controls
57 lines (44 loc) · 1.38 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
#include "WorldObject.h"
WorldObject::WorldObject(int x, int y, int vx, int vy, int width, int height, Uint8 r, Uint8 g, Uint8 b, WorldObjectType objectType)
: x(x), y(y), vx(vx), vy(vy), width(width), height(height), color({ r, g, b }), objectType(objectType), movable(vx != 0 && vy != 0) {}
int WorldObject::getX() const {
return x;
}
int WorldObject::getY() const {
return y;
}
int WorldObject::getVx() const {
return vx;
}
int WorldObject::getVy() const {
return vy;
}
void WorldObject::setVx(int newVx) {
vx = newVx;
}
void WorldObject::setVy(int newVy) {
vy = newVy;
}
int WorldObject::getWidth() const {
return width;
};
int WorldObject::getHeight() const {
return height;
};
void WorldObject::render(SDL_Renderer* renderer) {
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
SDL_Rect rect = { x, y, width, height };
SDL_RenderFillRect(renderer, &rect);
}
bool WorldObject::checkBoundaryCollision() const {
return x < 0 || x + width > SCREEN_WIDTH || y < 0 || y + height > SCREEN_HEIGHT;
}
WorldObjectType WorldObject::getObjectType() const {
return objectType;
}
bool WorldObject::collidesWith(std::shared_ptr<WorldObject> otherObject, int xPos, int yPos, int dx, int dy) {
return xPos < x + dx + width && xPos > x + dx && yPos < y + dy + height && yPos > y + dy;
}
bool WorldObject::isMovable() {
return movable;
}