-
Notifications
You must be signed in to change notification settings - Fork 0
/
parallax.cpp
107 lines (82 loc) · 1.63 KB
/
parallax.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
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
97
98
99
100
101
102
103
104
105
106
107
#include "parallax.h"
parallax::parallax()
{
paraX=0;
paraY=0;
paraX2=-799;
paraY2=0;
paraVelX=0;
parallaxRect1.x = paraX;
parallaxRect1.y = paraY;
parallaxRect1.w = PARALLAX_WIDTH;
parallaxRect1.h = PARALLAX_HEIGHT;
parallaxRect2.x = paraX2;
parallaxRect2.y = paraY2;
parallaxRect2.w = PARALLAX_WIDTH;
parallaxRect2.h = PARALLAX_HEIGHT;
}
parallax::~parallax(){
parallaxTexture.free();
}
void parallax::incrementFore(){
paraX+=4;
paraX2+=4;
updateRects();
resetParallax();
}
void parallax::incrementAnteriorMid(){
paraX+=3;
paraX2+=3;
updateRects();
resetParallax();
}
void parallax::incrementMid(){
paraX+=2;
paraX2+=2;
updateRects();
resetParallax();
}
void parallax::incrementBack(){
paraX+=1;
paraX2+=1;
updateRects();
resetParallax();
}
void parallax::specialIncrementFore(){
paraX+=4;
// paraX2+=4;
updateRects();
specialResetParallax();
}
void parallax::resetParallax()
{
if(paraX > 799){
paraX = -799;
}
if(paraX2 > 799){
paraX2 = -799;
}
}
void parallax::specialResetParallax()
{
if(paraX>799){
paraX=-1599;
}
/*
if(paraX2>799){
paraX2=-1599;
}*/
}
void parallax::updateRects()
{
parallaxRect1.x=paraX;
parallaxRect2.x=paraX2;
}
void parallax::parallaxRender(SDL_Renderer* renderer)
{
parallaxTexture.render(parallaxRect1.x,0,NULL,0.0,NULL,SDL_FLIP_NONE,renderer);
parallaxTexture.render(parallaxRect2.x,0,NULL,0.0,NULL,SDL_FLIP_NONE,renderer);
}
void parallax::freeParallaxTexture(){
parallaxTexture.free();
}