Commit 6847581b authored by Friends233's avatar Friends233

跳跃优化

parent 5f60989d
This diff is collapsed.
......@@ -86,6 +86,12 @@ export class IndexScene extends Scene {
_initEvents() {
this.addEventListener(FYGE.Event.ENTER_FRAME, this._enterFrame, this)
this.addEventListener(FYGE.MouseEvent.CLICK, this.birdJump, this)
// this.addEventListener(FYGE.MouseEvent.MOUSE_MOVE,this.testBird,this)
}
testBird(e) {
this.bird.x = e.stageX
this.bird.y = e.stageY
}
/** 检查小鸟掉落位置 */
......
......@@ -16,7 +16,9 @@ import FrameAni = FYGE.FrameAni;
/** 初始坠落步长 */
const FIAL_STEP = 4
/** 初始跳跃步长 */
const JUMP_STEP = 18
const JUMP_STEP = 19
/** 最大跳跃步长 */
const JUMP_MAX_STEP = JUMP_STEP - 8
/** 坠落速率 */
const FIAL_MUI = 0.4
......@@ -46,6 +48,8 @@ export class Bird extends Container {
]
this.player = new FrameAni(birdAni)
this.player.play(0)
this.anchorX = this.width / 2
this.anchorY = this.height / 2
// this.player.scale.x = 3
// this.player.scale.y = 3
this.addChild(this.player)
......@@ -83,7 +87,7 @@ export class Bird extends Container {
if(this.isGameOver) return
if (this.y <= 0) return
// console.log('jump')
this.failStep -= this.jumpStep
this.failStep = Math.max(this.failStep - this.jumpStep,-JUMP_MAX_STEP)
}
/** 重置 */
......@@ -97,7 +101,7 @@ export class Bird extends Container {
this.reset()
this.isGameOver = true
this.rotation = 0
this.player.reset()
this.player.reset(this.player.getCurrentFrame())
}
destroy() {
......
......@@ -26,6 +26,35 @@ function randomNum(min, max) {
return Math.floor(Math.random() * (max - min)) + min
}
/**
* 碰撞检测
* @param {FYGE.Container} coA
* @param {FYGE.Container} coB
* @returns 是否碰撞
*/
export const isCollision = (coA, coB) => {
const aGlobalPos = coA.localToGlobal(new FYGE.Point(0, 0), new FYGE.Point())
const bGlobalPos = coB.localToGlobal(new FYGE.Point(0, 0), new FYGE.Point())
const disX = (coA.width + coB.width) * 0.5
const disY = (coB.height + coB.height) * 0.5
const centerA = {
x: aGlobalPos.x + coA.width * 0.5,
y: aGlobalPos.y + coA.height * 0.5
}
const centerB = {
x: bGlobalPos.x + coB.width * 0.5,
y: bGlobalPos.y + coB.height * 0.5
}
const diffNumX = Math.abs(centerA.x - centerB.x)
const diffNumY = Math.abs(centerA.y - centerB.y)
return diffNumX < disX && diffNumY < disY
}
export class Pipe extends Container {
/** 水管类型 */
......@@ -94,7 +123,6 @@ export class PipeMannager {
/** 创建一组水管 */
createGroupPipe() {
console.log(this.deep)
const upD = this.downPipes.length ? this.downPipes.pop() : new Pipe('down')
const upP = this.upPipes.length ? this.upPipes.pop() : new Pipe('up')
upD.x = 750
......@@ -130,13 +158,17 @@ export class PipeMannager {
const player = this.player
const posx = player.x
// 重叠水管
if ((posx + player.width/2) >= up.x && (posx - player.width/2) <= (up.x + up.width)) {
if (((posx + player.width / 2) >= up.x) && ((posx - player.width / 2) <= (up.x + up.width))) {
// console.log('水管中')
const half =Number((player.height / 2).toFixed(3))
// 碰撞头朝上的水管
if (up.y <= player.y) {
if (up.y <= (player.y + half)) {
// console.log('触碰下',up.y,player.y, half)
this.stage.gameOver()
}
// 碰撞头朝下的水管
if ((down.y + down.height + player.height / 2) >= player.y) {
if ((down.y + down.height) >= (player.y - half)) {
// console.log('触碰上',(down.y + down.height),(player.y - half))
this.stage.gameOver()
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment