-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackground.h
96 lines (85 loc) · 2.83 KB
/
Background.h
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
89
90
91
92
93
94
95
96
#ifndef BACKGROUND_H
#define BACKGROUND_H
#include <QPainter>
#include <QPixmap>
/**
* Abstract class for the Background product.
*
* In order to achieve seamless, cyclic parallax background scrolling, each background object
* requies 2 identical images to be rendered together (initially, one is placed at x-coord 0,
* and the other at x-coord 'width' (this is the width of the background; see below).
* When bg1's pos becomes < 0-width, then it needs to move to bg2's pos+width (and vice-versa
* for bg2 and bg1).
*/
// DIALOG WINDOW
// +---------------------+
// |+--------------------|----------------------------------+
// || | | |
// || bg1 | | bg2 |
// || | | |
// |+--------------------|----------------------------------+
// +---------------------+
class Background {
public:
/**
* @brief Basic Background constructor
* @param img - source image of background (retrieved from resources.qrc)
* @param width - width of background image (pixels)
* @note bg1's x-coord is set to 0, and bg2's set to width.
*/
Background(QPixmap img, int width)
: m_img(img), m_width(width), m_bg1XCoord(0), m_bg2XCoord(width) {}
/**
* @brief Background destructor (no member variables on heap, so no need for deletes)
*/
virtual ~Background() {}
/**
* Basic getters and setters for member variables.
*/
const QPixmap& getImg() const {
return m_img;
}
int getWidth() const {
return m_width;
}
int getBG1XCoord() const {
return m_bg1XCoord;
}
int getBG2XCoord() const {
return m_bg2XCoord;
}
void setBG1XCoord(int x) {
m_bg1XCoord = x;
}
void setBG2XCoord(int x) {
m_bg2XCoord = x;
}
/**
* @brief Moves the position of background 1 (to the left) by passed value
* @param x - amount to move the background (to the left of the screen)
*/
void shiftBackground1(int x) {
m_bg1XCoord -= x;
}
/**
* @brief Moves the position of background 2 (to the left) by passed value
* @param x - amount to move the background (to the left of the screen)
*/
void shiftBackground2(int x) {
m_bg2XCoord -= x;
}
/**
* @brief Pure virtual method for rendering the background into the Dialog window
* @param painter - passed QPainter from Dialog.cpp
* @see Dialog::paintEvent()
* @param stickmanVelocity - current velocity of the stickman (dictates magnitude of background movement)
*/
virtual void render(QPainter& painter, int stickmanVelocity) = 0;
protected:
QPixmap const m_img;
int const m_width;
int m_xCoord;
int m_bg1XCoord;
int m_bg2XCoord;
};
#endif // BACKGROUND_H