-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackgroundstage3.cpp
More file actions
88 lines (70 loc) · 3.61 KB
/
backgroundstage3.cpp
File metadata and controls
88 lines (70 loc) · 3.61 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "backgroundstage3.h"
BackgroundStage3::BackgroundStage3(Coordinate main_coordinate):
Background (main_coordinate),
first_coordinate(main_coordinate),
second_coordinate(main_coordinate),
third_coordinate(main_coordinate) {
}
BackgroundStage3::~BackgroundStage3() = default;
void BackgroundStage3::render(QPainter& painter, bool paused) {
Coordinate first_coordinate_wrap(first_coordinate.getXCoordinate() + (100 + Config::config()->getWorldWidth()),
first_coordinate.getYCoordinate(),
first_coordinate.getFrameHeight(),
first_coordinate.getFrameWidth());
int loading_gap = 0;
if (Config::config()->getBackgroundNumber() == 2) {
loading_gap = 100;
}
Coordinate second_coordinate_wrap(second_coordinate.getXCoordinate() + (loading_gap + Config::config()->getWorldWidth()),
second_coordinate.getYCoordinate(),
second_coordinate.getFrameHeight(),
second_coordinate.getFrameWidth());
Coordinate third_coordinate_wrap(third_coordinate.getXCoordinate() + Config::config()->getWorldWidth(),
third_coordinate.getYCoordinate(),
third_coordinate.getFrameHeight(),
third_coordinate.getFrameWidth());
if (first_coordinate.getQtRenderingXCoordinate() < 0 - getFirst().width()) {
first_coordinate.setXCoordinateToZero(100);
}
if (Config::config()->getBackgroundNumber() == 2) {
if (second_coordinate.getQtRenderingXCoordinate() > Config::config()->getWorldWidth()) {
second_coordinate.setXCoordinateToZero(-100);
}
} else {
if (second_coordinate.getQtRenderingXCoordinate() < 0 - getSecond().width()) {
second_coordinate.setXCoordinateToZero(0);
}
}
painter.drawPixmap(first_coordinate.getQtRenderingXCoordinate(),
first_coordinate.getQtRenderingYCoordinate(),
getFirst());
painter.drawPixmap(first_coordinate_wrap.getQtRenderingXCoordinate(),
first_coordinate_wrap.getQtRenderingYCoordinate(),
getFirst());
painter.drawPixmap(second_coordinate.getQtRenderingXCoordinate(),
second_coordinate.getQtRenderingYCoordinate(),
getSecond());
painter.drawPixmap(second_coordinate_wrap.getQtRenderingXCoordinate(),
second_coordinate_wrap.getQtRenderingYCoordinate(),
getSecond());
int width = getThird().width();
int height = getThird().height();
// Calculate the x coordinate to start tiling the image from.
int start_x = int(third_coordinate_wrap.getQtRenderingXCoordinate()) % width - width;
// Tile multiple copies of the image to fill the screen.
for (int x = start_x; x < painter.device()->width(); x += width) {
for (int y = 0; y < painter.device()->height(); y += height) {
painter.drawPixmap(x, y, getThird());
}
}
//If it isn't in pause, then adjust the position of all the components.
if (!paused) {
first_coordinate.changeInXCoordinate(-0.2);
if (Config::config()->getBackgroundNumber() == 2) {
second_coordinate.changeInXCoordinate(0.5);
} else {
second_coordinate.changeInXCoordinate(-0.3);
}
third_coordinate.changeInXCoordinate(-Config::config()->getStickman()->getVelocity());
}
}