forked from iamkun/tower_game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
219 lines (201 loc) · 6.23 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no,minimal-ui">
<title>Tower Building</title>
<link rel="icon" href="assets/favicon.png">
<link rel="stylesheet" href="style.css">
</head>
<body>
<canvas id="canvas" class="hide"></canvas>
<div class="content">
<div class="loading">
<div class="main"><img
src="./assets/main-loading.gif">
<div class="progress">
<div class="title font-wenxue">0%</div>
<div class="bar">
<div class="sub">
<div class="percent"></div>
</div>
</div>
<div class="text">Loading...</div>
</div>
</div>
</div>
<div class="landing hide">
<div class="action-1">
<img
src="./assets/main-index-title.png"
class="title swing">
</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"><img
src="./assets/main-modal-bg.png"
class="bg">
<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">
<div class="tip"><p>Try Again!</p>
<img
src="./assets/main-modal-again-b.png"
class="over-button-b js-reload"><img
src="./assets/main-modal-invite-b.png"
class="over-button-b js-invite"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="wxShare hide">
<img src="./assets/main-share-icon.png">
</div>
</div>
<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()
}, 1000)
}
}
function updateLoading(status) {
var success = status.success
var total = status.total
var failed = status.failed
if (failed > 0 && !loadError) {
loadError = true
alert('Loading is fail... Please try again.')
return
}
var percent = parseInt((success / total) * 100);
if (percent === 100 && !canvasReady) {
canvasReady = true
hideLoading()
}
percent = percent > 98 ? 98 : percent
percent = percent + '%'
$('.loading .title').text(percent);
$('.loading .percent').css({
'width': percent
})
}
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()
}
}
// game init with option
function gameReady() {
game = TowerGame(option)
game.load(function () {
game.playBgm()
game.init()
}, updateLoading)
}
var isWechat = navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1
if (isWechat) {
document.addEventListener("WeixinJSBridgeReady", gameReady, false)
} else {
gameReady()
}
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
indexHide()
setTimeout(game.start, 400)
})
$('.js-reload').on('click', function () {
window.location.href = window.location.href + '?s=' + (+new Date())
})
$('.js-invite').on('click', function () {
$('.wxShare').show()
})
$('.wxShare').on('click', function () {
$('.wxShare').hide()
})
// listener
window.addEventListener('load', function () {
domReady = true
hideLoading()
}, false);
</script>
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-46444752-20', 'auto');
ga('send', 'pageview');
var _hmt = _hmt || [];
(function () {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?c1b044f909411ac4213045f0478e96fc";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</body>
</html>