利用HTML5实现Canvas聚宝盆接金币游戏



11 41 14



特效描述:利用HTML5实现 Canvas 聚宝盆 接金币游戏,利用HTML5实现Canvas聚宝盆接金币游戏

代码结构

1. 引入CSS

<link href="css/msjbp.css" rel="stylesheet" />

2. 引入JS

<script src="js/jquery-1.8.3.min.js"></script>
<script src="js/money.js"></script>
<script src="js/pen.js"></script>
<script src="js/body.js"></script>
<script src="js/requestNextAnimationFrame.js"></script>

3. HTML代码

<script type="text/javascript">
	function set_meta() {
		var body_width = document.documentElement.clientWidth;
		var get_scale = (body_width / 2) / 640;
		var get_content = "width=device-width, initial-scale=" + get_scale + ", minimum-scale=" + get_scale + ", maximum-scale=" + get_scale;
		document.getElementById("viewport").setAttribute('content', get_content);
	}
	set_meta();
</script>
<canvas width="640" height="1008" id="canvas"></canvas>
<div class="tim_dsq" id="clock"></div>
<script>
	var canvas = document.getElementById('canvas');
	var context = canvas.getContext('2d');
	var canvasWidth = 640;
	var canvasHeight = 1008;
	var penWidth = 198;
	var penHeight = 132;
	var penY = 740;
	var score = 0;
	var msb_num = 0;
	var sxd_num = 0;
	var dhj_num = 0;
	var cxs_num = 0;
	var ryb_num = 0;
	var jb_num = 0;
	var isEnd = false;//游戏结束
	var msb_num_left = 0;
	var sxd_num_left = 0;
	var dhj_num_left = 0;
	var cxs_num_left = 0;
	var ryb_num_left = 0;
	var jb_num_left = 0;
	var zad_num_left = 0;
	var body;
	function animate(now) {
		body.clear();
		body.draw();
		if (!isEnd) {
			requestNextAnimationFrame(animate); 
		}       
	}
	$().ready(function () {
		body = new Body();
		timedCount();
		window.requestNextAnimationFrame(animate); 
	})
	var time = 10;
	var clock;
	function timedCount() {
		$("#clock").html(time + "秒");
		if (time <= 0) {
			clearTimeout(clock);
			this.isEnd = true;
		} else {
			time = time - 1;
			clock = setTimeout("timedCount()", 1000);
		}
	}
</script>
<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
</div>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: 小游戏 H5游戏 游戏源码 手机游戏 微信游戏 网页游戏 其他游戏 其他h5游戏 其他h5源码游戏

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到