-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
executable file
·234 lines (213 loc) · 7.96 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
<!DOCTYPE html>
<html lang='zh-cn'>
<head>
<meta charset="UTF-8" />
<title>DEMO</title>
<link rel="stylesheet" type="text/css" href="./main.css" />
</head>
<body>
<div id="box">
<div id="container" class="container">
<img id="outer" src="image/bg.jpg" />
<div id="shadow" class="ball shadow"></div>
<div id="ball" class="ball"></div>
<div id="net"></div>
</div>
</div>
<div id="info">
<div class="avatar avatar-him">
<img src="image/o_skyking.jpg" />
<p>小胡子哥</p></div>
<div class="avatar avatar-me">
<img src="image/o_skyking.jpg" />
<p>小胡子哥</p>
</div>
<div class="score-box">
<strong>Score</strong>
<span id="score">1:2</span>
</div>
<div class="trace"></div>
</div>
<div id="beforeGame" style="display:dnone">
<div class="rolebox role-action-run">
<div class="role-header">
<div class="inBox box-forward"><img src="image/spider/header/forward.jpg" /></div>
<div class="inBox box-back"><img src="image/spider/header/back.jpg" /></div>
<div class="inBox box-left"><img src="image/spider/header/left.jpg" /></div>
<div class="inBox box-right"><img src="image/spider/header/right.jpg" /></div>
<div class="inBox box-top"><img src="image/spider/header/top.jpg" /></div>
<div class="inBox box-bottom"><img src="image/spider/header/bottom.jpg" /></div>
</div>
<div class="body-down">
<div class="role-body">
<div class="inBox box-forward"><img src="image/spider/body/forward.jpg" /></div>
<div class="inBox box-back"><img src="image/spider/body/back.jpg" /></div>
<div class="inBox box-left"><img src="image/spider/body/left.jpg" /></div>
<div class="inBox box-right"><img src="image/spider/body/right.jpg" /></div>
<!-- <div class="inBox box-top"><img src="image/spider/body/top.jpg" /></div> -->
<div class="inBox box-bottom"><img src="image/spider/body/bottom.jpg" /></div>
</div>
<div class="role-hand role-hand-left">
<div class="inBox box-forward"><img src="image/spider/hand/forward.jpg" /></div>
<div class="inBox box-back"><img src="image/spider/hand/back.jpg" /></div>
<div class="inBox box-left"><img src="image/spider/hand/left.jpg" /></div>
<div class="inBox box-right"><img src="image/spider/hand/right.jpg" /></div>
<div class="inBox box-top"><img src="image/spider/hand/top.jpg" /></div>
<div class="inBox box-bottom"><img src="image/spider/hand/bottom.jpg" /></div>
</div>
<div class="role-hand role-hand-right">
<div class="inBox box-forward"><img src="image/spider/hand/forward.jpg" /></div>
<div class="inBox box-back"><img src="image/spider/hand/back.jpg" /></div>
<div class="inBox box-left"><img src="image/spider/hand/left.jpg" /></div>
<div class="inBox box-right"><img src="image/spider/hand/right.jpg" /></div>
<div class="inBox box-top"><img src="image/spider/hand/top.jpg" /></div>
<div class="inBox box-bottom"><img src="image/spider/hand/bottom.jpg" /></div>
</div>
<div class="role-footer">
<div class="inBox box-forward"><img src="image/spider/footer/forward.jpg" /></div>
<div class="inBox box-back"><img src="image/spider/footer/back.jpg" /></div>
<div class="inBox box-left"><img src="image/spider/footer/left.jpg" /></div>
<div class="inBox box-right"><img src="image/spider/footer/right.jpg" /></div>
<!-- <div class="inBox box-top"><img src="image/spider/footer/top.jpg" /></div>
<div class="inBox box-bottom"><img src="image/spider/footer/bottom.jpg" /></div>-->
</div>
</div>
<div class="welcome-text">大家好,我是小胡子哥~</div>
</div>
</div>
<!-- <script type="text/javascript" src="./main.js"></script> -->
<script type="text/javascript">
// Game.init();
var _ = function(id)
{
return document.getElementById(id);
}
var ball = _('ball');
var outer = _('outer');
var net = _('net');
var ballx = 0; //球此刻x坐标
var bally = 0; //球此刻x坐标
var ballz = 0; //球此刻x坐标
var fallPosx = 0; //球落点x坐标
var fallPosy = 0; //球落点y坐标
var startPosx = 0; //球出发点x坐标
var startPosy = 0; //球出发点y坐标
var startPosz = 0; //球出发点z坐标
var ballvx = 0; //球x方向的速度 每一回合为常量 vx vy的平方和为v*v
var ballvy = 0; //球x方向的速度 每一回合为常量 vx vy的平方和为v*v
var ballv = 6; //常数 控制球速
var jumpTimes = 0; //反弹次数
var fallTime = 0; //一次运动时间
var nowRound = 1; //1为球向对方移动 0为球向己方移动
var g = 0.0009; //常数 控制重力加速度
var yconstA = -g; //抛物线三参数 A不变
var yconstB = 0; //抛物线三参数 B为计算出
var yconstC = 0; //抛物线三参数 C为击球时高度
var setBall = function(x, y, z)
{
var tX = x / 3 * 2; //因为camera完成了1/3的移动视角
var tY = 297 - z / 10 * 9; //因为camera完成了1/10的移动视角
var tZ = 300 - y;
ball.style.webkitTransform="translateY(" + tY + "px) translateZ(" + tZ + "px)translateX(" + tX + "px)";
shadow.style.webkitTransform="translateY(297px) translateZ(" + tZ + "px)translateX(" + tX + "px) rotateX(90deg)";
}
var moveBall = function()
{
fallTime += 1;
ballx = startPosx + fallTime*ballvx;
bally = startPosy + fallTime*ballvy;
var temp = fallTime*ballv;
ballz = yconstA*temp*temp + yconstB*temp + yconstC;
while (ballz < 0)
{
var x2 = Math.sqrt(Math.pow(fallPosx-startPosx, 2) + Math.pow(fallPosy-startPosy, 2));
var y1 = startPosz;
temp -= x2 + y1 / g / x2;
ballz = yconstA*temp*temp + yconstB*temp + yconstC;
}
setBall(ballx, bally, ballz);
moveCamera(ballx / 3, ballz / 20);
if (fallTime*ballv > Math.sqrt(Math.pow(fallPosx-startPosx, 2) + Math.pow(fallPosy-startPosy, 2)) * (1.2 + Math.random() * 0.2))
{
//模拟击打
hit();
}
else if (fallTime < 500)
{
setTimeout(moveBall, 20);
}
}
var init = function()
{
ballx = 100;
bally = 480;
ballz = 40;
startPosx = ballx;
startPosy = bally;
startPosz = ballz;
setFallPos(-100, -100);
}
var setFallPos = function(x, y)
{
fallPosx = x;
fallPosy = y;
//通过球落地点 来动态计算初始速度
var x2 = Math.sqrt(Math.pow(x-startPosx, 2) + Math.pow(y-startPosy, 2));
var y1 = startPosz;
yconstB = g*x2 - y1/x2; //分母为零
yconstC = y1;
var theta = Math.atan((y-startPosy) / (x-startPosx)); //分母为零
if (x < startPosx)
{
theta += Math.PI;
}
ballvx = ballv * Math.cos(theta);
ballvy = ballv * Math.sin(theta);
fallTime = 0;
jumpTimes = 0;
nowRound = !nowRound + 0;
}
var hit = function()
{
startPosx = ballx;
startPosy = bally;
startPosz = ballz;
if (nowRound)
{
setFallPos(parseInt(Math.random() * 400) - 200, 300 - parseInt(50 + Math.random() * 350));
}
else
{
setFallPos(parseInt(Math.random() * 400) - 200, 300 + parseInt(50 + Math.random() * 350));
}
moveBall();
}
var moveCamera = function(x, z)
{
outer.style.webkitTransform = "rotateX(90deg) translateZ(" + (z*-1-300) + "px) translateX(" + (x*-1) + "px)";
net.style.webkitTransform = "translateY(" + (z+300) + "px) translateX(" + (x*-1) + "px)";
}
init();
// setBall(0, 0, 0);
moveBall();
var roleBox = document.querySelector(".rolebox");
roleBox.addEventListener('webkitAnimationEnd', function(){
// 动画结束修改图片
var roleBox2 = roleBox.cloneNode(true);
[].slice.call(roleBox2.querySelectorAll("img")).forEach(function(item, index){
var attr = item.getAttribute("src");
item.setAttribute("src", attr.replace("spider", "spider"));
});
// 修改文字信息
roleBox2.querySelector(".welcome-text").innerHTML = "大家好,我就是小胡子~";
// 添加Class
var roleClass = roleBox2.getAttribute("class");
roleBox2.classList.remove("role-action-run");
roleBox2.classList.add("role-action-jump");
document.querySelector("#beforeGame").appendChild(roleBox2);
roleBox.style.top = "9999px";
})
</script>
</body>
</html>
<script src='http://www.barretlee.com/demo-platform.js'></script>