Pongo网页版JavaScript源代码及设计思路

开发 前端
这纯属又是一个自娱自乐,写完后的第三天因为开始忙着投简历找实习就没空再管,扔到朋友圈让朋友玩去了。这一个月过去了再重新看这游戏,感觉它不该就这样死掉,本人没什么技术,做得很拙略,因此发出这篇文字希望能帮到一些对pongo感兴趣的朋友,再者就是希望如果有这方面的高手看到了能够给予赐教,一切疑惑和赐教都欢迎给我留言,谢谢!

1.游戏背景介绍(写在前面的废话):

五月初的某天,看到某网推荐了这款游戏,Pongo,看着还不错的样子就用ipad下下来试玩了下,玩了两局感觉还错挺过瘾的,因为是手欠类游戏嘛大家懂的。

但是没一会发现游戏在ipad似乎有些bug,玩一会就会卡住然后只能强退了,真是揪心,记录还等着破呢。

怎么办?玩游戏不如玩自己的游戏的念头又邪恶的出现了,然后就把pad丢给了朋友虐心去,我默默回到电脑前开始动手自己写个不会卡的。

大概两小时吧,写出了基本框架,然后扔sinaapp里试了下效果基本能玩就洗洗睡了。

第二天醒来因为周末没事就花了些时间设计了下界面,同时不幸自己测出了一些比较严重的bug,最后又花了些时间给改掉了。

最后游戏取名”Pongo+“(手机党点我即玩),电脑端暂时不支持,并顺便在Github上上传了源码并去掉了提交成绩模块。

2.游戏试玩网址:

Pongo+(仅限移动端):http://mypongo.sinaapp.com/

github开源(欢迎fork让游戏更好):https://github.com/ChenReason/pongo/blob/gh-pages/index.html

3.游戏规则玩法:

点击屏幕会改变挡板的运动方向,点击一次挡板方向相应改变一次,目的是为了能刚好挡住四处滚动的小球不让其跑出大圆外。时间越长越好!最后可提交自己的成绩进行排名!

4.游戏所用技术:

HTML、CSS、JavaScript、Canvas、PHP

5.游戏设计思路:

a)运用Canvas将游戏的主界面画出,底部为一单色长方形,上面覆盖一个大圆,大圆上再绘制小圆及挡板,挡板中部还有一个大小为1px的超级小圆(作实现碰撞检测)。

b)小圆运动方向一共有8个分别为上、下、左、右、左上、左下、右上和右下。

c)挡板的运动方向只有两个,顺时针和逆时针。

d)碰撞检测未涉及到引擎的使用,而是根据小圆与挡板中部的超级小圆进行距离判断,从而实现简陋的碰撞检测。

e)小球碰撞后反弹的方向确定,利用常识列举,共8种情况。

6.游戏实现难点:

a)碰撞检测。

b)定时器setInterval的清除时机以及是否清楚彻底。

c)定时器周期长短与游戏体验的关系。

d)Android与IOS设备性能不同导致的游戏流畅度问题。

7.游戏现有问题:

a)由于碰撞检测是比较两圆的圆心距,且涉及到定时器的使用,因此由于定时器间隔极短导致在肉眼所见的一次碰撞背后其实已经发生了数十次碰撞,由此会导致小球最后实际的反弹方向与现实的物理定理有所不同,经过优化,出现的概率已经较低,但仍未能避免,因此有些玩家会发现小圆若没有很准地撞在挡板正中央则可能导致游戏失败。

b)由于函数过于冗长,运行效率较低,再加上使用定时器,因此在Andorid与iOS或其他移动端上的游戏体验不尽相同(整体来说iOS由于Android)。

c)排行榜并未实现自动实时更新。(数据库还不会用)

8.游戏界面预览:

(图1为初版,图2去掉了按钮,图3为最终版,图4为排行榜)

025513_ifYR_1476402.png

图1

025513_wGrZ_1476402.png

图2

025513_HEK6_1476402.png

图3

025514_vXHg_1476402.png

图4

#p#

