This repository was archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
234 lines (211 loc) · 5.19 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-TW">
<head>
<meta charset=UTF-8>
<title>Paper Toss</title>
<link rel="stylesheet" type="text/css" href="./papertoss.css" />
<script type="text/javascript">
if (window.location.hostname === 'timdream.org') {
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-4623408-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
}
</script>
</head>
<body>
<img id="bg" src="95-clouds.jpg" />
<canvas id="canvas"></canvas>
<p class="hud" id="score">分數: <span>0</span></p>
<p class="hud" id="wind">風向: <span>0</span></p>
<p class="hud" id="bucketSize">籃子大小: <span>200</span></p>
<button id="splus">S+</button>
<button id="sminus">S-</button>
<button id="tplus">θ+</button>
<button id="tminus">θ-</button>
<button id="yplus">▲</button>
<button id="yminus">▼</button>
<button id="go">Go</button>
<svg id="arrow"
width="47pt"
height="46pt"
version="1.0"
xmlns="http://www.w3.org/2000/svg">
<g transform="scale(0.1 0.1)">
<path
style="font-size:12;fill:#00f;stroke:#00f;"
d="M 345.23509 500.5 L 594.16634 251.00371 L 344.26968 1.468574 L 205.81581 1.525764 L 397.12537 194.51019 L 0.49999607 194.58168 L 0.62293607 305.57099 L 399.73581 305.59147 L 206.36939 500.5 L 345.23509 500.5 z "
sodipodi:nodetypes="cccccccccc" />
</g>
</svg>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript" src="./jquery.papertoss.js"></script>
<script type="text/javascript">
jQuery(function ($) {
var $c = $('#canvas'),
$s = $('#score > span'),
$w = $('#wind > span'),
$b = $('#bucketSize > span'),
$a = $('#arrow'),
score = 0;
function resetCanvasSize() {
var width = document.body.offsetWidth,
height = document.body.offsetHeight;
$c.attr(
{
height: height,
width: width
}
).css({
width: width.toString(10) + 'px',
height: height.toString(10) + 'px',
top: '50%',
left: '50%',
marginLeft: '-' + (width/2).toString(10) + 'px',
marginTop: '-' + (height/2).toString(10) + 'px'
});
}
function updateScore(num) {
renewParam();
score += num;
$s.text(score.toString(10));
}
function renewParam() {
bucketSize -= 20;
$b.text(bucketSize.toString(10));
if (bucketSize <= 100) {
$('#bg').attr('src', 'Bliss_XP_broken.jpg');
} else if (bucketSize <= 140) {
$('#bg').attr('src', 'Bliss_XP.jpg');
} else if (bucketSize < 180) {
$('#bg').attr('src', 'ME-clouds.jpg');
}
bucketPos = document.body.offsetWidth/2 + document.body.offsetWidth/2*Math.random() - bucketSize;
wind = [0.03*Math.random() - 0.015, 0.03*Math.random() - 0.015];
$w.text(
Math.abs(wind[0]*100).toString(10).substr(0,3)
+ ((wind[0] < 0)?' 逆風':' 順風') + ', '
+ Math.abs(wind[1]*100).toString(10).substr(0,3)
+ ((wind[1] < 0)?' 向下':' 向上')
);
}
var bucketPos,
speed = 20,
theta = Math.PI/4,
bucketSize = 200,
wind = [-0.03, 0],
startY = 180;
function newLabel() {
$c.paperToss(
{
gofor: 'bucket',
bucketImage: $('#bucket')[0],
bucketPos: [bucketPos, bucketSize],
bucketSize: [bucketSize, bucketSize]
}
);
}
function endLevel() {
$c[0].getContext('2d').clearRect(0, 0, $c.attr('width'), $c.attr('height'));
newLabel();
newInitPos(startY);
}
function newInitPos(y) {
var orgY = startY;
startY = y;
$c.paperToss(
{
gofor: 'initball',
ballImage: $('#ball')[0],
initPos: [30, startY],
cleanPos: [30, orgY]
}
);
}
function startToss() {
$c.paperToss(
{
ballImage: $('#ball')[0],
initPos: [30, startY],
initSpeed: [speed*Math.cos(theta), speed*Math.sin(theta)],
bucketPos: [bucketPos, bucketSize],
bucketSize: [bucketSize, bucketSize],
wind: wind,
inBucket: function () {
updateScore(100);
},
complete: endLevel
}
);
}
function updateInitCond() {
$a
.css('opacity', speed/40)
.css('-webkit-transform', 'rotate(-' + theta/Math.PI*180 + 'deg)');
// http://bugs.jquery.com/ticket/8346
$a[0].style['-ms-transform'] = 'rotate(-' + theta/Math.PI*180 + 'deg)';
}
renewParam();
resetCanvasSize();
setTimeout(
function () {
newLabel();
newInitPos(startY);
updateInitCond();
},
500
);
$('#go').bind(
'click',
startToss
);
$('#splus').bind(
'click',
function () {
if (speed < 40) speed += 1;
updateInitCond();
}
);
$('#sminus').bind(
'click',
function () {
if (speed > 0) speed -= 1;
updateInitCond();
}
);
$('#tplus').bind(
'click',
function () {
if (theta < Math.PI/2) theta += Math.PI/32;
updateInitCond();
}
);
$('#tminus').bind(
'click',
function () {
if (theta > 0) theta -= Math.PI/32;
updateInitCond();
}
);
$('#yplus').bind(
'click',
function () {
newInitPos(startY + 10);
}
);
$('#yminus').bind(
'click',
function () {
newInitPos(startY - 10);
}
);
});
</script>
<img id="bucket" src="HTML5-logo.svg" />
<img id="ball" src="IE9-logo.png" />
</body>
</html>