-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameview.cpp
More file actions
54 lines (43 loc) · 1.76 KB
/
Copy pathgameview.cpp
File metadata and controls
54 lines (43 loc) · 1.76 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
#include "gameview.h"
#include "ScreenObject.h"
#include "Background.h"
#include <iostream>
#include "ScreenRoot.h"
GameView gameView(0, 0, 3000, 2000);
GameView::GameView(int upperLeftX, int upperLeftY, int lowerRightX, int lowerRightY)
{
sizeOfViewCenter = 1000;
view.reset(sf::FloatRect(upperLeftX, upperLeftY, lowerRightX, lowerRightY));
}
void GameView::followProtagonist(Protagonist &prot)
{
if (prot.getXValue() < view.getCenter().x - sizeOfViewCenter/2) //if out of view center in left
{
int newCenterX = prot.getXValue() + sizeOfViewCenter/2;
if(ScreenRoot::access().background) //if there is a background
ScreenRoot::access().background ->followScreen(newCenterX - view.getCenter().x); //move the background
view.setCenter(newCenterX, view.getCenter().y);
ScreenRoot::access().window->setView(view);
}
else if (prot.getXValue() > view.getCenter().x + sizeOfViewCenter/2 - prot.getWidth()) //if out of view center in right
{
int newCenterX = prot.getXValue() - sizeOfViewCenter/2 + prot.getWidth();
if(ScreenRoot::access().background) //if there is a background
ScreenRoot::access().background ->followScreen(newCenterX - view.getCenter().x); //move the background
view.setCenter(newCenterX, view.getCenter().y);
ScreenRoot::access().window->setView(view);
}
///Y axis case to come
}
int getViewLeftBorder()
{
return gameView.view.getCenter().x - gameView.view.getSize().x / 2;
}
int getViewRightBorder()
{
return gameView.view.getCenter().x + gameView.view.getSize().x / 2;
}
bool xInView (int x)
{
return (x > getViewLeftBorder() && x < getViewRightBorder());
}