-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScenar7.class.cpp
155 lines (140 loc) · 4.09 KB
/
Scenar7.class.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Scenar7.class.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vjacquie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/01/27 17:13:25 by vjacquie #+# #+# */
/* Updated: 2015/01/29 13:29:37 by vjacquie ### ########.fr */
/* */
/* ************************************************************************** */
#include "Scenar7.class.hpp"
Scenar7::Scenar7() {
this->d = getData();
this->d->toShow = this->d->map2d;
}
Scenar7::Scenar7( Scenar7 const & rSource ) {
*this = rSource;
}
Scenar7 & Scenar7::operator=( Scenar7 const & rSource ) {
if ( this != &rSource ) {
this->d = rSource.d;
}
return *this;
}
Scenar7::~Scenar7() {}
void Scenar7::go( void ) {
int y = 0;
int x;
float xResult;
float yResult;
float color[3];
glBegin(GL_POINTS);
while ( y < TAB_SIZE ) {
x = 0;
while ( x < TAB_SIZE ) {
ft42::hillColor_toShow( d, y, x );
x++;
}
y++;
}
glEnd();
ft42::oceanBorder();
}
int Scenar7::Clamp(int x, int min, int max) {
if (x < min)
x = min;
else if (x > max)
x = max;
return (x);
}
void Scenar7::rUpWater(t_data * d, int z, int y, int x, bool line) {
int tmp = 0;
int tmp1 = 0;
int tmp2 = 0;
int tmp3 = 0;
short int dir = 0;
if (d->map2d[y][x].z - d->z >= -2) {
d->map2d[y][x].z = d->z;
}
else {
d->NeedUp += 1;
d->map2d[y][x].z++;
}
d->map2d[y][x].type = WATER;
if (d->map2d[y][x].upWater == 0) {
if (x + 1 < TAB_SIZE && d->map2d[y][x + 1].z < d->map2d[y][x].z)
dir = 1;
else if (x - 1 >= 0 && d->map2d[y][x - 1].z < d->map2d[y][x].z)
dir = 2;
else if (y + 1 < TAB_SIZE && d->map2d[y + 1][x].z < d->map2d[y][x].z)// || (y + 2 < TAB_SIZE && d->map2d[y + 2][x].z < d->map2d[y][x].z))
dir = 3;
else if (y - 1 >= 0 && d->map2d[y - 1][x].z < d->map2d[y][x].z)// || (y - 2 > 0 && d->map2d[y - 2][x].z < d->map2d[y][x].z))
dir = 4;
if ( dir == 1 && x + 1 < TAB_SIZE && d->map2d[y][x + 1].type != WATER && d->map2d[y][x + 1].z < d->map2d[y][x].z ) {
d->NeedUp += 1;
d->map2d[y][x + 1].type = WATER;
}
if ( dir == 2 && x - 1 >= 0 && d->map2d[y][x - 1].type != WATER && d->map2d[y][x - 1].z < d->map2d[y][x].z) {
d->NeedUp += 1;
d->map2d[y][x - 1].type = WATER;
d->map2d[y][x - 1].upWater = 1;
}
if ( dir == 3 && y + 1 < TAB_SIZE && d->map2d[y + 1][x].type != WATER && d->map2d[y + 1][x].z < d->map2d[y][x].z &&(x - 1 < 0 || d->map2d[y + 1][x - 1].type != WATER)) {
d->NeedUp += 1;
d->map2d[y + 1][x].type = WATER;
d->map2d[y + 1][x].upWater = 1;
}
if ( dir == 4 && y - 1 >= 0 && d->map2d[y - 1][x].type != WATER && d->map2d[y - 1][x].z < d->map2d[y][x].z && (x - 1 < 0 || d->map2d[y - 1][x - 1].type != WATER)) {
d->NeedUp += 1;
d->map2d[y - 1][x].type = WATER;
d->map2d[y - 1][x].upWater = 1;
}
}
else {
d->map2d[y][x].upWater = 0;
}
if (line == true) {
x--;
while (x >= 0 && d->map2d[y][x].type != WATER) {
x--;
}
if (x >= 0)
rUpWater(d, d->map2d[y][x].z, y, x, true);
}
}
void Scenar7::upWater( void ) {
int y = 0;
int x;
if ( this->d->NeedUp < WATERFLUX_6 ) {
this->d->z++;
}
this->d->NeedUp = 0;
while ( y < TAB_SIZE ) {
x = TAB_SIZE;
while ( x >= 0 && this->d->map2d[y][x].type != WATER ) {
x--;
}
rUpWater(this->d, this->d->map2d[y][x].z, y, x, true);
y++;
}
}
void Scenar7::InitWater( void ) {
static bool called = false;
if (called == false)
called = true;
else
return ;
int y = 0;
while ( y < TAB_SIZE ) {
if ( this->d->map2d[y][0].type != HILL ) {
this->d->map2d[y][0].type = WATER;
this->d->map2d[y][0].z = 0;
}
y++;
}
this->d->z = 1;
this->d->Water = 0;
this->d->NeedUp = 0;
}