1 Star 0 Fork 0

余赟昊 / Flappy-polimin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Pipe.js 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
余赟昊 提交于 2020-11-17 09:57 . 基本全部完成,修复若干bug
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;
}
}
1
https://gitee.com/yu_yunhao/flappy-polimin.git
git@gitee.com:yu_yunhao/flappy-polimin.git
yu_yunhao
flappy-polimin
Flappy-polimin
master

搜索帮助