-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCamera.cpp
More file actions
74 lines (61 loc) · 1.97 KB
/
Camera.cpp
File metadata and controls
74 lines (61 loc) · 1.97 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
#include "Camera.h"
#include "HealthBar.h"
#include "DodgeBar.h"
Camera::Camera(Hero* hero, sf::View* view, float tieldsWidth, float tieldsHeight, float width, float height)
{
x0 = 0; y0 = 0;
this->hero = hero; this->view = view; this->tieldsWidth = tieldsWidth; this->tieldsHeight = tieldsHeight; this->width = width; this->height = height;
view->setSize(sf::Vector2f(width, height));
view->setCenter(width / 2, height / 2);
healthBar = new HealthBar(view, 0, 0, UtilitiesGame::XY(), UtilitiesGame::SizeXY(tieldsWidth, tieldsHeight));
healthBar->setTrackingHero(hero);
dodgeBar = new DodgeBar(view, 0, 0, UtilitiesGame::XY(width - tieldsWidth, 0), UtilitiesGame::SizeXY(tieldsWidth, tieldsHeight));
dodgeBar->setTrackingHero(hero);
}
void Camera::setCoordinationCamera(float x0, float y0, float width, float height)
{
view->setCenter(hero->getSprite().getPosition().x + hero->getSprite().getLocalBounds().width / 2.0, hero->getSprite().getPosition().y + hero->getSprite().getLocalBounds().height / 2.0);
if (view->getCenter().x - view->getSize().x / 2 < x0)
{
view->setCenter(x0 + view->getSize().x / 2, view->getCenter().y);
}
if (view->getCenter().x + view->getSize().x / 2 > x0 + width)
{
view->setCenter(x0 + width - view->getSize().x / 2, view->getCenter().y);
}
if (view->getCenter().y - view->getSize().y / 2 < y0)
{
view->setCenter(view->getCenter().x, y0 + view->getSize().y / 2);
}
if (view->getCenter().y + view->getSize().y / 2 > y0 + height)
{
view->setCenter(view->getCenter().x, y0 + height - view->getSize().y / 2);
}
}
const sf::View* Camera::getView()
{
return view;
}
void Camera::setHero(Hero* hero)
{
this->hero = hero;
}
void Camera::setView(sf::View* view)
{
this->view = view;
healthBar->setView(view);
}
HealthBar* Camera::getHPProgressBar()
{
return healthBar;
}
DodgeBar* Camera::getDodgeProgressBar()
{
return dodgeBar;
}
void Camera::update()
{
healthBar->update();
dodgeBar->update();
setCoordinationCamera(0, 0, width, height);
}