• 朵拉钓鱼,快来一起钓鱼


    欢迎来到程序小院

    朵拉钓鱼

    玩法:鼠标对准鱼的位置点击左键进行钓鱼,钓到不同鱼有不同分数奖励,钓到鞋子-2,钓到鲨鱼游戏结束,统计分数,快去钓鱼吧^^。
    

    开始游戏icon-default.png?t=N7T8https://www.ormcc.com/play/gameStart/195

    html

    <canvas id="gameCanvas" width="480" height="800"></canvas>
    

    css

    1. #main
    2. {
    3.     width:320px;
    4.     margin:0 auto;
    5.     background-color:#FFF;
    6. }
    7. .popup-base {
    8.     position:fixed;
    9.     top:0;
    10.     left:0;
    11.     bottom:0;
    12.     right:0;
    13.     visibility:hidden;
    14.     z-index:1000000;
    15.     opacity:1;
    16.     -moz-transition:all .3s;
    17.     -webkit-transition:opacity .3s;
    18.     -o-transition:all .3s;
    19.     transition:all .3s;
    20.     background:rgba(0,0,0,.3);
    21. }
    22. .popup-base.popup-visible {
    23.     opacity:1;
    24.     visibility:visible;
    25. }
    26. #popup-bg {
    27.     position:fixed;
    28.     top:0;
    29.     left:0;
    30.     bottom:0;
    31.     right:0;
    32. }
    33. .popup-base .dialog {
    34.     position:absolute;
    35. }
    36. .dialog-prompt {
    37.     margin-top:10px;
    38.     text-align:center;
    39. }
    40. .dialog-buttons {
    41.     padding:10px;
    42.     text-align:right;
    43.     background:-webkit-gradient(linear , 0% 0% , 0% 100%from(#E6E6E6), to(#F7F6F6));
    44.     border-bottom-left-radius:4px;
    45.     border-bottom-right-radius:4px;
    46. }
    47. .popup {
    48.     font-family:sans-serif;
    49.     font-weight:700;
    50.     text-align:center;
    51.     font-size:12px;
    52.     line-height:130%;
    53.     /* text-transform:uppercase; */
    54.     background-color:rgba(049,049,049,.7);
    55.     border-radius:6px;
    56.     -webkit-box-shadow:0px 0px 5px rgba(0,0,0,1);
    57.     z-index:999999999;
    58. }

    js

    1. //鱼对象
    2. var fishObj = function (id, imgid, speed, direction, sizeindex, x, y, w, h, status, weight) {
    3.   this.id = id;
    4.   this.imgid = imgid;
    5.   this.speed = speed;
    6.   this.direction = direction;
    7.   this.sizeindex = sizeindex;
    8.   this.x = x;
    9.   this.y = y;
    10.   this.w = w;
    11.   this.h = h;
    12.   this.status = status;
    13.   this.weight = weight;
    14. }
    15. //玩家对象
    16. var MainObj = function () {
    17.   this.direction = 2;
    18.   this.status = -1;
    19.   this.x = 130;
    20.   this.y = 80;
    21.   this.defaultY = 80;
    22.   this.speed = brower.isIphone == true ? 100 : 105;
    23.   this.lese = 0;
    24.   this.isShark = 0;
    25. }
    26. //鲨鱼
    27. var SharkObj = function () {
    28.   this.flag = 0;
    29.   this.direction = 1;
    30.   this.speed = 4;
    31.   this.x = 30;
    32.   this.y = 180;
    33.   this.w = 30;
    34.   this.h = 20;
    35.   this.status = 0;
    36.   this.playnum = 10;
    37. }
    38. var mainObj = new MainObj();
    39. var sharkObj = new SharkObj();
    40. brower.InvaliBrower();
    41. $(document).ready(function (e) {
    42.   setInterval(function () { window.scrollTo(02); }, 500);
    43.   context = document.getElementById("mycanvas");
    44.   if (context.getContext) {
    45.       context = context.getContext("2d");
    46.       loadedimg = new Image();
    47.       loadedimg.src = '/default/game/dldy/img/load.png';
    48.       loadedimg.onload=drawLoaded;        
    49.       loadImages();
    50.   } else {
    51.       alert("is Not");
    52.   }
    53. });
    54. //点击钓鱼事件
    55. function Start(e) {
    56.   e.preventDefault();
    57.   var x = 0;
    58.   var x_2 = 0;
    59.   var y_2 = 0;
    60.   if (window.innerWidth > 320) {
    61.       if (brower.isIphone == false && brower.isMobile == false) {
    62.           x_2 = e.clientX;
    63.           y_2 = parseInt(event.clientY);
    64.       } else {
    65.           x_2 = event.touches[0].clientX;
    66.           y_2 = parseInt(event.touches[0].clientY);
    67.       }
    68.       x = x_2 - parseInt((window.innerWidth - 320/ 2);
    69.   } else {
    70.       if (brower.isIphone == false && brower.isMobile == false) {
    71.           x_2 = parseInt(event.clientX);
    72.           y_2 = parseInt(event.clientY);
    73.       } else {
    74.           x_2 = parseInt(event.touches[0].clientX);
    75.           y_2 = parseInt(event.touches[0].clientY);
    76.       }
    77.       x = x_2;
    78.   }
    79.   var need_y1 = 0;
    80.   var need_y2 = 40;
    81.   var need_x1 = 260;
    82.   var need_x2 = 300;
    83.   if(brower.isQQ==true){
    84.       need_y1 = -30;
    85.       need_y2 = 30;
    86.       need_x1 = 290;
    87.       need_x2 = 340;
    88.   }
    89.   if (x >= need_x1 && x <= need_x2 && y_2 >= need_y1 && y_2 <= need_y2) {
    90.       jQuery("#mycanvas").unbind(brower.clickEventName);
    91.       drawMsg(35);
    92.   } else if (mainObj.status == -1 && mainObj.y == mainObj.defaultY) {
    93.       if (x <= 75) {
    94.           mainObj.direction = 0;
    95.           mainObj.x = 50;
    96.       }
    97.       if (x > 75 && x <= 125) {
    98.           mainObj.direction = 1;
    99.           mainObj.x = 90;
    100.       }
    101.       if (x > 125 && x <= 170) {
    102.           mainObj.direction = 2;
    103.           mainObj.x = 130;
    104.       }
    105.       if (x > 170 && x <= 210) {
    106.           mainObj.direction = 3;
    107.           mainObj.x = 180;
    108.       }
    109.       if (x > 210) {
    110.           mainObj.direction = 4;
    111.           mainObj.x = 200;
    112.       }
    113.       mainObj.status = 0;
    114.   }
    115. }
    116. //加载图片
    117. function loadImages() {
    118.   var imgOnload = function () {
    119.       this.onload = null;
    120.       ld++;
    121.       loaded = ld;
    122.   }
    123.   for (var i = 0, ld = 0; i < imgfilelist.length; i++) {
    124.       var img = new Image();
    125.       img.onload = imgOnload;
    126.       img.src = "/default/game/dldy/img/" + imgfilelist[i];
    127.       if (img.complete) {
    128.           img.onload();
    129.       }
    130.       imglist.push(img);
    131.   }
    132. }
    133. //玩家钓鱼动作
    134. function MainTimer() {
    135.   var sx = mainObj.status > 0 ? mainObj.status * 46 : 0;
    136.   if (mainObj.status == 3) {
    137.       mainObj.y = parseInt(mainObj.y - ((mainObj.speed) * timer) / 100);
    138.       if (mainObj.lese == 1) {
    139.           if (mainObj.direction < 3)
    140.               context.drawImage(imglist[32], 00280226, mainObj.x - 16, mainObj.y + 155050);
    141.           else
    142.               context.drawImage(imglist[33], 00280226, mainObj.x, mainObj.y + 155050);
    143.       }
    144.       if (mainObj.y <= mainObj.defaultY) {
    145.           mainObj.y = mainObj.defaultY;
    146.           mainObj.status = -1;
    147.           if (mainObj.lese == 1) {
    148.               mainObj.lese = 0;
    149.               score - 2 < 0 ? score = 0 : score -= 2;
    150.           }
    151.           else {
    152.               if (fishList.length > 0) {
    153.                   for (var i = 0; i < fishList.length; i++) {
    154.                       if (fishList[i].status == 1) {
    155.                           switch (fishList[i].sizeindex) {
    156.                               case -1: { score += 3; break; }
    157.                               case 0: { score += 1; break; }
    158.                               case 1: { score += 5; break; }
    159.                           }
    160.                           fishList.splice(i, 1); //成功吊到了一只鱼
    161.                       }
    162.                   }
    163.               }
    164.           }
    165.       }
    166.   }
    167.   if (mainObj.status == 0) {
    168.       mainObj.y = parseInt(mainObj.y + ((mainObj.speed - 90* timer) / 100);
    169.       //钓到鱼了
    170.       if (fishList.length > 0) {
    171.           for (var i = 0; i < fishList.length; i++) {
    172.               if ((mainObj.x + 15 >= fishList[i].x) && (mainObj.x + 15 <= fishList[i].x +
    173.               fishList[i].w) && (mainObj.y + 10 >= fishList[i].y && mainObj.y + 10 <= 
    174.               fishList[i].y + fishList[i].h)) {
    175.                   fishList[i].status = 1;
    176.                   mainObj.status = mainObj.status + 1;
    177.                   break;
    178.               }
    179.           }
    180.       }
    181.       if (mainObj.y >= height + 260) {
    182.           mainObj.y = height + 260;
    183.           mainObj.status = 3;
    184.           mainObj.lese = 1;
    185.       }
    186.       //钓到鲨鱼
    187.       if (((sharkObj.x >= mainObj.x && sharkObj.x <= mainObj.x + 46) || 
    188.       ((sharkObj.x + sharkObj.w >= mainObj.x) && (sharkObj.x + sharkObj.w <= mainObj.x + 46))) 
    189.       && ((sharkObj.y >= mainObj.y && sharkObj.y <= mainObj.y + 46) || 
    190.       sharkObj.y + sharkObj.h >= mainObj.y) && (sharkObj.y + sharkObj.h <= mainObj.y + 46)) {
    191.           sharkObj.status = 1;
    192.           if (sharkObj.x > 150) {
    193.               sharkObj.flag = 3;
    194.           } else {
    195.               sharkObj.flag = 1;
    196.           }
    197.           mainObj.isShark = 1;
    198.           mainObj.status = 3;
    199.       }
    200.   } else if (mainObj.status > 0 && mainObj.status < 3) {
    201.       mainObj.status = mainObj.status + 1;
    202.   }
    203.   context.beginPath();
    204.   var qx;
    205.   switch (mainObj.direction) {
    206.       case 0: { qx = 65; break; }
    207.       case 1: { qx = 107; break; }
    208.       case 2: { qx = 150; break; }
    209.       case 3: { qx = 195; break; }
    210.       case 4: { qx = 220; break; }
    211.   }
    212.   context.moveTo(qx, 0);
    213.   context.lineTo(mainObj.x + 18, mainObj.y);
    214.   context.globalAlpha = 1;
    215.   context.lineWidth = 1;
    216.   context.stroke();
    217.   context.closePath();
    218.   context.drawImage(imglist[18], sx, 04648, mainObj.x, mainObj.y, 3535);
    219. }

    源码icon-default.png?t=N7T8https://www.ormcc.com/

    需要源码请关注添加好友哦^ ^

    转载:欢迎来到本站,转载请注明文章出处https://ormcc.com/

  • 相关阅读:
    机器人制作开源方案 | 智能家庭防护机器人
    仿射密码 affine
    474. 一和零
    react create-react-app v5配置 px2rem (不暴露 eject方式)
    2021年5月IB考试报告出炉
    Cesium
    SpringBoot基础
    数据⼀致性模型有哪些?
    redis能否替代threadlocal
    Node历史版本下载及配置npm镜像
  • 原文地址:https://blog.csdn.net/qq_16659821/article/details/134059871