Recebi alguns e-mails solicitando uma forma mais fácil do código para o jogo Street Frog. Abaixo estarei mostrando o código com apenas um carro, o sapo, o prédio, e seus movimentos.

Clique aqui para aprender como compilar o jogo.

Clique abaixo para baixar o código:

http://www.thiagomedeiros.com/publico/uploaded/frog_simples.zip

Usar o Dev C++ para compilar.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
Name: Street Frog
Copyright: 2008 Thiago Medeiros
Author: Thiago Medeiros Cavalcanti Sant' Anna
Date: 10/11/08 23:05
Description: Baseado no jogo de atari no qual o sapo tem que atravessar a avenida.
*/
 
#include "glut.h" //Janelas etc...
//Declaracoes das variaveis
GLint movercarro=0;
GLint moversapox=0;
GLint moversapoy=0;
GLint predioy=0;
GLint tempo=0;
GLint lado=0;

Ver o resto do código:

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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
//Desenha a pista
void Pista ()
{
glColor3f(1,1,1);
glLineWidth(3);
glBegin(GL_LINES);
glVertex2i(1,1);
glVertex2i(29,1);
glVertex2i(1,7);
glVertex2i(29,7);
glEnd();
 
glColor3f(1,1,1);
glLineWidth(2);
glBegin(GL_LINES);
glVertex2i(2,3);
glVertex2i(6,3);
glVertex2i(10,3);
glVertex2i(14,3);
glVertex2i(18,3);
glVertex2i(22,3);
glVertex2i(26,3);
glVertex2i(29,3);
glVertex2i(2,5);
glVertex2i(6,5);
glVertex2i(10,5);
glVertex2i(14,5);
glVertex2i(18,5);
glVertex2i(22,5);
glVertex2i(26,5);
glVertex2i(29,5);
glEnd();
 
glColor3f(0,0.5,0);
//Gramado
glBegin(GL_QUADS);
glVertex2f(1.0, 0.0);
glVertex2f(1.0, 0.8);
glVertex2f(29.0, 0.8);
glVertex2f(29.0, 0.0);
glEnd();
 
glColor3f(0,0.5,0);
//Gramado
glBegin(GL_QUADS);
glVertex2f(1.0, 7.2);
glVertex2f(1.0, 8.0);
glVertex2f(29.0, 8.0);
glVertex2f(29.0, 7.2);
glEnd();
}
 
//Desenha o sapo
void Sapo ()
{
glColor3f(0,1,0);
glPointSize(20.0);
glBegin(GL_POINTS);
glVertex2f (moversapox+15,moversapoy+1);
glEnd();
 
glColor3f(1,1,0);
glPointSize(3.0);
glBegin(GL_POINTS);
glVertex2f (moversapox+14.8,moversapoy+1.2);  //Olho esquerdo
glVertex2f (moversapox+15.2,moversapoy+1.2);  //Olho direito
glEnd();
 
//Desenha as pernas
glColor3f(0,1,0);
glLineWidth(2);
glBegin(GL_LINES);
glVertex2f(moversapox+14.3,moversapoy+1.3);
glVertex2f(moversapox+14.8,moversapoy+1.1);
glVertex2f(moversapox+15.7,moversapoy+1.3);
glVertex2f(moversapox+15.2,moversapoy+1.1);
glVertex2f(moversapox+14.8,moversapoy+0.9);
glVertex2f(moversapox+14.3,moversapoy+0.7);
glVertex2f(moversapox+15.7,moversapoy+0.7);
glVertex2f(moversapox+15.2,moversapoy+0.9);
glEnd();
 
//Ponto das maos
glColor3f(0,1,0);
glPointSize(1.0);
glBegin(GL_POINTS);
glVertex2f (moversapox+14.3,moversapoy+1.15);
glVertex2f (moversapox+15.7,moversapoy+1.15);
glVertex2f (moversapox+14.2,moversapoy+1.3);
glVertex2f (moversapox+15.8,moversapoy+1.3);
glVertex2f (moversapox+14.4,moversapoy+1.4);
glVertex2f (moversapox+15.6,moversapoy+1.4);
glEnd();
}
 
