-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboat.cpp
217 lines (178 loc) · 5.64 KB
/
boat.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#include "boat.h"
#include "main.h"
#include <time.h>
#include <unistd.h>
Boat::Boat(float x_cor, float y_cor) {
this->position = glm::vec3(x_cor, y_cor, 2);
this->rotation = 90;
this->cam_view = 1;
this->in_air = 0;
this->speedy = 0;
this->score = 0;
this->health = 300;
this->lives = 3;
this->is_boost = 0;
this->flag = 0;
this->level = 1;
this->points = 0;
color_t colors_boat[] = {
COLOR_1,COLOR_2,COLOR_3,COLOR_1,COLOR_2,COLOR_3,COLOR_1,COLOR_2,COLOR_3,COLOR_1,COLOR_2,COLOR_3,COLOR_1,COLOR_BROWN ,
};
float t = 255.0f;
color_t flag_colors_boat[] = {
COLOR_NAVY,COLOR_YELLOW,COLOR_GREEN,
};
GLfloat vertex_buffer_data[] = {
0.75, 0.2, -0.36 ,
0.75, 0.2, 0.36,
0.75 + 0.3, 0.2, 0,
-0.75, 0, -0.3,
-0.75, 0, 0.3,
-0.75, 0.2, 0.36,
-0.75, 0.2, 0.36,
-0.75, 0, -0.3,
-0.75, 0.2, -0.36,
-0.75, 0, -0.3,
0.75, 0, -0.3,
-0.75, 0.2, -0.36,
-0.75, 0.2, -0.36,
0.75, 0.2, -0.36,
0.75, 0, -0.3,
-0.75, 0, 0.3,
0.75, 0, 0.3,
-0.75, 0.2, 0.36,
-0.75, 0.2, 0.36,
0.75, 0.2, 0.36,
0.75, 0, 0.3,
0.75, 0, -0.3,
1.05 , 0, 0,
0.75, 0.2, -0.36,
0.75, 0.2, -0.36,
1.05 , 0.2, 0,
1.05, 0, 0,
0.75, 0, 0.3,
1.05, 0, 0,
0.75, 0.2, 0.36,
0.75, 0.2, 0.36,
1.05, 0.2, 0,
1.05, 0, 0,
-0.75, 0, -0.3,
-0.75, 0, 0.3,
0.75, 0, 0.3,
-0.75, 0, -0.3,
0.75, 0, -0.3,
0.75, 0, 0.3,
0.75, 0, -0.3,
0.75, 0, 0.3,
1.05, 0, 0,
};
GLfloat colors_data[126];
for(int i=0;i<14;i++) {
colors_data[9*i+0] = float(colors_boat[i].r)/t,colors_data[9*i+1] = float(colors_boat[i].g)/t,colors_data[9*i+2] = float(colors_boat[i].b)/t;
colors_data[9*i+3] = float(colors_boat[i].r)/t,colors_data[9*i+4] = float(colors_boat[i].g)/t,colors_data[9*i+5] = float(colors_boat[i].b)/t;
colors_data[9*i+6] = float(colors_boat[i].r)/t,colors_data[9*i+7] = float(colors_boat[i].g)/t,colors_data[9*i+8] = float(colors_boat[i].b)/t;
};
GLfloat vertex_data1[] = {
0.135, 0, -0.015,
0.135, 0, 0.015,
0.135, 1.0, -0.015,
0.135, 1.0, -0.015,
0.135, 1.0, 0.015,
0.135, 0, 0.015,
0.165, 0, -0.015,
0.165, 0, 0.015,
0.165, 1.0, -0.015,
0.165, 1.0, -0.015,
0.165, 1.0, 0.015,
0.165, 0, 0.015,
0.165, 0, -0.015,
0.135, 0, -0.015,
0.135, 1.0, -0.015,
0.135, 1.0, -0.015,
0.165, 1.0, -0.015,
0.165, 0, -0.015,
0.165, 0, 0.015,
0.135, 0, 0.015,
0.135, 1.0, 0.015,
0.135, 1.0, 0.015,
0.165, 1.0, 0.015,
0.165, 0, 0.015,
0.135, 1.0, -0.015,
0.135, 1.0, 0.015,
0.165, 1.0, 0.015,
0.135, 1.0, -0.015,
0.165, 1.0, 0.015,
0.165, 1.0, -0.015,
};
GLfloat vertex_data2[] = {
0.135, 0.2 , -0.015,
0.135, 1.0, -0.015,
-0.865, 0.2, -0.015,
};
GLfloat flag_color_data[] = {
float(flag_colors_boat[0].r)/t,
float(flag_colors_boat[0].g)/t,
float(flag_colors_boat[0].b)/t,
float(flag_colors_boat[1].r)/t,
float(flag_colors_boat[1].g)/t,
float(flag_colors_boat[1].b)/t,
float(flag_colors_boat[2].r)/t,
float(flag_colors_boat[2].g)/t,
float(flag_colors_boat[2].b)/t,
};
this->object1 = create3DObject(GL_TRIANGLES, 42, vertex_buffer_data, colors_data, GL_FILL);
this->object2 = create3DObject(GL_TRIANGLES, 30, vertex_data1,COLOR_GREEN, GL_FILL);
this->object3 = create3DObject(GL_TRIANGLES, 3, vertex_data2,flag_color_data, GL_FILL);
}
void Boat::draw(glm::mat4 VP) {
Matrices.model = glm::mat4(1.5f);
glm::mat4 translate = glm::translate (this->position); // glTranslatef
glm::mat4 rotate = glm::rotate((float) (this->rotation * M_PI / 180.0f), glm::vec3(0, 1, 0));
Matrices.model *= (translate * rotate);
glm::mat4 MVP = VP * Matrices.model;
glUniformMatrix4fv(Matrices.MatrixID, 1, GL_FALSE, &MVP[0][0]);
draw3DObject(this->object1);
draw3DObject(this->object2);
draw3DObject(this->object3);
}
void Boat::set_position(float x, float y) {
this->position = glm::vec3(x, y, 0);
}
void Boat::tick() {
if(this->in_air)
{
if(this->position.y <= -1)
{
this->position.y = -0.999;
this->in_air = 0;
this->speedy = 0;
}
this->position.y += this->speedy;
this->speedy -= 0.01;
}
}
void Boat::wind_tick(int is_wind, int dir) {
if(is_wind)
{
if(dir){
this->position.x += 0.002;
this->position.z -= 0.002;
this->rotation+= 0.1;
}
else
{
this->position.x -= 0.004;
this->position.z -= 0.004;
this->rotation-= 0.5;
}
}
}
int Boat::get_score() {
int lvl = this->level;
return 25*lvl*(lvl-1) + this->score;
}
bounding_box_t Boat::bounding_box(){
float x = this->position.x, y = this->position.y , z = this->position.z;
bounding_box_t bbox = { x, y, z};
return bbox;
}