Commit 66f73525 authored by honingwon's avatar honingwon

1

parent fbd059e5
import { WidgetBase, Event } from 'spark-wrapper-fyge';
import metaConfig from '../meta.json';
import Body from './Body';
let ground;
class GameStage extends WidgetBase {
onLaunched() {
this.bodys = [];
......@@ -11,25 +10,31 @@ class GameStage extends WidgetBase {
this
);
this.addbodys();
ground = this.stage.viewRect.height;
// this.addGround({x:0,y:500, width:300,height:10});
this.addGround({x:0,y:this.stage.viewRect.height, width:300,height:10});
// ground = this.stage.viewRect.height;
}
grounds;
addGround(ground){
this.grounds = this.grounds||[];
this.grounds.push(ground);
}
addbodys() {
const ball = new Body({
display: 'ball',
initialVelocityY: 2,
initialVelocityY: 0,
accelerationY: 2,
restitution:0.85
restitution:0
});
const block = new Body({
display: 'box',
initialVelocityY: 2,
accelerationY: 2,
restitution:0.4
initialVelocityY: 0,
accelerationY: 0,
restitution:0
});
block.x = 300;
// block.x = 300;
this.addChild(block);
this.bodys.push(block);
......@@ -46,11 +51,17 @@ class GameStage extends WidgetBase {
checkCollideGround(body) {
const y0 = body.y + body.height;
if (y0 > ground) {
body.y = ground - body.height;
body.velocityY = -body.velocityY * body.restitution;
//默认从上往下走,碰到第一个就停止
for (let i = 0; i < this.grounds.length; i++) {
const ground = this.grounds[i];
if (y0 > ground.y) {
body.y = ground.y - body.height;
body.velocityY = -body.velocityY * body.restitution;
break;
}
}
}
}
......
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