html5实现微信的打飞机游戏,利用这个小游戏学习一个HTML5吧,这是开发WEB的一个方向
代码如下:
// JavaScript Documentvar c = document.getElementById("dotu");var cxt = c.getContext("2d");var img = newImg("./assets/bg_01.jpg");var fps;cxt.drawImage(img,0,0,480,800);var flivverLog = 0;var flivver1 = newImg("./assets/flivver.png");var flivver2 = newImg("./assets/flivver2.png");var flivver3 = newImg("./assets/flivver3.png");// 用于记录游戏的时间,越到后面越快var time1 = 0;var time2 = 80;// 积分var jifen = 0;function getSudu(){ var number = parseInt(Math.random()*10); if(number < 5 && number > 0){ return number; } return 1;}// 飞机的对象function flivverObj(hp,ewidth,eheight,eimg,esudu){ // 随机的X this.x = parseInt(Math.random()*460+1); this.y = 0; // 血量 this.hp = hp; // 挨打 this.hit = 0; // 是否死亡 this.over = 0; this.width = ewidth; this.height = eheight; this.img = eimg; this.sudu = esudu;}// 获取飞机function getFlivver(type){ switch(type){ case 1: return new flivverObj(100,50,30,flivver1,getSudu()); case 2: return new flivverObj(500,70,90,flivver2,getSudu()); case 3: return new flivverObj(1000,110,170,flivver3,getSudu()); }}function cartridge(x,y){ this.x = x; this.y = y; }function gameover(){ window.clearTimeout(fps); //$('#dotu').fadeOut(); $('.content').css('position','relative'); $('.content').append(''); $('#sil').html('你').hide().fadeIn(1000,function(){ $(this).html('你屎').hide().fadeIn(1000,function(){ $(this).html('鼠标X:鼠标Y:小飞机数:子弹数:打中:生成飞机时间:
<script type="text/javascript" src="./dotu_game.js">《script》