canvas-js实现flyBird游戏

思路请私聊博主QQ918922703;

资源和源码链接链接:https://pan.baidu.com/s/1Rump1UOHJoygs-PQOhnXrQ 
提取码:mz9i 
 

简单代码如下

(function(){
	let Bird=function(){
		this.x=(game.canvas.width-48)/2;//鸟默认居中
		this.y=(game.canvas.height)*(1-0.618);//小鸟的默认位置垂直为0.618
		this.changeY=0//改变的值
		this.changeRad=0;
		this.img=[game.allImg["bird0_0"],game.allImg["bird0_1"],game.allImg["bird0_2"]];
		this.status="moveDown";
		this.Wing=0;//图片的位置 控制翅膀的上下
	};
	window.Bird=Bird;
	Bird.prototype.update=function(){
		if (this.status=="moveDown") {			
			this.changeY+=0.6;
			this.y+=this.changeY;
			this.changeRad+=0.05;
		}else if(this.status=="moveUp"){
			this.changeY-=0.8;
			if (this.changeY<=0) {
				this.status="moveDown";
				return;
			}
			this.y-=this.changeY;
			this.y<24?this.y=24:this.y;
			this.Wing++;
			this.Wing>2?this.Wing=0:null;
		}
		//落地检测
		if(this.y>game.canvas.height-114-10){
			game.Sm.enter(3);	
		}
	};
	Bird.prototype.render=function(){
		game.draw.save();
		game.draw.translate(this.x,this.y);
		game.draw.rotate(this.changeRad);
		game.draw.drawImage(this.img[this.Wing],-24,-24);
		game.draw.restore();
	};
	Bird.prototype.fly=function(){
		//点击canvas上升一点距离
		this.status="moveUp";
		this.changeRad=-1.2;
		this.changeY=10;
	}
})();

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值