9.游戏JavaScript部分源代码:

  1. var ifingame=0;   
  2. var maxgrade=0,grade=0;   
  3. var grade1,grade2;   
  4. var nickname;    
  5. var gamespeed=1.4;//小球速度   
  6. var linespeed=Math.PI/95;  //跟踪线速度   
  7. var crashdistancefaild=-7;//碰撞检测参数   
  8. var crashdistancesucc=15   
  9. var fantanjuli=7;       
  10. var themaxgradeline=12.1;        
  11.         
  12. function getCookie1(nickname)   
  13. {   
  14.     if (document.cookie.length>0)   
  15.     {    
  16.         c_start=document.cookie.indexOf(nickname + "=")   
  17.         if (c_start!=-1)   
  18.         {    
  19.             c_start=c_start + nickname.length+1;   
  20.             c_end=document.cookie.indexOf(",",c_start);   
  21.             if (c_end==-1)    
  22.                 c_end=document.cookie.length;   
  23.             return unescape(document.cookie.substring(c_start,c_end));   
  24.         }    
  25.     }      
  26.     return "" 
  27. }   
  28.         
  29. function getCookie2(mymaxgrade)   
  30. {   
  31.     if (document.cookie.length>0)   
  32.     {    
  33.         c_start=document.cookie.indexOf(mymaxgrade + "=")   
  34.         if (c_start!=-1)   
  35.         {    
  36.             c_start=c_start + mymaxgrade.length+1;   
  37.             c_end=document.cookie.indexOf(";",c_start);   
  38.             if (c_end==-1)    
  39.                 c_end=document.cookie.length;   
  40.             return unescape(document.cookie.substring(c_start,c_end));   
  41.         }    
  42.     }      
  43.     return "" 
  44. }       
  45.     
  46. function setCookie(nickname,value,mymaxgrade,maxgrade,expiredays)   
  47. {   
  48.     var exdate=new Date()   
  49.     exdate.setDate(exdate.getDate()+expiredays)   
  50.     document.cookie=nickname+ "=" +escape(value)+"," + mymaxgrade + "=" + escape(maxgrade) + ((expiredays==null) ? "" : "; expires="+exdate.toGMTString());   
  51. }   
  52.     
  53. function checkCookie()   
  54. {   
  55.     nickname=getCookie1('nickname');   
  56.     maxgrade=parseInt(getCookie2('mymaxgrade'));   
  57.        if(isNaN(maxgrade)==true)   
  58.        {   
  59.           maxgrade=0;   
  60.       }   
  61.     if (nickname!=null && nickname!="")   
  62.       {   
  63.         alert('欢迎'+nickname+'回来!'+'\n'+"如果喜欢请分享一下哈~");   
  64.     }   
  65.     else   
  66.       {   
  67.           nickname=prompt('请输入你的昵称:(名字太长上榜可是会显示不完整的哦)',"")   
  68.           if (nickname!=null && nickname!="")   
  69.          {   
  70.             var maxgradestring=maxgrade.toString();   
  71.             setCookie('nickname',nickname,'mymaxgrade',maxgradestring,365);   
  72.         }   
  73.       }   
  74. }       
  75.           
  76.         
  77. var objpane=document.getElementById("pane");   
  78. var ctxpane=objpane.getContext("2d");   
  79. ctxpane.translate(150,150);//必备 画布中心点平移     
  80.         
  81. function sendmail()   
  82.         {   
  83.             if(grade2>themaxgradeline)   
  84.             var max_grade=grade2;   
  85.             window.location.href='index.php?max_grade='+max_grade+'&nick_name='+nickname;   
  86.         /*    {   
  87.                     <?php   
  88.             $grade=$_GET['max_grade'];   
  89.             $nickname=$_GET['nick_name'];   
  90.             $mail = new SaeMail();   
  91.             $ret = $mail->quickSend( 'reasonpongo@163.com' , $grade , $nickname ,'reasonpongo@163.com' , 'mypongo' );   
  92.             $mail->clean();    
  93.             ?>   
  94.            }*/ 
  95.             alert(nickname+"你的成绩为:"+grade2+"提交成功~");   
  96.         }      
  97.             
  98.      
  99.         
  100. var gamedirection={   
  101.     shang   : 1,   
  102.     xia     : 5,   
  103.     zuo     : 7,   
  104.     you     : 3,   
  105.     zuoshang: 8,   
  106.     zuoxia  : 6,   
  107.     youshang: 2,   
  108.     youxia  : 4,   
  109.     clock   : 0,   
  110.     anticlock: 9,   
  111.     };//方向   
  112.     
  113. var canvas={   
  114.     width : 300,   
  115.     height: 300,   
  116.     };//画布   
  117.         
  118. var bigcircle = {//大圆参数   
  119.         x : 0,    //圆心的x轴坐标值   
  120.         y : 0,    //圆心的y轴坐标值   
  121.         r : 150,  //圆的半径   
  122.         c : 'rgb(255,255,255)',      
  123.     };//大圆   
  124.     
  125. var smallcircle = {//小圆参数   
  126.         x : 0,    //圆心的x轴坐标值   
  127.         y : 0,    //圆心的y轴坐标值   
  128.         r : 12,  //圆的半径   
  129.         c : 'rgb(204,105,106)',   
  130.         direction :  gamedirection.xia,   
  131.     };//小圆   
  132.         
  133. var line = {//挡板线的参数   
  134.     x : 0,    //圆心的x轴坐标值   
  135.     y : 0,    //圆心的y轴坐标值   
  136.     r : 150 ,  //圆弧的半径   
  137.     start:(Math.PI/2-Math.PI/16),   
  138.     end :  (Math.PI/2+Math.PI/16),   
  139.     c : 'rgb(55,55,55)',   
  140.     direction: gamedirection.anticlock,   
  141.     };//跟踪线   
  142.     
  143. var dot = {//跟踪点参数   
  144.     x   :   (bigcircle.r*Math.cos(line.start+Math.PI/16)),//以大圆为原点   
  145.     y   :   (bigcircle.r*Math.sin(line.start+Math.PI/16)),   
  146.     r   :   1,   
  147.     }//跟踪点   
  148.     
  149. function changelinedirection()   
  150. {   
  151.     if(line.direction==gamedirection.clock)   
  152.     {   
  153.         line.direction=gamedirection.anticlock;   
  154.     }   
  155.     else 
  156.     {   
  157.         line.direction=gamedirection.clock;   
  158.     }   
  159. }   
  160.         
  161. function getdistance(){   
  162.     var distance=Math.sqrt((smallcircle.x)*(smallcircle.x )+(smallcircle.y )*(smallcircle.y ));   
  163.     return distance;   
  164.     }//返回小球与大圆中心距离平方 getdistance()   
  165.         
  166.     
  167. function ifgameover(){//判断是否出界   
  168.     if((getdistance() - bigcircle.r)>5)   
  169.     return true;   
  170.     else 
  171.     return false;   
  172.     }   //判断游戏是否结束 ifgameover()   
  173.     
  174. function ifcrash(){        //碰撞检测   
  175.     var dx = dot.x-smallcircle.x;   
  176.     var dy = dot.y-smallcircle.y;   
  177.     var dd=Math.sqrt(dx*dx+dy*dy);   
  178.     if(dd< crashdistancesucc)   
  179.         return true;   
  180.     else   
  181.         return false;   
  182.     }//碰撞检测 ifcrash()   
  183.         
  184. function randomback()   
  185. {   
  186.     var x=Math.floor(Math.random()*3);   
  187.     switch (smallcircle.direction){                   
  188.                 case gamedirection.shang:   
  189.                 {   
  190.                     switch (x)   
  191.                     {   
  192.                         case 0:   
  193.                         smallcircle.direction=gamedirection.xia;   
  194.                         smallcircle.y=smallcircle.y+fantanjuli;   
  195.                         break;   
  196.                         case 1:   
  197.                         smallcircle.direction=gamedirection.zuoxia;   
  198.                         smallcircle.x=smallcircle.x-fantanjuli;   
  199.                         smallcircle.y=smallcircle.y+fantanjuli;    
  200.                         break;   
  201.                         case 2:   
  202.                         smallcircle.direction=gamedirection.youxia;   
  203.                         smallcircle.x=smallcircle.x+fantanjuli;   
  204.                         smallcircle.y=smallcircle.y+fantanjuli;   
  205.                         break;   
  206.                         default:   
  207.                         break;   
  208.                     }   break;   
  209.                 }   
  210.                 case gamedirection.xia:   
  211.                 {   
  212.                     switch (x)   
  213.                     {   
  214.                         case 0:   
  215.                         smallcircle.direction=gamedirection.shang;   
  216.                         smallcircle.y=smallcircle.y-fantanjuli;   
  217.                         break;   
  218.                         case 1:   
  219.                         smallcircle.direction=gamedirection.zuoshang;   
  220.                         smallcircle.x=smallcircle.x-fantanjuli;   
  221.                         smallcircle.y=smallcircle.y-fantanjuli;   
  222.                         break;   
  223.                         case 2:   
  224.                         smallcircle.direction=gamedirection.youshang;   
  225.                         smallcircle.x=smallcircle.x+fantanjuli;   
  226.                         smallcircle.y=smallcircle.y-fantanjuli;   
  227.                         break;   
  228.                         default:   
  229.                         break;                     
  230.                     }   break;   
  231.                 }   
  232.                 case gamedirection.zuo:   
  233.                 {   
  234.                     switch (x)   
  235.                     {   
  236.                         case 0:   
  237.                         smallcircle.direction=gamedirection.you;   
  238.                         smallcircle.x=smallcircle.x+fantanjuli;   
  239.                         break;   
  240.                         case 1:   
  241.                         smallcircle.direction=gamedirection.youshang;   
  242.                         smallcircle.x=smallcircle.x+fantanjuli;   
  243.                         smallcircle.y=smallcircle.y-fantanjuli;   
  244.                         break;   
  245.                         case 2:   
  246.                         smallcircle.direction=gamedirection.youxia;   
  247.                         smallcircle.x=smallcircle.x+fantanjuli;   
  248.                         smallcircle.y=smallcircle.y+fantanjuli;   
  249.                         break;   
  250.                         default:   
  251.                         break;   
  252.                     }   break;   
  253.                 }   
  254.                 case gamedirection.you:   
  255.                 {   
  256.                     switch (x)   
  257.                     {   
  258.                         case 0:   
  259.                         smallcircle.direction=gamedirection.zuo;   
  260.                         smallcircle.x=smallcircle.x-fantanjuli;   
  261.                         break;   
  262.                         case 1:   
  263.                         smallcircle.direction=gamedirection.zuoxia;   
  264.                         smallcircle.x=smallcircle.x-fantanjuli;   
  265.                         smallcircle.y=smallcircle.y+fantanjuli;   
  266.                         break;   
  267.                         case 2:   
  268.                         smallcircle.direction=gamedirection.zuoshang;   
  269.                         smallcircle.x=smallcircle.x-fantanjuli;   
  270.                         smallcircle.y=smallcircle.y-fantanjuli;   
  271.                         break;   
  272.                         default:   
  273.                         break;   
  274.                     }   break;   
  275.                         
  276.                 }   
  277.                 case gamedirection.zuoshang:   
  278.                 {   
  279.                     switch (x)   
  280.                     {   
  281.                         case 0:   
  282.                         smallcircle.direction=gamedirection.youxia;   
  283.                         smallcircle.x=smallcircle.x+fantanjuli;   
  284.                         smallcircle.y=smallcircle.y+fantanjuli;   
  285.                         break;   
  286.                         case 1:   
  287.                         smallcircle.direction=gamedirection.xia;   
  288.                         smallcircle.y=smallcircle.y+fantanjuli;   
  289.                         break;   
  290.                         case 2:   
  291.                         smallcircle.direction=gamedirection.you;   
  292.                         smallcircle.x=smallcircle.x+fantanjuli;   
  293.                         break;   
  294.                         default:   
  295.                         break;   
  296.                     }   break;   
  297.                         
  298.                 }   
  299.                 case gamedirection.zuoxia:   
  300.                 {   
  301.                     switch (x)   
  302.                     {   
  303.                         case 0:   
  304.                         smallcircle.direction=gamedirection.youshang;   
  305.                         smallcircle.x=smallcircle.x+fantanjuli;   
  306.                         smallcircle.y=smallcircle.y-fantanjuli;   
  307.                         break;   
  308.                         case 1:   
  309.                         smallcircle.direction=gamedirection.shang;   
  310.                         smallcircle.y=smallcircle.y-fantanjuli;   
  311.                         break;   
  312.                         case 2:   
  313.                         smallcircle.direction=gamedirection.you;   
  314.                         smallcircle.x=smallcircle.x+fantanjuli;   
  315.                         break;   
  316.                         default:   
  317.                         break;   
  318.                     }   break;   
  319.                         
  320.                 }   
  321.                 case gamedirection.youshang:   
  322.                 {   
  323.                     switch (x)   
  324.                     {   
  325.                         case 0:   
  326.                         smallcircle.direction=gamedirection.zuoxia;   
  327.                         smallcircle.x=smallcircle.x-fantanjuli;   
  328.                         smallcircle.y=smallcircle.y+fantanjuli;   
  329.                         break;   
  330.                         case 1:   
  331.                         smallcircle.direction=gamedirection.zuo;   
  332.                         smallcircle.x=smallcircle.x-fantanjuli;   
  333.                         break;   
  334.                         case 2:   
  335.                         smallcircle.direction=gamedirection.xia;   
  336.                         smallcircle.y=smallcircle.y+fantanjuli;   
  337.                         break;   
  338.                         default:   
  339.                         break;   
  340.                     }   break;   
  341.                         
  342.                 }   
  343.                 case gamedirection.youxia:   
  344.                 {   
  345.                     switch (x)   
  346.                     {   
  347.                         case 0:   
  348.                         smallcircle.direction=gamedirection.zuoshang;   
  349.                         smallcircle.x=smallcircle.x-fantanjuli;   
  350.                         smallcircle.y=smallcircle.y-fantanjuli;   
  351.                         break;   
  352.                         case 1:   
  353.                         smallcircle.direction=gamedirection.zuo;   
  354.                         smallcircle.x=smallcircle.x-fantanjuli;   
  355.                         break;   
  356.                         case 2:   
  357.                         smallcircle.direction=gamedirection.shang;   
  358.                         smallcircle.y=smallcircle.y-fantanjuli;   
  359.                         break;   
  360.                         default:   
  361.                         break;   
  362.                     }   break;   
  363.                         
  364.                 }   
  365.                 default:   
  366.                 {   
  367.                     break;         
  368.                 }   
  369.             }      
  370. }//小球随机反向 randomback()   
  371.     
  372. function smallcircledirection()   
  373. {   
  374.     switch (smallcircle.direction){                //根据小球方向做移动   
  375.                 case gamedirection.shang:   
  376.                 {   
  377.                     smallcircle.y=smallcircle.y-gamespeed;   
  378.                     grade++;   
  379.                     if(grade>maxgrade)   
  380.                     {   
  381.                         maxgrade=grade;   
  382.                        newrecoder();   
  383.                     }   
  384.                     addone();   
  385.                     break;   
  386.                 }   
  387.                 case gamedirection.xia:   
  388.                 {   
  389.                     smallcircle.y=smallcircle.y+gamespeed;   
  390.                     grade++;   
  391.                     if(grade>maxgrade)   
  392.                     {   
  393.                         maxgrade=grade;   
  394.                        newrecoder();   
  395.                     }   
  396.                     addone();   
  397.                     break;   
  398.                 }   
  399.                 case gamedirection.zuo:   
  400.                 {   
  401.                     smallcircle.x=smallcircle.x-gamespeed;   
  402.                     grade++;   
  403.                     if(grade>maxgrade)   
  404.                     {   
  405.                         maxgrade=grade;   
  406.                        newrecoder();   
  407.                     }   
  408.                     addone();   
  409.                     break;   
  410.                 }   
  411.                 case gamedirection.you:   
  412.                 {   
  413.                     smallcircle.x=smallcircle.x+gamespeed;   
  414.                     grade++;   
  415.                     if(grade>maxgrade)   
  416.                     {   
  417.                         maxgrade=grade;   
  418.                        newrecoder();   
  419.                     }   
  420.                     addone();   
  421.                     break;   
  422.                 }   
  423.                 case gamedirection.zuoshang:   
  424.                 {   
  425.                     smallcircle.x=smallcircle.x-gamespeed*0.8;   
  426.                     smallcircle.y=smallcircle.y-gamespeed*0.8;   
  427.                     grade++;   
  428.                     if(grade>maxgrade)   
  429.                     {   
  430.                         maxgrade=grade;   
  431.                        newrecoder();   
  432.                     }   
  433.                     addone();   
  434.                     break;   
  435.                 }   
  436.                 case gamedirection.zuoxia:   
  437.                 {   
  438.                     smallcircle.x=smallcircle.x-gamespeed*0.8;   
  439.                     smallcircle.y=smallcircle.y+gamespeed*0.8;   
  440.                     grade++;   
  441.                     if(grade>maxgrade)   
  442.                     {   
  443.                         maxgrade=grade;   
  444.                        newrecoder();   
  445.                     }   
  446.                     addone();   
  447.                     break;   
  448.                 }   
  449.                 case gamedirection.youshang:   
  450.                 {   
  451.                     smallcircle.x=smallcircle.x+gamespeed*0.8;   
  452.                     smallcircle.y=smallcircle.y-gamespeed*0.8;   
  453.                     grade++;   
  454.                     if(grade>maxgrade)   
  455.                     {   
  456.                         maxgrade=grade;   
  457.                        newrecoder();   
  458.                     }   
  459.                     addone();   
  460.                     break;   
  461.                 }   
  462.                 case gamedirection.youxia:   
  463.                 {   
  464.                     smallcircle.x=smallcircle.x+gamespeed*0.8;   
  465.                     smallcircle.y=smallcircle.y+gamespeed*0.8;   
  466.                     grade++;   
  467.                     if(grade>maxgrade)   
  468.                     {   
  469.                         maxgrade=grade;   
  470.                        newrecoder();   
  471.                     }   
  472.                     addone();   
  473.                     break;   
  474.                 }   
  475.                 default:   
  476.                 {   
  477.                     break;         
  478.                 }   
  479.             }      
  480. }//小球移动 smallcircledirection()   
  481.     
  482. /*画出底部圆*/ 
  483. ctxpane.beginPath();    //大圆   
  484. ctxpane.arc(bigcircle.x,bigcircle.y,bigcircle.r,0,Math.PI*2,true);   
  485. ctxpane.fillStyle = bigcircle.c;   
  486. ctxpane.fill();   
  487. ctxpane.closePath();   
  488.     
  489. /*画出底部追踪线条*/ 
  490. ctxpane.beginPath();   
  491. ctxpane.lineWidth=6;   
  492. ctxpane.strokeStyle = line.c;   
  493. ctxpane.arc(line.x, line.y, line.r, line.start, line.end,false);    
  494. ctxpane.stroke();    
  495. ctxpane.closePath();   
  496.     
  497. function tapme()//tapme   
  498. {   
  499.     ctxpane.beginPath();   
  500.     ctxpane.strokeStyle="rgb(255,222,195)";   
  501.     ctxpane.font = "80px Papyrus";   
  502.     ctxpane.strokeText('TAP',-95,30);   
  503.     ctxpane.fillStyle="rgb(255,205,105)";   
  504.     ctxpane.font = "35px Papyrus";   
  505.     ctxpane.fillText('me',70,30);   
  506.     ctxpane.closePath();   
  507.     }   
  508.     
  509. function newrecoder()    
  510. {   
  511.     ctxpane.beginPath();   
  512.     ctxpane.fillStyle="rgb(255,0,0)";   
  513.     ctxpane.font = "18px Papyrus";   
  514.     ctxpane.fillText("New!",58,80);   
  515.     ctxpane.closePath();   
  516.     }    
  517.         
  518. function addone()   
  519. {   
  520.     grade1=(grade/150).toFixed(1);   
  521.     grade2=(maxgrade/150).toFixed(1);   
  522.     var say1="now";   
  523.     var say2="best" 
  524.     ctxpane.beginPath();   
  525.     ctxpane.strokeStyle="rgb(250,222,185)";   
  526.     ctxpane.font = "60px Papyrus";   
  527.     ctxpane.strokeText(grade1,-45,-60);   
  528.     ctxpane.strokeText(grade2,-45,100);   
  529.         
  530.     ctxpane.fillStyle="rgb(255,0,100)";   
  531.     ctxpane.font = "15px Papyrus";   
  532.     ctxpane.fillText(say1,58,-60);   
  533.         
  534.     ctxpane.fillStyle="rgb(255,0,100)";   
  535.     ctxpane.font = "15px Papyrus";   
  536.     ctxpane.fillText(say2,58,100);   
  537.     ctxpane.closePath();   
  538. }   
  539.     
  540. function movetest(){   
  541.         
  542.     if(ifgameover())   
  543.     {    
  544.         ifingame=0;   
  545.         if(maxgrade>parseInt(getCookie2('mymaxgrade')))   
  546.         {   
  547.             setCookie('nickname',nickname,'mymaxgrade',maxgrade.toString(),365);           
  548.         }   
  549.         clearInterval(timer);   
  550.         tapme();   
  551.     
  552.     }   
  553.     else 
  554.     {   
  555.         if(ifcrash())   
  556.             {   
  557.                 randomback();   
  558.             }      
  559. ctxpane.clearRect(-150,-150,300,300);   //清屏   
  560.         
  561. ctxpane.beginPath();    //大圆   
  562. ctxpane.arc(bigcircle.x,bigcircle.y,bigcircle.r,0,Math.PI*2,true);   
  563. ctxpane.fillStyle = bigcircle.c;   
  564. ctxpane.fill();   
  565. ctxpane.closePath();   
  566.     
  567. if(line.direction==gamedirection.clock)   //跟踪线顺时针   
  568. {   
  569.     line.start=line.start + linespeed;       
  570.     line.end=line.end +linespeed;   
  571.     ctxpane.beginPath();   
  572.     ctxpane.lineWidth=4;   
  573.     ctxpane.strokeStyle = line.c;   
  574.     ctxpane.arc(line.x, line.y, line.r, line.start, line.end,false);    
  575.     ctxpane.stroke();    
  576.     ctxpane.closePath();       
  577. }   
  578. if(line.direction==gamedirection.anticlock)                                 //跟踪逆顺时针   
  579. {   
  580.     line.start=line.start - linespeed;       
  581.     line.end=line.end -linespeed;   
  582.     ctxpane.beginPath();   
  583.     ctxpane.lineWidth=4;   
  584.     ctxpane.strokeStyle = line.c;   
  585.     ctxpane.arc(line.x, line.y, line.r, line.start, line.end,false);    
  586.     ctxpane.stroke();    
  587.     ctxpane.closePath();           
  588. }   
  589.         
  590. dot.x=bigcircle.r*Math.cos(line.start+Math.PI/32)   //跟踪点   
  591. dot.y=bigcircle.r*Math.sin(line.start+Math.PI/32)   
  592. ctxpane.beginPath();//线上跟踪点   
  593. ctxpane.arc(dot.x,dot.y,dot.r,0,Math.PI*2,true);   
  594. ctxpane.fillStyle = smallcircle.c;   
  595. ctxpane.fill();   
  596. ctxpane.closePath();       
  597. smallcircledirection();//小圆   
  598. ctxpane.save();   
  599. ctxpane.beginPath();   
  600. ctxpane.arc(smallcircle.x,smallcircle.y,smallcircle.r,0,Math.PI*2,true);   
  601. ctxpane.fillStyle = smallcircle.c;   
  602. ctxpane.fill();   
  603. ctxpane.closePath();   
  604. ctxpane.restore();   
  605.     }   
  606. }//主函数   
  607.     
  608.     
  609.       
  610.     ///////////////////////////////////////////   
  611. tapme();   
  612. var timer;   
  613. function startgame(){//开始游戏   
  614.         
  615.     
  616.     if(ifingame==0)   
  617.     {   
  618.         ifingame=1;   
  619.         grade=0;   
  620.         var xx=Math.floor(Math.random()*8);   
  621.         /*      switch(xx)   
  622.         {   
  623.             case 0:   
  624.             smallcircle.direction=gamedirection.shang;   
  625.             break;   
  626.             case 1:   
  627.             smallcircle.direction=gamedirection.xia;   
  628.             break;   
  629.             case 2:   
  630.             smallcircle.direction=gamedirection.zuo;   
  631.             break;   
  632.             case 3:   
  633.             smallcircle.direction=gamedirection.you;   
  634.             break;   
  635.             case 4:   
  636.             smallcircle.direction=gamedirection.zuoshang;   
  637.             break;   
  638.             case 5:   
  639.             smallcircle.direction=gamedirection.zuoxia;   
  640.             break;   
  641.             case 6:   
  642.             smallcircle.direction=gamedirection.youshang;   
  643.             break;   
  644.             case 7:   
  645.             smallcircle.direction=gamedirection.youxia;   
  646.             break;   
  647.             default:   
  648.             break;   
  649.         }*/ 
  650.     smallcircle.direction=gamedirection.xia;   
  651.     smallcircle.x=smallcircle.y=0;   
  652.     line.start=Math.PI/2-Math.PI/26;   
  653.     line.end=Math.PI/2+Math.PI/26;   
  654.     line.direction=gamedirection.anticlock;   
  655.         
  656.     clearInterval(timer);   
  657.     timer=setInterval(movetest,10);   
  658.     }   
  659.     }//开始游戏 startgame()      
  660.         
  661.     function opentop()   
  662.     {   
  663.         window.location="http://pongotop.sinaapp.com";   
  664.     }   

