-
Notifications
You must be signed in to change notification settings - Fork 0
/
Box.cpp
65 lines (51 loc) · 1.01 KB
/
Box.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
#include "stdafx.h"
#include "Box.h"
Box::Box(int number, int posX, int posY, int width, int height):
number_(number),
width_((float)width),
height_((float)height),
x_(posX),
y_(posY)
{
_sprite.SetPosition((float)posX, (float)posY);
}
void Box::BindMaterial(const Material& material)
{
_material = material;
_sprite.SetImage(*material.GetImage());
sf::Vector2f size = _sprite.GetSize();
float scaleX = width_ / size.x;
float scaleY = height_ / size.y;
_sprite.Scale(scaleX, scaleY);
}
const Material& Box::GetMaterial() const
{
return _material;
}
Material& Box::GetMaterial()
{
return _material;
}
void Box::Render(sf::RenderTarget& rt) const
{
rt.Draw(_sprite);
}
void Box::GetCoordinates(int& x, int& y, float& width, float& height)
{
x = x_;
y = y_;
width = width_;
height = height_;
}
float Box::GetSpeedFactor()
{
return _material.GetSpeedFactor();
}
int Box::GetNumber()
{
return number_;
}
sf::Vector2f Box::GetCenter() const
{
return sf::Vector2f(x_ + width_ / 2.0f, y_ + height_ / 2.0f);
}