This repository has been archived by the owner on Jan 2, 2025. It is now read-only.
forked from iamkun/tower_game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
218 lines (208 loc) Β· 7.52 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,minimal-ui">
<link rel="icon" type="image/x-icon" href="./assets/favicon.png">
<style>
*{margin:0;padding:0}
img{width:100%}
html{background:#fff;height:100%}
body{font-family:"Helvetica Neue",Arial,Helvetica,sans-serif;margin:0 auto;text-align:center;width:100%;height:100%;background:#000;}
@media screen and (min-height:560px){
html{font-size:100px}
}
@media screen and (min-height:640px){
html{font-size:112.5px}
}
@media screen and (min-height:720px){
html{font-size:125px}
}
@media screen and (min-height:800px){
html{font-size:137.5px}
}
@media screen and (min-height:880px){
html{font-size:150px}
}
@media screen and (min-height:960px){
html{font-size:162.5px}
}
@media screen and (min-height:1040px){
html{font-size:180px}
}
@media screen and (min-height:1200px){
html{font-size:200px}
}
html{
font-size:17.6vh
}
#canvas{position:fixed;left:0;top:0;right:0;bottom:0;margin:auto}
a{text-decoration:none}
li,ol,ul{list-style-type:none;padding:0;margin:0}
.hide{display:none}
.clear{clear:both}
.loading{background:#000; height:100%;width:100%}
.content{height:100vh;margin:0 auto;position:relative}
.landing .action-2{position:absolute;bottom:.2rem;width:100%}
.landing .start{width:65%}
#highscorelist {margin-top:.4em; font-size:.28em; font-weight:bold; color:white}
.slideTop{-webkit-animation:st 1s ease-in-out;animation:st 1s ease-in-out}
@-webkit-keyframes st{0%{transform:translateZ(0)}100%{transform:translate3d(0,-100%,0)}}
@keyframes st{0%{transform:translateZ(0)}100%{transform:translate3d(0,-100%,0)}}
.slideBottom{-webkit-animation:sb 1s ease-in-out;animation:sb 1s ease-in-out}
@-webkit-keyframes sb{0%{transform:translateZ(0)}100%{transform:translate3d(0,200%,0)}}
@keyframes sb{0%{transform:translateZ(0)}100%{transform:translate3d(0,200%,0)}}
@-webkit-keyframes sw{0%{transform:rotate(5deg);transform-origin:top center}100%{transform:rotate(-5deg);transform-origin:top center}}
@keyframes sw{0%{transform:rotate(5deg);transform-origin:top center}100%{transform:rotate(-5deg);transform-origin:top center}}
.modal.mask{background-color:#000;opacity:.6;position:fixed;height:100%;width:100%;top:0;left:0}
.modal .modal-content{position:fixed;height:100%;width:90%;margin-top:.3rem;top:0}
.modal .main{width:85%;margin:0 auto}
.modal .container{position:relative}
.modal .bg{width:100%;position:absolute;top:0;left:0}
.modal .modal-main{width:100%;position:absolute;top:0;left:0;margin-top:-.4rem}
.modal .over-img{width:80%;margin:.8rem auto 0}
.modal .over-score{margin-top:-.2rem;font-size:.5rem;color:#ff735c;text-shadow:-2px -2px 0 #fff,2px -2px 0 #fff,-2px 2px 0 #fff,2px 2px 0 #fff}
.modal .over-button-b{width:70%;margin:.1rem auto 0}
@font-face{font-family:wenxue;src:url(assets/wenxue.eot);src:url(assets/wenxue.eot),url(assets/wenxue.woff),url(assets/wenxue.ttf),url(assets/wenxue.svg)}
.font-wenxue{font-family:wenxue}
@media (prefers-color-scheme: light) {
body{background:#fff;}
.loading{background:#fff;}
}
</style>
</head>
<body>
<canvas id="canvas" class="hide"></canvas>
<div class="content">
<div class="loading">
</div>
<div class="landing hide">
<div class="action-1"><div id="highscorelist"></div></div>
<div class="action-2"><img id="start" src="./assets/main-index-start.png" class="start"></div>
</div>
<div id="modal" class="modal hide">
<div class="mask"></div>
<div class="js-modal-content modal-content">
<div class="main">
<div class="container">
<div class="modal-main">
<div id="over-modal" class="hide js-modal-card">
<img src="./assets/main-modal-over.png" class="over-img">
<div id="score" class="over-score font-wenxue"></div>
<div id="over-zero" class="hide"><img src="./assets/main-modal-again-b.png" class="over-button-b js-reload"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="./webxdc.js"></script>
<script src="./highscore.js"></script>
<script src="./dist/main.js"></script>
<script src="./assets/zepto-1.1.6.min.js"></script>
<script>
var domReady, loadFinish, canvasReady, loadError, gameStart, game, score, successCount
// init window height and width
var gameWidth = window.innerWidth
var gameHeight = window.innerHeight
var ratio = 1.5
if (gameHeight / gameWidth < ratio) {
gameWidth = Math.ceil(gameHeight / ratio)
}
$('.content').css({ "height": gameHeight + "px", "width": gameWidth + "px" })
$('.js-modal-content').css({ "width": gameWidth + "px" })
// loading animation
function hideLoading() {
if (domReady && canvasReady) {
$('#canvas').show()
loadFinish = true
setTimeout(function () {
$('.loading').hide()
$('.landing').show()
}, 100)
}
}
function updateLoading(status) {
var success = status.success
var total = status.total
var failed = status.failed
if (failed > 0 && !loadError) {
loadError = true
alert('Network error... Please try again.')
return
}
var percent = parseInt((success / total) * 100);
if (percent === 100 && !canvasReady) {
canvasReady = true
hideLoading()
}
}
function overShowOver() {
$('#modal').show()
$('#over-modal').show()
$('#over-zero').show()
}
// game customization options
const option = {
width: gameWidth,
height: gameHeight,
canvasId: 'canvas',
soundOn: true,
setGameScore: function (s) {
score = s
},
setGameSuccess: function (s) {
successCount = s
},
setGameFailed: function (f) {
$('#score').text(score)
if (f >= 3) {
overShowOver()
updateSelfHighscore(score)
}
}
}
// game init with option
game = TowerGame(option)
game.load(function () {
game.init()
setTimeout(function () {
game.playBgm()
})
}, updateLoading);
function indexHide() {
$('.landing .action-1').addClass('slideTop')
$('.landing .action-2').addClass('slideBottom')
setTimeout(function () {
$('.landing').hide()
}, 950)
}
// click event
$('#start').on('click', function () {
if (gameStart) return
gameStart = true
setTimeout(function () {
game.playBgm()
})
indexHide()
setTimeout(game.start, 400)
})
$('.js-reload').on('click', function () {
window.location.href = window.location.href + '?s=' + (+new Date())
})
// listener
window.addEventListener('load', function () {
domReady = true
hideLoading()
}, false);
window.webxdc.setUpdateListener((update) => {
const player = update.payload
setHighscoreFor(player.addr, player.name, player.score)
if (update.serial === update.max_serial) {
$('#highscorelist').html(getAllHighscoresHtml())
}
}, 0);
</script>
</body>
</html>