10.写在最后

这纯属又是一个自娱自乐,写完后的第三天因为开始忙着投简历找实习就没空再管,扔到朋友圈让朋友玩去了。这一个月过去了再重新看这游戏,感觉它不该就这样死掉,本人没什么技术,做得很拙略,因此发出这篇文字希望能帮到一些对pongo感兴趣的朋友,再者就是希望如果有这方面的高手看到了能够给予赐教,一切疑惑和赐教都欢迎给我留言,谢谢!

本文地址:http://chenreason.blog.51cto.com/9045252/1426514

责任编辑:林师授 来源: 51CTO
相关推荐

2024-02-22 14:24:34

2023-12-08 09:15:53

Java单表树形结构Tree

2009-07-06 17:57:22

JSF表格组件

2023-11-20 08:39:24

Spring定时任务

2023-11-27 08:15:26

Spring订单取消

2011-04-22 10:43:37

JavaScript

2015-09-01 15:45:50

开源字体Hack

2014-06-25 09:15:33

JavaScript 编辑器

2023-08-04 17:52:22

2020-05-06 12:18:20

任天堂黑客代码

2015-03-03 13:15:19

ASP.NET大文件下载实现思路

2013-04-10 09:59:46

PythonC++

2009-07-24 18:40:50

2019-05-29 17:45:32

JavaScript算法思路代码实现

2009-03-10 08:59:18

2015-09-02 11:22:36

JavaScript实现思路

2017-07-26 17:10:24

前端JavascriptThis

2020-11-13 13:05:27

Java开发代码

2015-07-23 18:09:02

IBM开源

2009-08-18 13:56:18

开源代码Linux系统云计算
点赞
收藏

51CTO技术栈公众号