代码拉取完成,页面将自动刷新
class Pipe {
constructor(type = 0) {
// this.type = ~~(Math.random() + 0.5); //0为朝上,1为朝下
this.type = type;
this.width = 72;
this.height = Math.random() * ((game.canvas.height >> 1) - 100) + 100;
//管子图片起始切片宽度
this.startWidth = 175;
//地板以上画布高度
// this.overFloorHeight = 421;
this.overFloorHeight = game.canvas.height - game.floor.height
this.x = game.canvas.width;
this.y = this.type === 0 ? this.overFloorHeight - this.height : 0;
this.speed = 3;
}
update() {
this.x -= this.speed;
//碰撞检测
//进入当前管子
if (game.bird.x > this.x - game.bird.width && game.bird.x < this.x + this.width) {
if (this.type === 0) {
if (game.bird.y + game.bird.height >= this.y) {
game.audio.setAttribute('src', 'music/No.mp3');
game.audio.load();
game.audio.play();
game.suspend();
game.restart();
}
} else if (this.type === 1) {
if (game.bird.y <= this.height) {
game.audio.setAttribute('src', 'music/No.mp3');
game.audio.load();
game.audio.play();
game.suspend();
game.restart();
}
}
}
//加分
// if(this.x < canvas.width / 2 - this.width && !this.done){
// game.scoreManager.score++;
// this.done = true;
// const audio = document.getElementsByTagName("audio")[0];
// audio.load();
// audio.play();
// }
if (this.x < game.bird.x - this.width && !this.done) {
game.scoreManager.score++;
this.done = true;
game.audio.load();
game.audio.play();
}
}
render() {
if (this.type === 0) {
//向上的管子
// console.log(this.height);
game.pen.drawImage(game.images.pipe1, this.startWidth, 0, this.width, this.height, this.x, this.overFloorHeight - this.height, this.width, this.height);
} else if (this.type === 1) {
//向下的管子
game.pen.drawImage(game.images.pipe2, this.startWidth, 420 - this.height, this.width, this.height, this.x, 0, this.width, this.height);
}
}
pause() {
this.speed = 0;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。