[模仿]html5游戏_兔子踩铃铛

在模仿着做了一个html5手机游戏—兔子踩铃铛,和flash版兔子踩铃铛差的不多吧

效果图:

代码:

index.htm

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <meta name="description" content="An HTML5 canvas game.">
 6         <meta name="keywords" content="html5, canvas, web, game">
 7         <meta name="author" content="Wang Xin Sheng">
 8         <meta name="apple-mobile-web-app-capable" content="yes">
 9         <meta name="apple-mobile-web-app-status-bar-style" content="black">
10         <meta name="viewport" id="viewport" content="width = device-width, initial-scale = 1, minimum-scale = 1, maximum-scale = 1, user-scalable=no">
11         <meta http-equiv="X-UA-Compatible" content="chrome=1">
12         <meta http-equiv="Pragma" content="no-cache">
13         <meta http-equiv="Cache-Control" content="no-cache">
14         <meta equiv="Expires" content="0">
15         <meta http-equiv="content-script-type" content="text/javascript">
16         <title>[WXS]兔子跳铃铛</title>
17         <script src="requestNextAnimationFrame.js"></script>
18         <style type="text/css">
19          html {
   color:#000;background:#222;margin:0px;}
20          body {
   -webkit-user-select:none;margin:0px;}
21         #gameWorld{
   cursor:pointer;}
22         #btn_start{
   color:white;font-size:38px;font-weight:bold;z-index:999;display:none;background:rgba(150,150,150,0.8);text-align:center;cursor:pointer;}
23         </style>
24     </head>
25     <body>
26     <section>
27         <div style='position:absolute;left:0px;top:0px;width:100%;height:100%;overflow:hidden;' id='btn_start'></div>
28         <canvas id="gameWorld" style="position: absolute; left: 0px; top: 0px;">
29             <p>You need a <a href="http://www.google.com/chrome">modern browser</a> to view this.</p>
30         </canvas>
31     </section>
32     </body>
33     <script src="CGM010.js"></script>
34 </html>

CGM010.js:

  1 ;
  2 var gameWorld = new function () {
  3     function doSize() {
  4         caW = window.innerWidth;
  5         caH = window.innerHeight;
  6         caObj.width = caW;
  7         caObj.height = caH;
  8         caObj.style.width = caW + "px";
  9         caObj.style.height = caH + "px";
 10         bellLst = [];
 11         birdLst = [];
 12         explLst = [];
 13         snowLst=[];
 14         rabit = null;
 15         birdGenTime = 20; // 每几个生成一个bird
 16         genBellCount = 0;
 17         bellW = 20;//caH * 0.06;
 18         bellH = bellW;
 19         bellGap = caH * 0.05;
 20         rabitH = 20;
 21         rabitW = rabitH;
 22         bellDownSpeed = bellH * 0.15;
 23         genTop = caH * 0.9;
 24         bellOutScreenTop = genTop;
 25         birdSpeed = bellW * 0.3;
 26         rabitSpeed = 0;
 27         rabitA = 0;
 28         rabitD = -1; //-1:left,1:right
 29         mouseTObj = {x:null,y:null};
 30         rabitOnAirFlg = false;
 31         lastFpsUpdateTime = new Date;
 32         scoreB = 1;
 33         score = 0;
 34         scoreOne = 10;
 35         flyFlg = false;
 36     }
 37     function gen(name) {
 38         switch(name){
 39             case "bell":
 40                 while(genTop>=-caH){
 41                     if(genBellCount>=birdGenTime){
 42                         gen("bird");
 43                     }
 44                     bellLst.push(new bell(genTop, Math.random()*(caW-bellW), bellW, bellH, 0, bellPicLst.length));
 45                     genTop -= (bellGap + bellH);
 46                     genBellCount++;
 47                     if(genBellCount>=birdGenTime)
 48                         genTop += bellGap - bellH * 0.5;
 49           
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用C3.js库中的transition动画函数实现摇铃铛效果。以下是一个实现的示例代码: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>C3.js 摇铃铛效果</title> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.18/c3.min.css"> </head> <body> <div id="chart"></div> <script src="https://d3js.org/d3.v5.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.18/c3.min.js"></script> <script> var chart = c3.generate({ bindto: '#chart', data: { columns: [ ['data', 30] ], type: 'gauge' }, gauge: { width: 15, min: 0, max: 100, units: 'value', label: { show: false } }, color: { pattern: ['#FF0000', '#F97600', '#F6C600', '#60B044'], threshold: { values: [30, 60, 90, 100] } } }); function shakeBell() { chart.load({ columns: [ ['data', 30] ], type: 'gauge', done: function() { chart.internal.config.gauge_label_show = false; d3.select('.c3-gauge-value') .transition() .duration(500) .ease(d3.easeElasticOut) .attr('transform', 'translate(0, 10)') .transition() .duration(500) .ease(d3.easeElasticOut) .attr('transform', 'translate(0, -10)') .transition() .duration(500) .ease(d3.easeElasticOut) .attr('transform', 'translate(0, 0)'); } }); } setInterval(shakeBell, 3000); </script> </body> </html> ``` 在此示例中,我们使用了C3.js的仪表图(gauge)类型,然后通过定时调用shakeBell()函数来实现摇铃铛的效果。在shakeBell()函数中,我们先重新加载了一个值为30的数据列,并通过transition函数来实现振动动画效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值