-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
434 lines (397 loc) · 14.7 KB
/
Copy pathindex.html
File metadata and controls
434 lines (397 loc) · 14.7 KB
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
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stackup Invaders</title>
<style>
[x-cloak] { display: none !important; }
.modal {
transition: opacity 0.25s ease;
}
body.modal-active {
overflow-x: hidden;
overflow-y: visible !important;
}
</style>
<script src="libs/tailwind.js"></script>
<link rel="stylesheet" href="assets/css/styles.css">
<link rel="stylesheet" href="libs/bootstrap.min.css" defer>
<script src="libs/imtbl-sdk@0.44.0.js" defer></script>
<script type="module" src="assets/js/passport.js"></script>
<script type="module" src="assets/js/login.js"></script>
<script src="libs/alpine.js" defer></script>
<script src="libs/p5.min.js"></script>
<script src="libs/p5.dom.min.js"></script>
<script src="assets/js/Alien.js" type="application/javascript"></script>
<script src="assets/js/Invaders.js" type="application/javascript"></script>
<script src="assets/js/Player.js" type="application/javascript"></script>
<script src="assets/js/Bullet.js" type="application/javascript"></script>
<script src="assets/js/PlayerBullet.js" type="application/javascript"></script>
<script src="assets/js/AlienBullet.js" type="application/javascript"></script>
<script src="assets/js/Debris.js" type="application/javascript"></script>
<script src="assets/js/sketch.js" type="application/javascript" defer></script>
</head>
<body
class=""
x-data='{
highestScore: null,
highestScoreUser: null,
user: "",
loadingUser: false,
playing: false,
}'
x-init="
window.passport.loginCallback()
"
@notconnected="
window.gameIsNotOn = true
playing=false
"
style="background-image: url('assets/images/bg.png')"
>
<header class="container flex items-center justify-between px-4 py-2 text-white">
<a href="https://github.com/Complexlity" target="_blank">
<div class="w-12 h-12 m-1">
<img alt="logo" src="assets/images/complex.png" class="w-full h-full object-cover">
</div>
</a>
<button
x-cloak
x-show="!user"
@click="
loadingUser = true
try {
await connectPassport()
user = window.userProfile
highestScore = window.highestScoreData.score
highestScoreUser = window.highestScoreData.userAddress
}
catch(err){
console.log(err)
}
finally {
loadingUser = false
}
"
:class="loadingUser ? 'disabled text-gray-500 px-2 !cursor-not-allowed' : 'text-white cursor-pointer'"
class="flex items-center text-xl bg-blue-950 text-blue-400 !border !border-blue-400 !border-b-4 font-medium overflow-hidden relative px-4 py-2 !rounded-xl hover:brightness-150 hover:!border-t-4 hover:!border-b active:opacity-75 outline-none duration-300 group">
<svg
x-show="loadingUser"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="mr-2 h-8 w-8 animate-spin"
x-cloak
>
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
</svg>
<span
class="bg-blue-400 shadow-blue-400 absolute -top-[150%] left-0 inline-flex w-80 h-[5px] rounded-md opacity-50 group-hover:top-[150%] duration-500 shadow-[0_0_10px_10px_rgba(0,0,0,0.3)]"></span>
<span
x-text="loadingUser ? 'Connecting...' : 'Connect Wallet'"
></span>
</button>
</div>
<div
x-cloak
x-show="user"
class="py-2 text-white flex gap-4"
>
<p
class="text-white-800 font-xl text-xl px-4 py-2 bg-purple-800"
x-text="user.email"></p>
<button
x-data="{
loggingOut: false
}"
x-cloak
x-show="user"
@click="
loggingOut=true
try{
await window.passport.logout()
window.userProfile=''
user = ''
playing = ''
window.gameIsStarted = false
window.gameIsNotOne = false
}catch(error){
console.log(error)
}finally{
loggingOut=false
}
"
:class="loggingOut ? 'disabled text-gray-500 px-2 !cursor-not-allowed' :
'text-white cursor-pointer'"
class="flex items-center text-xl bg-red-950 text-white !border !border-red-400 !border-b-4 font-medium overflow-hidden relative px-4 py-2 !rounded-xl hover:brightness-150 hover:!border-t-4 hover:!border-b active:opacity-75 outline-none duration-300 group">
<svg
x-show="loggingOut"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="mr-2 h-8 w-8 animate-spin"
x-cloak
>
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
</svg>
<span
class="bg-red-400 shadow-red-400 absolute -top-[150%] left-0 inline-flex w-80 h-[5px] rounded-md opacity-50 group-hover:top-[150%] duration-500 shadow-[0_0_10px_10px_rgba(0,0,0,0.3)]"></span>
<span
x-text="loggingOut ? 'Logging Out...' : 'Log Out'"
></span>
</button>
</div>
</header>
<section
class="congrats-modal"
x-data='{
savingScore: false,
savingSuccess: false
}'
@gameover='
const finalGameScore = window.finalGameScore
if(highestScore >= finalGameScore) return
highestScore = finalGameScore
highestScoreUser = window.userProfile.address
savingScore = true
window.toggleModal()
const api = window.highestScoringApi
const data = {
score: finalGameScore,
userAddress: highestScoreUser,
}
try{
const res = await fetch(api, {
headers: {
"Content-Type": "application/json"
},
method: "POST",
body: JSON.stringify(data)
})
savingSuccess = true
const result = await res.json()
} catch(e){
console.log(e)
savingSuccess = false
}finally {
savingScore = false
}
'
>
<!--Modal-->
<div class="modal scale-0 opacity-0 pointer-events-none fixed w-full h-full top-0 left-0 flex items-center justify-center">
<div class="modal-overlay absolute w-full h-full bg-gray-900 opacity-50"></div>
<div class="modal-container bg-white w-11/12 md:max-w-md mx-auto rounded shadow-lg z-50 overflow-y-auto">
<!-- Add margin if you want to see some of the overlay behind the modal-->
<div class="modal-content py-4 text-left px-6">
<!--Title-->
<div class="flex justify-between items-center pb-3">
<p class="text-2xl text-center flex-1">Congratulations!!! <span class="font-bold" x-text="user.email"></span>
<br/>
You Beat The Highscore</p>
<div class="modal-close cursor-pointer z-50">
<svg
x-show="!savingScore"
class="fill-current text-black" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18">
<path d="M14.53 4.53l-1.06-1.06L9 7.94 4.53 3.47 3.47 4.53 7.94 9l-4.47 4.47 1.06 1.06L9 10.06l4.47 4.47 1.06-1.06L10.06 9z"></path>
</svg>
</div>
</div>
<!--Body-->
<div class="flex my-4 gap-4 items-center justify-center">
<p :class="savingScore ? 'text-amber-400' : savingSuccess ? 'text-green-600' : 'text-red-600'"
class="font-bold text-2xl"
x-text="savingScore ? 'Saving Score...' : savingSuccess ? 'Highest Score Saved' : 'Something Went Wrong'"></p>
<svg
x-show="savingScore"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="mr-2 h-8 w-8 animate-spin text-amber-500"
x-cloak
><path d="M21 12a9 9 0 1 1-6.219-8.56" />
</svg>
<svg
x-show="!savingScore && savingSuccess"
class="text-green-700"
xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-check"><path d="M20 6 9 17l-5-5"/></svg>
<svg
x-show="!savingScore && !savingSuccess"
class="fill-current text-black" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18">
<path d="M14.53 4.53l-1.06-1.06L9 7.94 4.53 3.47 3.47 4.53 7.94 9l-4.47 4.47 1.06 1.06L9 10.06l4.47 4.47 1.06-1.06L10.06 9z"></path>
</svg>
</div>
<!--Footer-->
<div
class="flex justify-end pt-2">
<button :disabled='savingScore' :class="savingScore ? 'bg-indigo-400' : ''" class="modal-close px-4 bg-indigo-500 p-3 rounded-lg text-white hover:bg-indigo-400">Close</button>
</div>
</div>
</div>
</section>
<section
x-show="!playing"
x-cloak
class="h-[calc(100vh-60px)] w-full max-w-[150ch] mx-auto py-2 text-white grid items-center gap-8"
>
<div class="container px-4 md:px-6">
<div
class="flex flex-col md:flex-row items-center md:space-x-4 space-y-4 md:space-y-0 text-center md:text-left"
>
<div class="space-y-2">
<h1
class="text-4xl text-center font-bold tracking-tighter sm:text-5xl md:text-6xl lg:text-7xl bg-clip-text text-transparent bg-gradient-to-r from-purple-500 via-pink-500 to-red-500"
>
Welcome to StackUp Invaders
</h1>
<p class="text-2xl italic text-teal-600">The best game for legendary shooters
</p>
</div>
<div class="relative rounded-md w-4/5 lg:w-1/2">
<img
src="assets/images/hero.webp"
alt="Game Channel Image"
class="hero1 w-full h-full object-cover rounded-md"
width="500"
height="500"
style="aspect-ratio: 500 / 500; object-fit: cover"
/>
<img
src="assets/images/hero2.jpg"
alt="Game Channel Image"
class="hero2 w-full h-full object-cover rounded-md"
width="500"
height="500"
style="aspect-ratio: 500 / 500; object-fit: cover"
/>
</div>
</div>
</div>
<!-- Play now button -->
<div class="space-x-4 text-center mb-2">
<div class="relative inline-flex group">
<div
class="absolute transitiona-all duration-1000 opacity-70 -inset-px bg-gradient-to-r from-[#44BCFF] via-[#FF44EC] to-[#FF675E] rounded-xl blur-lg group-hover:opacity-100 group-hover:-inset-1 group-hover:duration-200 animate-tilt"
></div>
<button
@click="
if(!user){
alert('Please connect your wallet first');
}
else {
playing=true
window.gameIsStarted = true
}
"
href="#"
title="Get quote now"
class="breathing relative inline-flex items-center justify-center px-8 py-4 text-lg font-bold text-white transition-all duration-200 bg-gray-900 font-pj rounded-xl focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-900"
role="button"
>
Play Now
</button>
</div>
</div>
</section>
<section
x-cloak
x-show="playing"
>
<div
x-cloak
x-show="playing"
class="container-fluid p-4">
<div class="flex gap-4">
<div class="alert alert-primary" role="alert">
Press the spacebar to shoot and arrows to move in all 4 directions!
</div>
<div class="alert alert-primary" role="alert">
Overall Highest Score: <span x-text="highestScore">
</span>
<span class="italic text-sm mx-1">(Set by <span class="text-[#6400ff] text-base font-bold " x-text="highestScoreUser == user.address ? 'You' : highestScoreUser"></span>)</span>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="row">
<div class="card col-12 pt-2 pb-2 ">
<div class="">
<div
x-cloak
x-show="playing"
id="sketch-holder">
</div>
</div>
</div>
</div>
</div>
<div class="col-6">
<div id="nft">
</div>
</div>
</div>
<div class="row col-6 text-center flex justify-center my-4">
<button class="
start-button
bg-green-900 text-white !border !border-green-400 !border-b-4 font-medium overflow-hidden relative px-4 py-2 !rounded-xl
hover:brightness-150 hover:!border-t-4 hover:!border-b active:opacity-75 outline-none duration-300 group">
<span class="bg-green-400 shadow-green-400 absolute -top-[150%] left-0 inline-flex w-80 h-[5px] rounded-md opacity-50 group-hover:top-[150%] duration-500 shadow-[0_0_10px_10px_rgba(0,0,0,0.3)]"></span>
Start Game
</button>
</div>
</div>
</section>
</body>
<script>
// const overlay = document.querySelector('.modal-overlay')
// overlay.addEventListener('click', toggleModal)
var closemodal = document.querySelectorAll('.modal-close')
for (var i = 0; i < closemodal.length; i++) {
closemodal[i].addEventListener('click', () => {
const modal = document.querySelector('.modal')
if(modal.classList.contains("opacity-0")) return
toggleModal()
})
}
// document.onkeydown = function(evt) {
// evt = evt || window.event
// var isEscape = false
// if ("key" in evt) {
// isEscape = (evt.key === "Escape" || evt.key === "Esc")
// } else {
// isEscape = (evt.keyCode === 27)
// }
// if (isEscape && document.body.classList.contains('modal-active')) {
// toggleModal()
// }
// };
function toggleModal () {
const body = document.querySelector('body')
const modal = document.querySelector('.modal')
modal.classList.toggle('opacity-0')
modal.classList.toggle('scale-0')
modal.classList.toggle('pointer-events-none')
body.classList.toggle('modal-active')
}
window.toggleModal = toggleModal
</script>
</html>