//Desenha o predio
void Predio ()
{
glColor3f(1,1,1);
glBegin(GL_QUADS);
glVertex2f (1,8);
glVertex2f (1,predioy+10);
glVertex2f (6,predioy+10);
glVertex2f (6,8);
glEnd();
 
//Janela Esquerda
glColor3f(0,0,0);
glLineWidth(2);
glBegin(GL_LINES);
glVertex2f (2,9.3);
glVertex2f (3,9.3);
glVertex2f (2,9.8);
glVertex2f (3,9.8);
glVertex2f (2,9.3);
glVertex2f (2,9.8);
glVertex2f (3,9.3);
glVertex2f (3,9.8);
glEnd();
 
//Janela Direita
glColor3f(0,0,0);
glLineWidth(2);
glBegin(GL_LINES);
glVertex2f (4,9.3);
glVertex2f (5,9.3);
glVertex2f (4,9.8);
glVertex2f (5,9.8);
glVertex2f (4,9.3);
glVertex2f (4,9.8);
glVertex2f (5,9.3);
glVertex2f (5,9.8);
 
//Janela Esquerda Escondida
glColor3f(0,0,0);
glLineWidth(2);
glBegin(GL_LINES);
glVertex2f (2,10.3);
glVertex2f (3,10.3);
glVertex2f (2,10.8);
glVertex2f (3,10.8);
glVertex2f (2,10.3);
glVertex2f (2,10.8);
glVertex2f (3,10.3);
glVertex2f (3,10.8);
glEnd();
 
//Janela Direita Escondida
glColor3f(0,0,0);
glLineWidth(2);
glBegin(GL_LINES);
glVertex2f (4,10.3);
glVertex2f (5,10.3);
glVertex2f (4,10.8);
glVertex2f (5,10.8);
glVertex2f (4,10.3);
glVertex2f (4,10.8);
glVertex2f (5,10.3);
glVertex2f (5,10.8);
glEnd();
 
//Janela Esquerda Escondida
glColor3f(0,0,0);
glLineWidth(2);
glBegin(GL_LINES);
glVertex2f (2,11.3);
glVertex2f (3,11.3);
glVertex2f (2,11.8);
glVertex2f (3,11.8);
glVertex2f (2,11.3);
glVertex2f (2,11.8);
glVertex2f (3,11.3);
glVertex2f (3,11.8);
glEnd();
 
//Janela Direita Escondida
glColor3f(0,0,0);
glLineWidth(2);
glBegin(GL_LINES);
glVertex2f (4,11.3);
glVertex2f (5,11.3);
glVertex2f (4,11.8);
glVertex2f (5,11.8);
glVertex2f (4,11.3);
glVertex2f (4,11.8);
glVertex2f (5,11.3);
glVertex2f (5,11.8);
glEnd();
}
 
//Desenha o caminhao
void Caminhao ()
 
{
glColor3f(0.5,1,0);
glBegin(GL_QUADS);
glVertex2f (movercarro+2,3.5);
glVertex2f (movercarro+2,4.5);
glVertex2f (movercarro+4,4.5);
glVertex2f (movercarro+4,3.5);
glEnd();
glBegin(GL_QUADS);
glVertex2f (movercarro+1,3.5);
glVertex2f (movercarro+1,4.0);
glVertex2f (movercarro+2,4.0);
glVertex2f (movercarro+2,3.5);
glEnd();
glPointSize(5.0);
glBegin(GL_POINTS);
glColor3f(0.5,0.5,0.5);
glVertex2f (movercarro+1.5,3.5);
glVertex2f (movercarro+3.5,3.5);
glEnd();
}
 
//Movimentação automatica apenas ir
void movimentacarro(int passo) //Carro verde (Caminhao)
{
{
movercarro -= 4; //carro anda de -4 em -4 na tela.. ou seja pra esquerda..
if(movercarro == -8) // se o carro tocar  a tela em -8
{
movercarro = 36; //carro reaparece em 36 na tela (lado direito da tela)
}
glutPostRedisplay(); //redesenhe o carro
glutTimerFunc(100-tempo,movimentacarro, 1); //timer de tempo pra ajustar a velocidade de movimento do carro
}
}
 
