//检测小鸟是否撞击铅笔
static isStrike (bird,pencil) {
let s = false;
if (bird.top>pencil.bottom||bird.bottom<pencil.top||bird.right<pencil.left||bird.left>pencil.right) {
s = true;
return s;
}else {
return !s;
}
}
//检测小鸟是否足撞击地板
check () {
const birds = this.dateStore.get('birds');
const land = this.dateStore.get('land');
const pencils = this.dateStore.get('pencils');
if (birds.birdsY[0] + birds.birdsHeight[0]>=land.y) {
this.isGameover =true;
return;
}
let birdsBorder = {
top:birds.birdsY[0],
bottom:birds.birdsY[0] + birds.birdsHeight[0],
left:birds.birdsX[0],
right:birds.birdsX[0]+birds.birdsWidth[0]
};
let length = pencils.length;
for (let i=0;i<length;i++) {
let pencil = pencils[i];
let pencilBorder = {
top:pencil.y,
bottom:pencil.y + pencil.height,
left:pencil.x,
right:pencil.x + pencil.width
};
if (Director.isStrike(birdsBorder,pencilBorder)) {
this.isGameover = true;
return;
}
}
}