game.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. var BrowerObj = function () {
  2. this.ua = navigator.userAgent.toLowerCase(); //设置UA
  3. this.isInvaliBrower = !((/chrome/).test(this.ua) || (/safari/).test(this.ua) || (/mqqbrowser/).test(this.ua)); //返回true,false 是否为禁止使用浏览器
  4. this.isMobile = (/mobile/).test(this.ua); //是否为移动浏览器
  5. this.isIphone = (/iphone/).test(this.ua); //是否为IPhone手机
  6. this.isAndroid = (/android/).test(this.ua);
  7. this.isQQ = (/mqqbrowssser/).test(this.ua);
  8. this.isPhone = function () {
  9. if (brower.isPhone == false && brower.isAndroid == false) {
  10. return false;
  11. } else {
  12. return true;
  13. }
  14. }; //是否手机浏览
  15. this.InvaliBrower = function () {
  16. if (this.isInvaliBrower) {
  17. }
  18. };
  19. this.clickEventName = this.isMobile ? "touchstart" : "click";
  20. this.downEventName = this.isMobile ? "touchstart" : "mousedown";
  21. this.upEventName = this.isMobile ? "touchend" : "mouseup";
  22. this.moveEventName = this.isMobile ? "touchmove" : "mousemove";
  23. this.clickDownEventName = this.isMobile ? "touchend" : "click";
  24. this.outEventName = this.isMobile ? "touchcancel" : "mouseout";
  25. }
  26. var brower = new BrowerObj();
  27. var loadedimg;
  28. var imglist = new Array();
  29. var fishList = new Array(); //正在鱼塘运行的鱼集合
  30. var imgfilelist =
  31. ["bg.png",
  32. "big_f1_l.png",
  33. "big_f1_r.png",
  34. "big_f2_l.png",
  35. "big_f2_r.png",
  36. "big_f3_l.png",
  37. "big_f3_r.png",
  38. "big_f4_l.png",
  39. "big_f4_r.png",
  40. "bubble.png",
  41. "close.png",
  42. "continue.png",
  43. "descript.png",
  44. "down.png",
  45. "exit.png",
  46. "exitgame.png",
  47. "gameover.png",
  48. "go.png",
  49. "hand.png",
  50. "hdbg2.png",
  51. "hdbg.png",
  52. "main2.png",
  53. "main.png",
  54. "no.png",
  55. "other_f1_l.png",
  56. "other_f1_r.png",
  57. "other_f2_l.png",
  58. "other_f2_r.png",
  59. "other_f3_l.png",
  60. "other_f3_r.png",
  61. "other_f4_l.png",
  62. "other_f4_r.png",
  63. "other_f5_l.png",
  64. "other_f5_r.png",
  65. "over.png",
  66. "pausedgame.png",
  67. "score.png",
  68. "shark_move_l.png",
  69. "shark_move_r.png",
  70. "shark_up_l.png",
  71. "shark_up_r.png",
  72. "small_f1_l.png",
  73. "small_f1_r.png",
  74. "small_f2_l.png",
  75. "small_f2_r.png",
  76. "small_f3_l.png",
  77. "small_f3_r.png",
  78. "small_f4_l.png",
  79. "small_f4_r.png",
  80. "small_f5_l.png",
  81. "small_f5_r.png",
  82. "small_f6_l.png",
  83. "small_f6_r.png",
  84. "startfish.png",
  85. "timer.png",
  86. "up.png",
  87. "victory.png",
  88. "water.png",
  89. "yes.png",
  90. "nums/0.png",
  91. "nums/1.png",
  92. "nums/2.png",
  93. "nums/3.png",
  94. "nums/4.png",
  95. "nums/5.png",
  96. "nums/6.png",
  97. "nums/7.png",
  98. "nums/8.png",
  99. "nums/9.png",
  100. "main3.png",
  101. "main4.png",
  102. "startfish.jpg"];
  103. var context;
  104. var loaded = 0;
  105. var poolright = 300; //池潭右边界
  106. var poolleft = -80; //池潭左边界
  107. var height = brower.isIphone == true ? 170 : 220; //池潭深度
  108. var timer = brower.isIphone == true ? 30 : 60; //刷新频率
  109. var score = 0; //得分成绩
  110. var isStop = false; //是否游戏结束
  111. var bubbleplaynum = 0; //水泡播放进度
  112. var OneLoad = 1; //是否第一次加载页面
  113. //鱼对象
  114. var fishObj = function (id, imgid, speed, direction, sizeindex, x, y, w, h, status, weight) {
  115. this.id = id;
  116. this.imgid = imgid;
  117. this.speed = speed;
  118. this.direction = direction;
  119. this.sizeindex = sizeindex;
  120. this.x = x;
  121. this.y = y;
  122. this.w = w;
  123. this.h = h;
  124. this.status = status;
  125. this.weight = weight;
  126. }
  127. //玩家对象
  128. var MainObj = function () {
  129. this.direction = 2;
  130. this.status = -1;
  131. this.x = 130;
  132. this.y = 80;
  133. this.defaultY = 80;
  134. this.speed = brower.isIphone == true ? 100 : 105;
  135. this.lese = 0;
  136. this.isShark = 0;
  137. }
  138. //鲨鱼
  139. var SharkObj = function () {
  140. this.flag = 0;
  141. this.direction = 1;
  142. this.speed = 4;
  143. this.x = 30;
  144. this.y = 180;
  145. this.w = 30;
  146. this.h = 20;
  147. this.status = 0;
  148. this.playnum = 10;
  149. }
  150. var mainObj = new MainObj();
  151. var sharkObj = new SharkObj();
  152. brower.InvaliBrower();
  153. $(document).ready(function (e) {
  154. setInterval(function () { window.scrollTo(0, 2); }, 500);
  155. context = document.getElementById("mycanvas");
  156. if (context.getContext) {
  157. context = context.getContext("2d");
  158. loadedimg = new Image();
  159. loadedimg.src = 'img/load.png';
  160. loadedimg.onload=drawLoaded;
  161. loadImages();
  162. } else {
  163. alert("is Not");
  164. }
  165. });
  166. //点击钓鱼事件
  167. function Start(e) {
  168. e.preventDefault();
  169. var x = 0;
  170. var x_2 = 0;
  171. var y_2 = 0;
  172. if (window.innerWidth > 320) {
  173. if (brower.isIphone == false && brower.isMobile == false) {
  174. x_2 = e.clientX;
  175. y_2 = parseInt(event.clientY);
  176. } else {
  177. x_2 = event.touches[0].clientX;
  178. y_2 = parseInt(event.touches[0].clientY);
  179. }
  180. x = x_2 - parseInt((window.innerWidth - 320) / 2);
  181. } else {
  182. if (brower.isIphone == false && brower.isMobile == false) {
  183. x_2 = parseInt(event.clientX);
  184. y_2 = parseInt(event.clientY);
  185. } else {
  186. x_2 = parseInt(event.touches[0].clientX);
  187. y_2 = parseInt(event.touches[0].clientY);
  188. }
  189. x = x_2;
  190. }
  191. var need_y1 = 0;
  192. var need_y2 = 40;
  193. var need_x1 = 260;
  194. var need_x2 = 300;
  195. if(brower.isQQ==true){
  196. need_y1 = -30;
  197. need_y2 = 30;
  198. need_x1 = 290;
  199. need_x2 = 340;
  200. }
  201. if (x >= need_x1 && x <= need_x2 && y_2 >= need_y1 && y_2 <= need_y2) {
  202. jQuery("#mycanvas").unbind(brower.clickEventName);
  203. drawMsg(35);
  204. } else if (mainObj.status == -1 && mainObj.y == mainObj.defaultY) {
  205. if (x <= 75) {
  206. mainObj.direction = 0;
  207. mainObj.x = 50;
  208. }
  209. if (x > 75 && x <= 125) {
  210. mainObj.direction = 1;
  211. mainObj.x = 90;
  212. }
  213. if (x > 125 && x <= 170) {
  214. mainObj.direction = 2;
  215. mainObj.x = 130;
  216. }
  217. if (x > 170 && x <= 210) {
  218. mainObj.direction = 3;
  219. mainObj.x = 180;
  220. }
  221. if (x > 210) {
  222. mainObj.direction = 4;
  223. mainObj.x = 200;
  224. }
  225. mainObj.status = 0;
  226. }
  227. }
  228. //加载图片
  229. function loadImages() {
  230. var imgOnload = function () {
  231. this.onload = null;
  232. ld++;
  233. loaded = ld;
  234. }
  235. for (var i = 0, ld = 0; i < imgfilelist.length; i++) {
  236. var img = new Image();
  237. img.onload = imgOnload;
  238. img.src = "img/" + imgfilelist[i];
  239. if (img.complete) {
  240. img.onload();
  241. }
  242. imglist.push(img);
  243. }
  244. }
  245. //玩家钓鱼动作
  246. function MainTimer() {
  247. var sx = mainObj.status > 0 ? mainObj.status * 46 : 0;
  248. if (mainObj.status == 3) {
  249. mainObj.y = parseInt(mainObj.y - ((mainObj.speed) * timer) / 100);
  250. if (mainObj.lese == 1) {
  251. if (mainObj.direction < 3)
  252. context.drawImage(imglist[32], 0, 0, 280, 226, mainObj.x - 16, mainObj.y + 15, 50, 50);
  253. else
  254. context.drawImage(imglist[33], 0, 0, 280, 226, mainObj.x, mainObj.y + 15, 50, 50);
  255. }
  256. if (mainObj.y <= mainObj.defaultY) {
  257. mainObj.y = mainObj.defaultY;
  258. mainObj.status = -1;
  259. if (mainObj.lese == 1) {
  260. mainObj.lese = 0;
  261. score - 2 < 0 ? score = 0 : score -= 2;
  262. }
  263. else {
  264. if (fishList.length > 0) {
  265. for (var i = 0; i < fishList.length; i++) {
  266. if (fishList[i].status == 1) {
  267. switch (fishList[i].sizeindex) {
  268. case -1: { score += 3; break; }
  269. case 0: { score += 1; break; }
  270. case 1: { score += 5; break; }
  271. }
  272. fishList.splice(i, 1); //成功吊到了一只鱼
  273. }
  274. }
  275. }
  276. }
  277. }
  278. }
  279. if (mainObj.status == 0) {
  280. mainObj.y = parseInt(mainObj.y + ((mainObj.speed - 90) * timer) / 100);
  281. //钓到鱼了
  282. if (fishList.length > 0) {
  283. for (var i = 0; i < fishList.length; i++) {
  284. if ((mainObj.x + 15 >= fishList[i].x) && (mainObj.x + 15 <= fishList[i].x + fishList[i].w) && (mainObj.y + 10 >= fishList[i].y && mainObj.y + 10 <= fishList[i].y + fishList[i].h)) {
  285. fishList[i].status = 1;
  286. mainObj.status = mainObj.status + 1;
  287. break;
  288. }
  289. }
  290. }
  291. if (mainObj.y >= height + 260) {
  292. mainObj.y = height + 260;
  293. mainObj.status = 3;
  294. mainObj.lese = 1;
  295. }
  296. //钓到鲨鱼
  297. if (((sharkObj.x >= mainObj.x && sharkObj.x <= mainObj.x + 46) || ((sharkObj.x + sharkObj.w >= mainObj.x) && (sharkObj.x + sharkObj.w <= mainObj.x + 46))) && ((sharkObj.y >= mainObj.y && sharkObj.y <= mainObj.y + 46) || sharkObj.y + sharkObj.h >= mainObj.y) && (sharkObj.y + sharkObj.h <= mainObj.y + 46)) {
  298. sharkObj.status = 1;
  299. if (sharkObj.x > 150) {
  300. sharkObj.flag = 3;
  301. } else {
  302. sharkObj.flag = 1;
  303. }
  304. mainObj.isShark = 1;
  305. mainObj.status = 3;
  306. }
  307. } else if (mainObj.status > 0 && mainObj.status < 3) {
  308. mainObj.status = mainObj.status + 1;
  309. }
  310. context.beginPath();
  311. var qx;
  312. switch (mainObj.direction) {
  313. case 0: { qx = 65; break; }
  314. case 1: { qx = 107; break; }
  315. case 2: { qx = 150; break; }
  316. case 3: { qx = 195; break; }
  317. case 4: { qx = 220; break; }
  318. }
  319. context.moveTo(qx, 0);
  320. context.lineTo(mainObj.x + 18, mainObj.y);
  321. context.globalAlpha = 1;
  322. context.lineWidth = 1;
  323. context.stroke();
  324. context.closePath();
  325. context.drawImage(imglist[18], sx, 0, 46, 48, mainObj.x, mainObj.y, 35, 35);
  326. }
  327. //总贞定时器
  328. function runTimer() {
  329. if (isStop == false) {
  330. context.clearRect(0, 0, 320, 500);
  331. context.drawImage(imglist[0], 0, 0, 480, 800, 0, 0, 320, 600); //画背景
  332. context.drawImage(imglist[12], 0, 0, 152, 226, 0, 0, 105, 170); //画说明面板
  333. context.drawImage(imglist[55], 0, 0, 30, 34, 37, 145, 20, 22); //说明面板收缩箭头
  334. context.drawImage(imglist[36], 0, 0, 144, 191, 220, -10, 100, 120); //画分数面板
  335. context.drawImage(imglist[55], 0, 0, 30, 34, 268, 85, 20, 22); //分数面板收缩箭头
  336. if (mainObj.isShark > 0) {
  337. context.drawImage(imglist[70], mainObj.isShark == 1 ? 430 : 0, 0, 300, 261, 90, -30, 200, 200);
  338. mainObj.isShark++;
  339. } else if (mainObj.lese == 1) {
  340. context.drawImage(imglist[69], 300 * mainObj.direction, 0, 300, 290, 50, -30, 200, 200); //画玩家人物 钓到臭鞋
  341. } else {
  342. context.drawImage(imglist[22], 300 * mainObj.direction, 0, 300, 290, 50, -30, 200, 200); //画玩家人物 钓到鱼
  343. }
  344. //如果池潭鱼的数量小于3只 增加新的鱼
  345. if (fishList.length < 3) {
  346. newFish();
  347. }
  348. var op_x;
  349. var op_y;
  350. for (var i = 0; i < fishList.length; i++) {
  351. //判断是否被抓到了
  352. if (fishList[i].status == 1) {
  353. switch (fishList[i].id) {
  354. case 1: { fishList[i].y = mainObj.y + 5; break; }
  355. case 2: { fishList[i].y = mainObj.y + 4; break; }
  356. case 3: { fishList[i].y = mainObj.y; break; }
  357. case 4: { fishList[i].y = mainObj.y; break; }
  358. case 5: { fishList[i].y = mainObj.y + 12; break; }
  359. case 6: { fishList[i].y = mainObj.y + 10; break; }
  360. case 7: { fishList[i].y = mainObj.y; break; }
  361. case 8: { fishList[i].y = mainObj.y + 10; break; }
  362. case 9: { fishList[i].y = mainObj.y + 5; break; }
  363. case 10: { fishList[i].y = mainObj.y + 10; break; }
  364. case 11: { fishList[i].y = mainObj.y; break; }
  365. case 12: { fishList[i].y = mainObj.y + 10; break; }
  366. }
  367. fishList[i].x = fishList[i].w > 46 ? mainObj.x - (fishList[i].w - 46) : mainObj.x + 5;
  368. context.drawImage(imglist[fishList[i].imgid], 0, 0, 280, 226, fishList[i].x, fishList[i].y, fishList[i].w, fishList[i].h);
  369. } else {
  370. if (fishList[i].direction == 1) {
  371. if (fishList[i].x >= poolright) {
  372. context.drawImage(imglist[fishList[i].imgid], 0, 0, 280, 226, fishList[i].x, fishList[i].y, fishList[i].w, fishList[i].h);
  373. fishList.splice(i, 1); //游到目标点了
  374. } else {
  375. fishList[i].x = (fishList[i].x + ((fishList[i].speed * timer) / 100) * 4);
  376. context.drawImage(imglist[fishList[i].imgid], 0, 0, 280, 226, fishList[i].x, fishList[i].y, fishList[i].w, fishList[i].h);
  377. }
  378. } else {
  379. if (fishList[i].x <= poolleft) {
  380. context.drawImage(imglist[fishList[i].imgid], 0, 0, 280, 226, fishList[i].x, fishList[i].y, fishList[i].w, fishList[i].h);
  381. fishList.splice(i, 1); //游到目标点了
  382. } else {
  383. fishList[i].x = (fishList[i].x - ((fishList[i].speed * timer) / 100) * 4);
  384. context.drawImage(imglist[fishList[i].imgid], 0, 0, 280, 226, fishList[i].x, fishList[i].y, fishList[i].w, fishList[i].h);
  385. }
  386. }
  387. }
  388. }
  389. if (mainObj.isShark == 0) {
  390. MainTimer();
  391. }
  392. drawBubble();
  393. if (brower.isIphone == true)
  394. context.drawImage(imglist[19], 0, 0, 480, 263, 0, 178, 320, 240);
  395. else
  396. context.drawImage(imglist[19], 0, 0, 480, 263, 0, 260, 320, 240);
  397. sharkTimer();
  398. drawScore(); //画分数
  399. context.drawImage(imglist[35], 0, 0, 60, 79, 280, 0, 35, 35);
  400. if (score >= 200) {
  401. drawMsg(56);
  402. Gamehub.Score.submitHide(score); //加分
  403. //Gamehub.Score.submit(score); //加分
  404. }
  405. }
  406. setTimeout("runTimer()", timer);
  407. }
  408. //新出一条鱼
  409. function newFish() {
  410. var fish; //随机生成的鱼对象
  411. var direction = parseInt(Math.random() * 2 + 1); //方向10=左 2=右
  412. var x;
  413. var y; //生成鱼在池潭的深处值
  414. var op_speed;
  415. var op_height;
  416. var op_width;
  417. var op_sizeindex;
  418. var op_weight;
  419. var isConDe = false; //重叠 = false, 不重叠 = true;
  420. var op_imgid;
  421. var op_id = parseInt(Math.random() * 12 + 1);
  422. switch (op_id) {
  423. case 1: { op_imgid = (direction == 2 ? 1 : 2); op_width = 80; op_height = 55; op_speed = 5; op_sizeindex = 1; op_weight = 15; break; }
  424. case 2: { op_imgid = (direction == 2 ? 3 : 4); op_width = 60; op_height = 50; op_speed = 5; op_sizeindex = 1; op_weight = 16; break; }
  425. case 3: { op_imgid = (direction == 2 ? 5 : 6); op_width = 80; op_height = 55; op_speed = 4; op_sizeindex = 1; op_weight = 16; break; }
  426. case 4: { op_imgid = (direction == 2 ? 7 : 8); op_width = 60; op_height = 50; op_speed = 4; op_sizeindex = 1; op_weight = 15; break; }
  427. case 5: { op_imgid = (direction == 2 ? 41 : 42); op_width = 50; op_height = 35; op_speed = 2; op_sizeindex = -1; op_weight = 10; break; }
  428. case 6: { op_imgid = (direction == 2 ? 43 : 44); op_width = 50; op_height = 35; op_speed = 1; op_sizeindex = -1; op_weight = 10; break; }
  429. case 7: { op_imgid = (direction == 2 ? 45 : 46); op_width = 50; op_height = 35; op_speed = 1; op_sizeindex = -1; op_weight = 8; break; }
  430. case 8: { op_imgid = (direction == 2 ? 47 : 48); op_width = 50; op_height = 35; op_speed = 3; op_sizeindex = -1; op_weight = 9; break; }
  431. case 9: { op_imgid = (direction == 2 ? 49 : 50); op_width = 50; op_height = 35; op_speed = 5; op_sizeindex = -1; op_weight = 11; break; }
  432. case 10: { op_imgid = (direction == 2 ? 26 : 27); op_width = 40; op_height = 30; op_speed = 1; op_sizeindex = 0; op_weight = 5; break; }
  433. case 11: { op_imgid = (direction == 2 ? 28 : 29); op_width = 70; op_height = 60; op_speed = 1; op_sizeindex = 0; op_weight = 6; break; }
  434. case 12: { op_imgid = (direction == 2 ? 30 : 31); op_width = 40; op_height = 30; op_speed = 1; op_sizeindex = 0; op_weight = 8; break; }
  435. }
  436. op_speed = 2;
  437. while (!isConDe) {
  438. y = parseInt(Math.random() * height + 220);
  439. isConDe = true;
  440. if (fishList.length > 0) {
  441. for (var i = 0; i < fishList.length; i++) {
  442. if (((y >= fishList[i].y && y <= (fishList[i].y + fishList[i].h)) ||
  443. ((y + op_height) >= fishList[i].y && (y + op_height) <= (fishList[i].y + fishList[i].h)))
  444. &&
  445. ((direction == fishList[i].direction && op_speed <= fishList[i].speed) || ((direction != fishList[i].direction) && (op_speed >= fishList[i].speed)))
  446. ) {
  447. isConDe = false;
  448. break;
  449. }
  450. }
  451. }
  452. }
  453. if (direction == 1) {
  454. x = -80;
  455. } else {
  456. x = 300;
  457. }
  458. fish = new fishObj(op_id, op_imgid, op_speed, direction, op_sizeindex, x, y, op_width, op_height, 0, op_weight); //鱼对象
  459. fishList.push(fish);
  460. }
  461. //画鲨鱼
  462. function sharkTimer() {
  463. if (sharkObj.status == 0) {
  464. if (sharkObj.direction == 1) {
  465. sharkObj.x = (sharkObj.x + (sharkObj.speed * timer) / 100);
  466. if (sharkObj.x >= poolright - 70) {
  467. sharkObj.direction = 2;
  468. }
  469. } else {
  470. sharkObj.x = (sharkObj.x - (sharkObj.speed * timer) / 100);
  471. if (sharkObj.x <= poolleft + 110) {
  472. sharkObj.direction = 1;
  473. }
  474. }
  475. if (sharkObj.flag <= 0)
  476. sharkObj.flag = 166;
  477. else
  478. sharkObj.flag = sharkObj.flag - 83;
  479. context.drawImage(sharkObj.direction == 1 ? imglist[38] : imglist[37], sharkObj.flag, 0, 80, 41, sharkObj.x, sharkObj.y, 40, 30);
  480. } else {
  481. var imgindex;
  482. var x;
  483. if (sharkObj.x > 150) {
  484. x = 100;
  485. imgindex = 40;
  486. if (sharkObj.playnum > 0) {
  487. if (sharkObj.flag == 1) {
  488. sharkObj.flag = 3;
  489. sharkObj.playnum--;
  490. } else {
  491. sharkObj.flag--;
  492. }
  493. } else {
  494. drawMsg(16);
  495. }
  496. } else {
  497. x = 0;
  498. imgindex = 39;
  499. if (sharkObj.playnum > 0) {
  500. if (sharkObj.flag == 3) {
  501. sharkObj.flag = 1;
  502. sharkObj.playnum--;
  503. } else {
  504. sharkObj.flag++;
  505. }
  506. } else {
  507. drawMsg(16);
  508. }
  509. }
  510. context.drawImage(imglist[imgindex], 271 * sharkObj.flag, 0, 270, 151, x, 110, 200, 120);
  511. }
  512. }
  513. //画分数
  514. function drawScore() {
  515. var bits = score % 10;
  516. var ten = parseInt((score % 100) * 0.1);
  517. context.drawImage(imglist[59 + ten], 0, 0, 19, 38, 262, 50, 18, 30); //分数 (十位)
  518. context.drawImage(imglist[59 + bits], 0, 0, 19, 38, 275, 50, 18, 30); //分数 (个位)
  519. if (score >= 10) {
  520. sharkObj.speed = 7;
  521. }
  522. if (score >= 20) {
  523. sharkObj.speed = 10;
  524. }
  525. if (score >= 40) {
  526. sharkObj.speed = 12;
  527. }
  528. if (score >= 53) {
  529. sharkObj.speed = 15;
  530. }
  531. if (score >= 69) {
  532. sharkObj.speed = 17;
  533. }
  534. if (score >= 99) {
  535. sharkObj.speed = 20;
  536. }
  537. if (score >= 189) {
  538. sharkObj.speed = 25;
  539. }
  540. }
  541. //画水泡
  542. function drawBubble() {
  543. //context.drawImage(imglist[9],60*17,0,30,221,0,200,30,221);
  544. }
  545. //弹出对话框
  546. function drawMsg(imgindex) {
  547. isStop = true;
  548. context.globalAlpha = 0.5;
  549. context.fillStyle = '#000';
  550. context.fillRect(0, 0, 320, 500);
  551. context.globalAlpha = 0.8;
  552. context.fillStyle = '#FC6';
  553. context.fillRect(20, 190, 280, 150);
  554. context.globalAlpha = 1.0;
  555. context.fillStyle = '#FFC';
  556. context.fillRect(35, 205, 250, 120);
  557. context.drawImage(imglist[imgindex], 0, 0, 258, 79, 60, 210, 200, 60); //文字
  558. if (imgindex == 35) {
  559. //context.drawImage(imglist[11], 0, 0, 130, 81, 60, 270, 80, 50); //继续按钮
  560. context.drawImage(imglist[11], 0, 0, 130, 81, 120, 270, 80, 50); //继续按钮
  561. } else {
  562. //context.drawImage(imglist[34], 0, 0, 130, 81, 60, 270, 80, 50); //重来按钮
  563. context.drawImage(imglist[34], 0, 0, 130, 81, 120, 270, 80, 50); //重来按钮
  564. }
  565. //context.drawImage(imglist[14], 0, 0, 130, 81, 170, 270, 80, 50); //退出按钮
  566. if (imgindex == 35) {
  567. //jQuery("#mycanvas").bind(brower.downEventName, MsgDownClick_Continue);
  568. //jQuery("#mycanvas").bind(brower.upEventName, MsgUpClick_Continue);
  569. jQuery("#mycanvas").bind(brower.clickEventName, MsgClick_Continue);
  570. } else {
  571. //jQuery("#mycanvas").bind(brower.downEventName, MsgDownClick);
  572. // jQuery("#mycanvas").bind(brower.upEventName, MsgUpClick);
  573. jQuery("#mycanvas").bind(brower.clickEventName, MsgClick);
  574. }
  575. }
  576. //按下按钮事件 重来
  577. function MsgDownClick(e) {
  578. e.preventDefault();
  579. var x = 0;
  580. var y = 0;
  581. if (brower.isMobile == false && brower.isIphone == false) {
  582. x = e.clientX - (window.innerWidth - 320) / 2;
  583. y = e.clientY;
  584. } else {
  585. x = event.touches[0].clientX - (window.innerWidth - 320) / 2;
  586. y = event.touches[0].clientY;
  587. }
  588. var need_y1 = 270;
  589. var need_y2 = 320;
  590. if (brower.isQQ==true){
  591. need_y1 = 230;
  592. need_y2 = 280;
  593. }
  594. if (x >= 60 && x <= 140 && y >= need_y1 && y <= need_y2) {
  595. context.clearRect(60, 270, 80, 50);
  596. context.drawImage(imglist[34], 130, 0, 130, 81, 60, 270, 80, 50);
  597. }
  598. if (x >= 170 && x <= 250 && y >= need_y1 && y <= need_y2) {
  599. context.clearRect(170, 270, 80, 50);
  600. context.drawImage(imglist[14], 130, 0, 130, 81, 170, 270, 80, 50);
  601. }
  602. }
  603. //按下按钮事件 继续
  604. function MsgDownClick_Continue(e) {
  605. e.preventDefault();
  606. var x = 0;
  607. var y = 0;
  608. if (brower.isMobile == false && brower.isIphone == false) {
  609. x = e.clientX - (window.innerWidth - 320) / 2;
  610. y = e.clientY;
  611. } else {
  612. x = event.touches[0].clientX - (window.innerWidth - 320) / 2;
  613. y = event.touches[0].clientY;
  614. }
  615. var need_y1 = 270;
  616. var need_y2 = 320;
  617. if (brower.isQQ==true){
  618. need_y1 = 230;
  619. need_y2 = 280;
  620. }
  621. if (x >= 60 && x <= 140 && y >= need_y1 && y <= need_y2) {
  622. context.clearRect(60, 270, 80, 50);
  623. context.drawImage(imglist[11], 130, 0, 130, 81, 60, 270, 80, 50);
  624. }
  625. if (x >= 170 && x <= 250 && y >= need_y1 && y <= need_y2) {
  626. context.clearRect(170, 270, 80, 50);
  627. context.drawImage(imglist[14], 130, 0, 130, 81, 170, 270, 80, 50);
  628. }
  629. }
  630. //放开按钮事件 重来
  631. function MsgUpClick(e) {
  632. e.preventDefault();
  633. var x = 0;
  634. var y = 0;
  635. if (brower.isMobile == false && brower.isIphone == false) {
  636. x = e.clientX - (window.innerWidth - 320) / 2;
  637. y = e.clientY;
  638. } else {
  639. x = event.touches[0].clientX - (window.innerWidth - 320) / 2;
  640. y = event.touches[0].clientY;
  641. }
  642. var need_y1 = 270;
  643. var need_y2 = 320;
  644. if (brower.isQQ==true){
  645. need_y1 = 230;
  646. need_y2 = 280;
  647. }
  648. if (x >= 60 && x <= 140 && y >= need_y1 && y <= need_y2) {
  649. context.clearRect(60, 270, 80, 50);
  650. context.drawImage(imglist[34], 0, 0, 130, 81, 60, 270, 80, 50);
  651. }
  652. if (x >= 170 && x <= 250 && y >= need_y1 && y <= need_y2) {
  653. context.clearRect(170, 270, 80, 50);
  654. context.drawImage(imglist[14], 0, 0, 130, 81, 170, 270, 80, 50);
  655. }
  656. }
  657. //放开按钮事件 继续
  658. function MsgUpClick_Continue(e) {
  659. e.preventDefault();
  660. var x = 0;
  661. var y = 0;
  662. if (brower.isMobile == false && brower.isIphone == false) {
  663. x = e.clientX - (window.innerWidth - 320) / 2;
  664. y = e.clientY;
  665. } else {
  666. x = event.touches[0].clientX - (window.innerWidth - 320) / 2;
  667. y = event.touches[0].clientY;
  668. }
  669. var need_y1 = 270;
  670. var need_y2 = 320;
  671. if (brower.isQQ==true){
  672. need_y1 = 230;
  673. need_y2 = 280;
  674. }
  675. if (x >= 60 && x <= 140 && y >= need_y1 && y <= need_y2) {
  676. context.clearRect(60, 270, 80, 50);
  677. context.drawImage(imglist[11], 0, 0, 130, 81, 60, 270, 80, 50);
  678. }
  679. if (x >= 170 && x <= 250 && y >= need_y1 && y <= need_y2) {
  680. context.clearRect(170, 270, 80, 50);
  681. context.drawImage(imglist[14], 0, 0, 130, 81, 170, 270, 80, 50);
  682. }
  683. }
  684. //按钮单击事件 重来
  685. function MsgClick(e) {
  686. e.preventDefault();
  687. var x = 0;
  688. var y = 0;
  689. if (brower.isMobile == false && brower.isIphone == false) {
  690. x = e.clientX - (window.innerWidth - 320) / 2;
  691. y = e.clientY;
  692. } else {
  693. x = event.touches[0].clientX - (window.innerWidth - 320) / 2;
  694. y = event.touches[0].clientY;
  695. }
  696. var need_y1 = 270;
  697. var need_y2 = 320;
  698. if (brower.isQQ==true){
  699. need_y1 = 230;
  700. need_y2 = 280;
  701. }
  702. // if (x >= 60 && x <= 140 && y >= need_y1 && y <= need_y2) {
  703. // score = 0;
  704. // sharkObj = new SharkObj();
  705. // mainObj = new MainObj();
  706. // fishList = [];
  707. // isStop = false;
  708. // jQuery("#mycanvas").unbind(brower.downEventName);
  709. // jQuery("#mycanvas").unbind(brower.upEventName);
  710. // jQuery("#mycanvas").unbind(brower.clickEventName);
  711. // jQuery("#mycanvas").bind(brower.clickEventName, Start);
  712. // //Gamehub.Score.submitHide(score);
  713. // }
  714. // if (x >= 170 && x <= 250 && y >= need_y1 && y <= need_y2) {
  715. // if (score > 0) {
  716. // Gamehub.Score.submit(score);
  717. // } else {
  718. // window.location.href = "http://yx8.com" + getLXT();
  719. // }
  720. // }
  721. if (x >= 120 && x <= 200 && y >= need_y1 && y <= need_y2) {
  722. if (score > 0) {
  723. Gamehub.Score.submitHide(score);
  724. }
  725. resetGame();
  726. }
  727. }
  728. function resetGame () {
  729. score = 0;
  730. sharkObj = new SharkObj();
  731. mainObj = new MainObj();
  732. fishList = [];
  733. isStop = false;
  734. jQuery("#mycanvas").unbind(brower.downEventName);
  735. jQuery("#mycanvas").unbind(brower.upEventName);
  736. jQuery("#mycanvas").unbind(brower.clickEventName);
  737. jQuery("#mycanvas").bind(brower.clickEventName, Start);
  738. }
  739. function exitGame () {
  740. if (score > 0) {
  741. Gamehub.Score.submitHide(score);
  742. }
  743. window.location.href = "http://yx8.com" + getLXT();
  744. }
  745. function exitGame2 () {
  746. if (score > 0) {
  747. Gamehub.Score.submitHide(score);
  748. }
  749. DrawOneLoad();
  750. }
  751. //按钮单击事件 继续
  752. function MsgClick_Continue(e) {
  753. e.preventDefault();
  754. var x = 0;
  755. var y = 0;
  756. if (brower.isMobile == false && brower.isIphone == false) {
  757. x = e.clientX - (window.innerWidth - 320) / 2;
  758. y = e.clientY;
  759. } else {
  760. x = event.touches[0].clientX - (window.innerWidth - 320) / 2;
  761. y = event.touches[0].clientY;
  762. }
  763. var need_y1 = 270;
  764. var need_y2 = 320;
  765. if (brower.isQQ==true){
  766. need_y1 = 230;
  767. need_y2 = 280;
  768. }
  769. // if (x >= 60 && x <= 140 && y >= need_y1 && y<= need_y2) {
  770. // isStop = false;
  771. // jQuery("#mycanvas").unbind(brower.downEventName);
  772. // jQuery("#mycanvas").unbind(brower.upEventName);
  773. // jQuery("#mycanvas").unbind(brower.clickEventName);
  774. // jQuery("#mycanvas").bind(brower.clickEventName, Start);
  775. // }
  776. // if (x >= 170 && x <= 250 && y >= need_y1 && y <= need_y2) {
  777. // if (score > 0) {
  778. // Gamehub.Score.submit(score);
  779. // } else {
  780. // window.location.href = "http://yx8.com" + getLXT();
  781. // }
  782. // }
  783. if (x >= 120 && x <= 200 && y >= need_y1 && y <= need_y2) {
  784. isStop = false;
  785. jQuery("#mycanvas").unbind(brower.downEventName);
  786. jQuery("#mycanvas").unbind(brower.upEventName);
  787. jQuery("#mycanvas").unbind(brower.clickEventName);
  788. jQuery("#mycanvas").bind(brower.clickEventName, Start);
  789. }
  790. }
  791. //按钮单击事件 开始游戏
  792. function MsgClick_Start(e) {
  793. e.preventDefault();
  794. var x = 0;
  795. var y = 0;
  796. if (brower.isMobile == false && brower.isIphone == false) {
  797. x = e.clientX - (window.innerWidth - 320) / 2;
  798. y = e.clientY;
  799. } else {
  800. x = event.touches[0].clientX - (window.innerWidth - 320) / 2;
  801. y = event.touches[0].clientY;
  802. }
  803. var need_y1 = 200;
  804. var need_y2 = 240;
  805. if (brower.isQQ==true){
  806. need_y1 = 160;
  807. need_y2 = 200;
  808. }
  809. // if (x >= 30 && x <= 150 && y >= need_y1 && y <= need_y2) {
  810. // jQuery("#mycanvas").unbind(brower.clickEventName);
  811. // drawDescore();
  812. // }
  813. if (x >= 100 && x <= 220 && y >= need_y1 && y <= need_y2) {
  814. jQuery("#mycanvas").unbind(brower.clickEventName);
  815. drawDescore();
  816. }
  817. if (x >= 170 && x <= 290 && y >= need_y1 && y <= need_y2) {
  818. //window.location.href = "http://yx8.com" + getLXT();
  819. }
  820. }
  821. function drawDescore() {
  822. isStop = true;
  823. context.globalAlpha = 0.5;
  824. context.fillStyle = '#000';
  825. context.fillRect(0, 0, 320, 500);
  826. context.globalAlpha = 0.8;
  827. context.fillStyle = '#FC6';
  828. context.fillRect(20, 90, 280, 250);
  829. context.globalAlpha = 1.0;
  830. context.fillStyle = '#FFC';
  831. context.fillRect(35, 105, 250, 220);
  832. context.drawImage(imglist[2], 0, 0, 280, 226, 50, 120, 100, 80);
  833. context.drawImage(imglist[44], 0, 0, 280, 226, 50, 180, 100, 80);
  834. context.drawImage(imglist[37], 0, 0, 74, 40, 60, 255, 74, 40);
  835. context.drawImage(imglist[58], 0, 0, 91, 85, 190, 110, 70, 70);
  836. context.drawImage(imglist[58], 0, 0, 91, 85, 190, 170, 70, 70);
  837. context.drawImage(imglist[23], 0, 0, 91, 85, 190, 240, 70, 70);
  838. context.drawImage(imglist[10], 0, 0, 103, 104, 270, 70, 50, 50);
  839. jQuery("#mycanvas").bind(brower.clickEventName, clickDisplay);
  840. }
  841. function clickDisplay() {
  842. jQuery("#mycanvas").unbind(brower.clickEventName);
  843. jQuery("#mycanvas").bind(brower.clickEventName, Start);
  844. isStop = false;
  845. runTimer();
  846. }
  847. //画进度条
  848. function drawLoaded() {
  849. context.clearRect(0, 0, 320, 500);
  850. //context.drawImage(loadedimg, 0, 0, 250, 85, 40, 150, 250, 85);
  851. try{
  852. //context.drawImage(loadedimg, 0, 90, 250 * (loaded / imgfilelist.length), 5, 42, 201, 245 * (loaded / imgfilelist.length), 10);
  853. }catch(ex){
  854. }
  855. context.fillStyle = '#2982BC';
  856. context.font = '18px 微软雅黑';
  857. context.fillText(parseInt(loaded / imgfilelist.length * 100) + '%', 150, 255);
  858. context.fillText('正在努力加载中,请稍候', 80, 205);
  859. if (loaded < imgfilelist.length) {
  860. setTimeout("drawLoaded()", 100);
  861. } else {
  862. document.body.style.backgroundColor='#000';
  863. DrawOneLoad();
  864. }
  865. }
  866. function DrawOneLoad() {
  867. context.drawImage(imglist[71], 0, 0, 480, 800, 0, 0, 320, 480);
  868. jQuery("#mycanvas").bind(brower.clickEventName, MsgClick_Start);
  869. }
  870. function getLXT() {
  871. var url = window.location.href;
  872. var start = url.indexOf("lxt=");
  873. var urllxt;
  874. if (start !== -1)
  875. urllxt = '?' + url.substring(start);
  876. else {
  877. urllxt = "";
  878. }
  879. return urllxt;
  880. }