index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Catch it!</title>
  6. <script type="text/javascript" src="http://game.ikongzhong.cn/games/qw/jquery.min.js"></script>
  7. <script type="text/javascript">
  8. var dataForWeixin = {
  9. appId: "gh_ff79a97cd7f3",
  10. TLImg: "http://game.ikongzhong.cn/games/zhua/logo.jpg",
  11. url: "http://game.ikongzhong.cn/games/zhua/",
  12. title: "Classic game <Catch it!>, please share your friends! Circle friends wechat!",
  13. desc: "please share your friends! Circle friends wechat!"
  14. };
  15. var onBridgeReady = function(){
  16. WeixinJSBridge.on('menu:share:appmessage', function(argv){
  17. var infos = $("#infos").text();
  18. WeixinJSBridge.invoke('sendAppMessage', {
  19. "appid": dataForWeixin.appId,
  20. "img_url": dataForWeixin.TLImg,
  21. "img_width": "120",
  22. "img_height": "120",
  23. "link": dataForWeixin.url + '?f=wx_hy_bb',
  24. "title": infos + dataForWeixin.title,
  25. "desc": dataForWeixin.desc
  26. });
  27. setTimeout(function () {location.href = "http://game.ikongzhong.cn/games/zhua/";}, 1500);
  28. });
  29. WeixinJSBridge.on('menu:share:timeline', function(argv){
  30. var infos = $("#infos").text();
  31. WeixinJSBridge.invoke('shareTimeline', {
  32. "appid": dataForWeixin.appId,
  33. "img_url":dataForWeixin.TLImg,
  34. "img_width": "120",
  35. "img_height": "120",
  36. "link": dataForWeixin.url + '?f=wx_pyq_bb',
  37. "title": infos + dataForWeixin.title,
  38. "desc": dataForWeixin.desc
  39. });
  40. setTimeout(function () {location.href = "http://game.ikongzhong.cn/games/zhua/";}, 1500);
  41. });
  42. };
  43. if(document.addEventListener){
  44. document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
  45. }else if(document.attachEvent){
  46. document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
  47. document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
  48. }
  49. </script>
  50. <style>
  51. *{
  52. font-family:Arial;
  53. }
  54. canvas{
  55. margin:0px;
  56. padding:0px;
  57. border-right:#333 dashed;
  58. border-bottom:#333 dashed;
  59. cursor: none;
  60. }
  61. body{
  62. margin:0px;
  63. background:#fc0;
  64. }
  65. .label {
  66. font-weight:bold;
  67. }
  68. .label span {
  69. font-weight:normal;
  70. }
  71. img {
  72. position:fixed;
  73. right:20px;
  74. bottom:20px;
  75. z-index:1000;
  76. border:0px;
  77. }
  78. .STYLE1 {color: #FF0000}
  79. </style>
  80. </head>
  81. <body>
  82. <canvas id="canvas" height="320" width="320">how can you use the internet?</canvas>
  83. <div class="label">Score: <span id="score">0</span></div>
  84. <div class="label">Max-Score: <span id="max_score">0</span></div>
  85. <div class="label">Tries: <span id="tries">1</span></div>
  86. <div style="padding-top:0px;">
  87. <p class="STYLE1">Players control a red circle with mouse on a yellow court and have to catch a red rectangle. Players must not hit one of the gray circles on the yellow court. The number of gray balls increases with every new catch. By a simple click, Players can inverse the direction of all balls C which is sometimes helpful if urged in the top left corner for example.</p>
  88. <p>Read the <img src="http://img.tongji.linezing.com/3455448/tongji.gif" /></p>
  89. </div>
  90. <script>
  91. (function(window) {
  92. var ctx;
  93. var document = window.document;
  94. // our ball object holder
  95. var balls = new Array();
  96. // mouse position cache
  97. var mouse = {x: -100, y: -100};
  98. // our prey we want to hunt
  99. var prey = {x: Math.random() * 310, y: Math.random() * 310};
  100. // cache 2*PI for arc()
  101. var pi2 = Math.PI * 2;
  102. var tries = 1;
  103. var score = 0;
  104. var maxScore = 0;
  105. var currentColor = '#333';
  106. var activeDecay = -1;
  107. var lastCatch = Date.now();
  108. function $(id) {
  109. return document.getElementById(id);
  110. }
  111. function updateStat() {
  112. $('tries').innerHTML = tries;
  113. $('score').innerHTML = score;
  114. $('max_score').innerHTML = maxScore;
  115. }
  116. function Ball(x, y, xsee, ysee) {
  117. this.x = x;
  118. this.y = y;
  119. this.xsee = xsee;
  120. this.ysee = ysee;
  121. this.type = Math.random() * 1.05 | 0;
  122. this.move = function() {
  123. if (this.x > 315) {
  124. this.x = 315;
  125. this.xsee = -this.xsee;
  126. } else if (this.x < 5) {
  127. this.x = 5;
  128. this.xsee = -this.xsee;
  129. }
  130. if (this.y > 315) {
  131. this.y = 315;
  132. this.ysee = -this.ysee;
  133. } else if (this.y < 5) {
  134. this.y = 5;
  135. this.ysee = -this.ysee;
  136. }
  137. this.x += this.xsee;
  138. this.y += this.ysee;
  139. if (this.type === 0) {
  140. ctx.fillStyle = currentColor;
  141. } else {
  142. ctx.fillStyle = '#fff';
  143. }
  144. ctx.beginPath();
  145. ctx.arc(this.x, this.y, 5, 0, pi2, true);
  146. ctx.closePath();
  147. ctx.fill();
  148. };
  149. }
  150. function createBall() {
  151. var x, y;
  152. do {
  153. x = Math.random() * 315;
  154. y = Math.random() * 315;
  155. } while (prey.x <= x + 35 && x <= prey.x + 55 && prey.y <= y + 35 && y <= prey.y + 55);
  156. balls.push(new Ball(x, y, Math.random() * 5.5 - 2.75, Math.random() * 5.5 - 2.75));
  157. }
  158. ctx = $('canvas').getContext('2d');
  159. window.setInterval(clock, 1000 / 60);
  160. function clock() {
  161. // global clear is faster for many balls
  162. ctx.clearRect(0, 0, 320, 320);
  163. ctx.fillStyle = "#c00";
  164. ctx.fillRect(prey.x, prey.y, 20, 20);
  165. ctx.fillStyle = "#c00";
  166. ctx.beginPath();
  167. ctx.arc(mouse.x, mouse.y, 10, 0, pi2, true);
  168. ctx.closePath();
  169. ctx.fill();
  170. if (activeDecay !== -1) {
  171. var now = Date.now();
  172. var pct = (now - activeDecay) / 3000;
  173. if (pct >= 1) {
  174. activeDecay = -1;
  175. pct = 1;
  176. }
  177. currentColor = 'rgba(51,51,51,'+(1 - 2 * pct)*(1 - 2 * pct)+')';
  178. }
  179. for (var i = 0; i < balls.length; i++) {
  180. balls[i].move();
  181. if (
  182. balls[i].x <= mouse.x + 15 && mouse.x <= balls[i].x + 15 &&
  183. balls[i].y <= mouse.y + 15 && mouse.y <= balls[i].y + 15 &&
  184. ((mouse.x - balls[i].x) * (mouse.x - balls[i].x) + (mouse.y - balls[i].y) * (mouse.y - balls[i].y)) <= 225) {
  185. if (balls[i].type === 0) {
  186. balls = new Array();
  187. if (maxScore < score) {
  188. maxScore = score;
  189. }
  190. score = 0;
  191. tries++;
  192. updateStat();
  193. activeDecay = -1;
  194. currentColor = '#333';
  195. } else {
  196. activeDecay = Date.now();
  197. }
  198. }
  199. }
  200. }
  201. document.onclick = function(ev) {
  202. var x = ev.pageX;
  203. var y = ev.pageY;
  204. for (var i = 0; i < balls.length; i++) {
  205. var t = balls[i];
  206. var d = ((t.x - x) * (t.x - x) + (t.y - y) * (t.y - y));
  207. t.xsee += (t.x - x) / d * 180;
  208. t.ysee += (t.y - y) / d * 180;
  209. }
  210. };
  211. document.ontouchstart = function(e) {
  212. };
  213. document.ontouchmove = document.onmousemove = function(e) {
  214. e.preventDefault();
  215. mouse.x = e.pageX;
  216. mouse.y = e.pageY;
  217. ctx.fillStyle = "#c00";
  218. ctx.beginPath();
  219. ctx.arc(mouse.x, mouse.y, 10, 0, pi2, true);
  220. ctx.closePath();
  221. ctx.fill();
  222. /////////////
  223. if (prey.x <= mouse.x + 10 && mouse.x <= prey.x + 30 && prey.y <= mouse.y + 10 && mouse.y <= prey.y + 30) {
  224. prey = {x: Math.random() * 300, y: Math.random() * 300};
  225. createBall();
  226. var now = Date.now();
  227. score+= Math.round(Math.max(5, 30 * Math.exp((now - lastCatch) * 0.000089)) * (activeDecay === -1 ? 1 : 2));
  228. lastCatch = now;
  229. updateStat();
  230. }
  231. };
  232. })(this);
  233. </script>
  234. </body>
  235. </html>