-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
310 lines (248 loc) · 12.7 KB
/
index.html
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
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
<head>
<title>Jogo com WebGL</title>
<link rel="apple-touch-icon" sizes="180x180" href="favicon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
<link rel="manifest" href="favicon/site.webmanifest">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/11.8.2/math.js"></script>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css">
<link rel="stylesheet" href="style.css">
<script src="game/index.js"></script>
<script id="vertex-shader" type="notjs">
// attribute -> muda para cada vértice
attribute vec4 position;
attribute vec2 texCoord;
uniform mat4 transfproj;
//uniform mat4 transf;
varying vec2 v_texCoord;
attribute vec3 normal;
varying vec3 v_normal;
uniform vec3 lightpos;
varying vec3 pointToLight;
uniform vec3 campos;
varying vec3 pointToCam;
void main()
{
gl_Position = transfproj*position;
pointToLight = lightpos - position.xyz;
pointToCam = campos - gl_Position.xyz;
v_normal = (vec4(normal,1)).xyz;
v_texCoord = texCoord;
}
</script>
<script id="frag-shader" type="notjs">
precision mediump float;
//texturas
uniform sampler2D tex;
varying vec2 v_texCoord;
//iluminação:
varying vec3 v_normal;
uniform vec3 lightDirection;
uniform vec3 lightColor;
//cores sólidas:
uniform vec4 color;
uniform bool isSolid;
varying vec3 pointToLight;
varying vec3 pointToCam;
void main()
{
vec3 pToLight = normalize(pointToLight);
vec3 pToCam = normalize(pointToCam);
vec3 halfVec = normalize(pToCam + pToLight);
vec3 v_normal_n = normalize(v_normal);
vec3 lightDirection_n = normalize(-lightDirection);
float lightd = dot(v_normal_n,lightDirection_n);
float lightp = dot(v_normal_n,pToLight);
float lighte = dot(v_normal_n,halfVec);
if (lightd<0.0) lightd = 0.0;
if (lightp<0.0) lightp = 0.0;
if (lighte<0.0) lighte = 0.0;
if(isSolid){ //Caso verdadeiro, objeto deve ser renderizado com cor sólida
gl_FragColor = color;
}else{
//Com luz de cor
//gl_FragColor = vec4(lightColor*light*texture2D(tex, v_texCoord).rgb, 1);
// Modelo de reflexão de Phong:
// Ambiente:
//gl_FragColor = 0.6 * texture2D(tex, v_texCoord);
// Direcional:
//gl_FragColor += 0.5 * lightp * texture2D(tex, v_texCoord);
vec3 texColor = texture2D(tex, v_texCoord).rgb;
gl_FragColor.rgb = 0.1*lightColor*texColor;
gl_FragColor.rgb += 0.3*lightColor*lightd*texColor;
gl_FragColor.rgb += 0.4*lightColor*lightp*texColor;
gl_FragColor.rgb += 0.4* lightColor*pow(lighte,20.0)*texColor;
gl_FragColor.a = texture2D(tex, v_texCoord).a;
}
}
</script>
</head>
<body class="bg-light bg-gradient">
<div class="container my-4">
<section id="game" class="mb-5">
<div class="d-flex flex-column align-items-center">
<div>
<p class="lead mb-0 fs-3">Pontuação atual: <b id="live-scoreboard">0</b></p>
<div class="d-flex gap-1 h6 mb-0">
<p>Recorde: <b id="record">0</b></p>
<p class="d-none text-success new-record"> (Novo recorde!)</p>
</div>
</div>
<div class="d-flex flex-column align-items-center position-relative w-500px h-500px">
<!-- Start Overlay -->
<div
class="hide-start z-1 d-flex justify-content-center flex-column align-items-center position-absolute top-0 start-0 w-100 h-100 bg-dark-subtle">
<p class="display-6 text-center">Desvie dos trens!
<p class="h4 text-center">(Utilize as teclas WASD)</p>
<button class="btn btn-success mt-3" onclick="startGame()">
<i class="bi bi-play-fill"></i>
Iniciar
</button>
</div>
<!-- Game Over Overlay -->
<div
class="show-end z-1 d-none justify-content-center flex-column align-items-center position-absolute top-0 start-0 w-100 h-100 bg-dark bg-opacity-75">
<p class="text-danger h1">GAME OVER</p>
<p class="text-white h3">Pontuação: <b id="end-scoreboard">0</b></p>
<p class="d-none text-success h5 new-record">(Novo recorde!)</p>
<button class="btn btn-primary" onclick="location.reload()">
<i class="bi bi-arrow-clockwise"></i>
Reiniciar
</button>
</div>
<!-- Canvas -->
<canvas id="glcanvas1" width="500" height="500"
class="show-start d-none justify-content-center flex-column align-items-center position-absolute top-0 start-0"></canvas>
</div>
</div>
</section>
<section id="about" class="my-5">
<h2>Sobre o jogo <a title="Ver no GitHub" target="_blank" class='link-body-emphasis'
href="https://github.com/caiofov/CG-WebGL"><i class="mx-2 bi bi-github fs-4"></i></a></h2>
<p>Inspirado no popular <b>Subway Surfers</b>, o jogador deve desviar dos trens enquanto coleta moedas, que
aumentam sua pontuação total. Os movimentos são realizados utilizando as teclas <b>W, A, S</b> e
<b>D</b>. A melhor pontuação obtida é armazenada e exibida, permitindo ao jogador saber qual foi seu
recorde anterior.
</p>
<div class="d-flex gap-5 mt-4 align-items-center">
<h5>Desenvolvido por: </h5>
<div class="d-flex flex-column align-items-center gap-2">
<p class="lead mb-0"><strong>Caio Oliveira</strong></p>
<div class="d-flex gap-3">
<a target="_blank" class="link-body-emphasis" title="GitHub"
href="https://github.com/caiofov"><i class="bi bi-github fs-5"></i></a>
<a target="_blank" class="link-body-emphasis" title="LinkedIn"
href="https://www.linkedin.com/in/caio-oliveira1312/"><i
class="bi bi-linkedin fs-5"></i></a>
</div>
</div>
<div class="d-flex flex-column align-items-center gap-2">
<p class="lead mb-0"><strong>Matheus Ribeiro</strong></p>
<div class="d-flex gap-3">
<a target="_blank" class="link-body-emphasis" title="GitHub" class="link-body-emphasis"
href="https://github.com/matheusriale"><i class="bi bi-github fs-5"></i></a>
<a target="_blank" class="link-body-emphasis" title="LinkedIn" class="link-body-emphasis"
href="https://www.linkedin.com/in/matheusribeiroalencar/"><i
class="bi bi-linkedin fs-5"></i></a>
</div>
</div>
</div>
</section>
<section id="tech">
<h2>Informações</h2>
<div class="row mt-5 row-cols-md-3 row-cols-1 text-center">
<div class="col d-flex flex-column align-items-center mb-4">
<div class="d-flex flex-column align-items-center mb-3">
<i class="bi bi-camera-reels fs-1 mb-3"></i>
<h4 class="card-title">
Câmera
</h4>
</div>
<p>A visão é em <b>3ª pessoa</b>, podendo ser movida com as teclas <b>WASD</b>. O
personagem do
jogador também se move junto à câmera.</p>
</div>
<div class="col d-flex flex-column align-items-center mb-4">
<div class="d-flex flex-column align-items-center mb-3">
<i class="bi bi-lightbulb fs-1 mb-3"></i>
<h4 class="card-title">
Iluminação
</h4>
</div>
<p>Utilizamos o modelo de reflexão de <b>Phong</b> com luzes <b>ambiente</b>, <b>direcional</b> e
<b>especular</b>. A luz da moeda é pontual e se move.
</p>
</div>
<div class="col d-flex flex-column align-items-center mb-4">
<div class="d-flex flex-column align-items-center mb-3">
<i class="bi bi-arrow-repeat fs-1 mb-3"></i>
<h4 class="card-title">
Transformações
</h4>
</div>
<p>Foram realizadas <b>translações</b> para a moeda, jogador e trens. Além disso, a
moeda também <b>rotaciona</b>.</p>
</div>
<div class="col d-flex flex-column align-items-center mb-4">
<div class="d-flex flex-column align-items-center mb-3">
<i class="bi bi-bricks fs-1 mb-3"></i>
<h4 class="card-title">
Texturas
</h4>
</div>
<p>Todos os objetos tem <b>textura</b>, com exceção do jogador e da moeda, que
possuem <b>cor sólida</b>.</p>
</div>
<div class="col d-flex flex-column align-items-center mb-4">
<div class="d-flex flex-column align-items-center mb-3">
<i class="bi bi-code-slash fs-1 mb-3"></i>
<h4 class="card-title">
Tecnologias
</h4>
</div>
<p>Além do <b>JavaScript</b>, foi utilizado o <b>WebGL</b> para os gráficos e a biblioteca
<b>math.js</b> para realizar
operações com matrizes.
</p>
</div>
<div class="col d-flex flex-column align-items-center mb-4">
<div class="d-flex flex-column align-items-center mb-3">
<i class="bi bi-box fs-1 mb-3"></i>
<h4 class="card-title">
Objetos
</h4>
</div>
<p>O jogador e a moeda são objetos carregados de <b>arquivos .obj</b> a partir de um leitor
implementador por nós.</p>
</div>
</div>
</section>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
<script src="game/camera.js"></script>
<script src="game/events.js"></script>
<script src="game/utils.js"></script>
<script src="game/webgl.js"></script>
<script src="game/drawing/readObj.js"></script>
<script src="game/drawing/shapes.js"></script>
<script src="game/drawing/textures.js"></script>
<script src="game/drawing/vertices.js"></script>
<script src="game/elements/game.js"></script>
<script src="game/elements/player.js"></script>
<script src="game/elements/scenario.js"></script>
<script src="game/elements/train.js"></script>
<script src="game/elements/coin.js"></script>
<script>
document.querySelector("#record").innerHTML = RECORD
function startGame() {
document.querySelectorAll(".hide-start").forEach(e => e.className = e.className.replace("d-flex", "d-none"))
document.querySelectorAll(".show-start").forEach(e => e.className = e.className.replace("d-none", "d-flex"))
init()
}
</script>