Commit f9df87f4 authored by wildfirecode13's avatar wildfirecode13

1

parent f56db825
......@@ -20,17 +20,17 @@ class GameStage extends WidgetBase {
this
);
this.addbodys();
const groundData = { x: 0, y: this.stage.viewRect.height / 2, width: 300, height: 10 };
const groundData = { x: 0, y: this.stage.viewRect.height / 2, width: 100, height: 10 };
const ground = new Ground({ data: groundData, display: createGroundDisplay(groundData) })
this.addGround(ground);
const groundData1 = { x: 400, y: this.stage.viewRect.height /3 * 2, width: 200, height: 10 };
const groundData1 = { x: 100, y: this.stage.viewRect.height / 3 * 2, width: 100, height: 10 };
const ground1 = new Ground({ data: groundData1, display: createGroundDisplay(groundData1) })
this.addGround(ground1);
// setTimeout(() => {
// this.removeGround(ground)
// }, 3000);
const groundData2 = { x: 200, y: this.stage.viewRect.height / 3 * 2 * 1.2, width: 200, height: 10 };
const ground2 = new Ground({ data: groundData2, display: createGroundDisplay(groundData2) })
this.addGround(ground2);
}
grounds;
......@@ -50,22 +50,10 @@ class GameStage extends WidgetBase {
const ball = new Body({
display: 'box',
initialVelocityY: 0,
initialVelocityX: 2,
initialVelocityX: 1,
accelerationY: 2,
restitution: 0
});
const block = new Body({
display: 'box',
initialVelocityY: 0,
accelerationY: 2,
restitution: 0
});
block.x = 620;
this.addChild(block);
this.bodys.push(block);
this.addChild(ball);
this.bodys.push(ball);
}
......@@ -82,13 +70,21 @@ class GameStage extends WidgetBase {
//默认从上往下走,碰到第一个就停止
for (let i = 0; i < this.grounds.length; i++) {
const ground = this.grounds[i];
// console.log(y0, ground.y)
const dis0 = body.width / 2 + ground.data.width / 2;
const dis1 = Math.abs(body.x + body.width / 2 - ground.data.x - ground.data.width / 2);
if (y0 > ground.y && dis1 < dis0) {
// if (!body.checkCollideGround) {
// body.checkCollideGround = ground;
// console.log('碰撞了地面', JSON.stringify(ground.data));
// }
body.y = ground.y - body.height;
body.velocityY = -body.velocityY * body.restitution;
break;
} else {
// if (body.checkCollideGround) {
// console.log('取消碰撞地面', JSON.stringify(ground.data));
// }
// body.checkCollideGround = null;
}
}
}
......
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