思路请私聊博主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;
}
})();