-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObject.cpp
More file actions
executable file
·51 lines (45 loc) · 1.07 KB
/
GameObject.cpp
File metadata and controls
executable file
·51 lines (45 loc) · 1.07 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
#include "include/GameObject.hpp"
GameObject::GameObject()
{
dirY = 1;
dirX = 1;
velX = 0;
velY = 0;
}
void GameObject::Init(int x, int y, int width, int height)
{
posX = x;
posY = y;
sizeX = width;
sizeY = height;
}
void GameObject::Update()
{
posX += velX * dirX;
posY += velY * dirY;
}
void GameObject::Render(sf::RenderWindow &window)
{
sf::RectangleShape tile;
tile.setSize(sf::Vector2f(sizeX, sizeY));
tile.setFillColor(sf::Color(0, 0, 255));
tile.setPosition(posX, posY);
window.draw(tile);
}
float GameObject::distanceBetweenObjects(GameObject *otherObject)
{
float dx = static_cast<float>(posX - otherObject->posX);
float dy = static_cast<float>(posY - otherObject->posY);
return sqrt(dx * dx + dy * dy);
}
bool GameObject::Collided(GameObject *otherObject)
{
if (posX < otherObject->posX + otherObject->sizeX &&
posX + sizeX > otherObject->posX &&
posY < otherObject->posY + otherObject->sizeY &&
posY + sizeY > otherObject->posY)
{
return true;
}
return false;
}