//Caso o carro passe por cima do sapo, retornar ao inicio
void Colisao ()
{
//obs: Porque 4 linhas de colisao? Simples, o carro anda de -4 em -4, se vc tiver no ponto x= 3, não iria acontecer
// a colisao, ou seja, +1, +2, +3 foi uma forma de corrigir esse erro. (x=3 +1...
 
if ((movercarro-10 == moversapox+1) && (4 == moversapoy+1)) moversapoy = 0;
// se movercarro-10 igual a valor x do sapo +1 e o valor da altura do sapo em y igual a 4 (altura da linha do carro,
// sapo vai para o inicio
if ((movercarro-10 == moversapox+2) && (4 == moversapoy+1)) moversapoy = 0;
if ((movercarro-10 == moversapox+3) && (4 == moversapoy+1)) moversapoy = 0;
if ((movercarro-10 == moversapox+4) && (4 == moversapoy+1)) moversapoy = 0;
 
if ((7 == moversapoy+1) && (lado == 0)) lado = 1;  //Mudanca de lado
 
glutPostRedisplay();
}
 
//Comentario final
void Comentarios ()
{
 
{
glColor3f(1,1,1);
glRasterPos2f(9.2, 6.0);
char* p = (char*) "Parabens!! Voce Ganhou!!";
while (*p != '\0')
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *p++);
}
}
}
 
//Chama o desenho
void Desenha(void)
{
 
if(lado == 0)
{
tempo = 40;  //Inicio
glClear(GL_COLOR_BUFFER_BIT);
Pista();
Colisao();
Caminhao();
Sapo();
Predio();
glutSwapBuffers();
}
 
if(lado == 1) //Final
{
glClear(GL_COLOR_BUFFER_BIT);
Comentarios();
glutSwapBuffers();
}
 
}
 
//Funcoes para teclado (atribuicoes de teclas especiais)
void Mover (int key, int x, int y)
{
if(key == GLUT_KEY_UP)      { moversapoy += 1; }
if(key == GLUT_KEY_DOWN)    { moversapoy -= 1; }
if(key == GLUT_KEY_LEFT)    { moversapox -= 1; }
if(key == GLUT_KEY_RIGHT)   { moversapox += 1; }
 
//Limitando o sapo, para nao sair da tela
if (moversapoy < 0)   		 { moversapoy = 0;  }
if (moversapoy > 6)         { moversapoy = 6;  }
if (moversapox < -13)       { moversapox = -13;}
if (moversapox > 13)        { moversapox = 13; }
}
 
//Funcoes para teclado (atribuicoes de teclas)
void Teclado ( unsigned char key, int x, int y )
{
//Fazer o predio subir e descer com W e S
if(key == 119)        { predioy += 1; }
if(key == 115)        { predioy -= 1; }
//Limites minimo e maximo do predio
if (predioy < 0)      { predioy = 0;  }
if (predioy > 2)      { predioy = 2;  }
//Tela cheia na tecla f
if(key == 102)        { glutFullScreen(); }
//Redesenha o novo valor
glutPostRedisplay();
//Sai ao se precionar a tecla esc
if(key == 27)  {   exit(0); }
}
 
//Define configuracoes da janela
void Inicializa (void)
{
// Define a cor de fundo da janela de visualização como preta
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,30.0,0.0,15.0);
}
 
//Chamada do main
int main(void)
{
//E por fim a chamada para o OpenGL
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); //Modo para nao exibir rastros na tela
glutInitWindowSize (690, 530); //Tamanho da janela
glutInitWindowPosition (50, 50);  //Localizacao inicial da janela
glutCreateWindow("Street Frog"); //Nome da janela
glutKeyboardFunc(Teclado); //Chama as funcoes do teclado
glutSpecialFunc(Mover);  //Chama as funcoes especias do teclado (setas de movimento)
Inicializa(); //Define cor de fundo da janela, largura e altura
glutDisplayFunc(Desenha); //Chama o desenho
glutTimerFunc(10,movimentacarro,1);   //Chamada de movimento do carro
glutMainLoop();
//Final das funcoes do OpenGL
 
}