Commit 48ed6490 authored by wildfirecode13's avatar wildfirecode13

1

parent 66f73525
...@@ -3,7 +3,10 @@ export default class Body extends Sprite { ...@@ -3,7 +3,10 @@ export default class Body extends Sprite {
constructor(props) { constructor(props) {
super(); super();
if(typeof(props.display)==='string')
this.texture = TextureCache[props.display || 'box']; this.texture = TextureCache[props.display || 'box'];
else
this.addChild(props.display);
this.restitution = props.restitution; this.restitution = props.restitution;
this.velocityX = this.initialVelocityX = props.initialVelocityX || 0; this.velocityX = this.initialVelocityX = props.initialVelocityX || 0;
......
import { Sprite, TextureCache } from 'spark-wrapper-fyge';
export default class Ground extends Sprite {
constructor(props) {
super();
this.data = props.data;
this.display = props.display;
this.addChild(this.display);
this.x = this.data.x;
this.y = this.data.y;
}
onEnterFrame() {
}
}
import { WidgetBase, Event } from 'spark-wrapper-fyge'; import { WidgetBase, Event, Shape } from 'spark-wrapper-fyge';
import metaConfig from '../meta.json'; import metaConfig from '../meta.json';
import Body from './Body'; import Body from './Body';
import Ground from './Ground';
const createGroundDisplay = (ground) => {
const shape = new Shape();
shape.beginFill(0, 1);
shape.drawRect(0, 0, ground.width, ground.height);
shape.endFill();
return shape;
}
class GameStage extends WidgetBase { class GameStage extends WidgetBase {
onLaunched() { onLaunched() {
this.bodys = []; this.bodys = [];
...@@ -10,31 +20,44 @@ class GameStage extends WidgetBase { ...@@ -10,31 +20,44 @@ class GameStage extends WidgetBase {
this this
); );
this.addbodys(); this.addbodys();
// this.addGround({x:0,y:500, width:300,height:10}); const groundData = { x: 0, y: this.stage.viewRect.height / 2, width: 300, height: 10 };
this.addGround({x:0,y:this.stage.viewRect.height, width:300,height:10}); const ground = new Ground({ data: groundData, display: createGroundDisplay(groundData) })
// ground = this.stage.viewRect.height; this.addGround(ground);
setTimeout(() => {
this.removeGround(ground)
}, 3000);
} }
grounds; grounds;
addGround(ground){ addGround(ground) {
this.grounds = this.grounds||[]; this.grounds = this.grounds || [];
this.grounds.push(ground); this.grounds.push(ground);
this.addChild(ground)
}
removeGround(ground) {
const index = this.grounds.indexOf(ground);
if (index != -1) {
this.removeChild(ground);
this.grounds.splice(index, 1);
}
} }
addbodys() { addbodys() {
const ball = new Body({ const ball = new Body({
display: 'ball', display: 'ball',
initialVelocityY: 0, initialVelocityY: 0,
accelerationY: 2, accelerationY: 2,
restitution:0 restitution: 0
}); });
const block = new Body({ const block = new Body({
display: 'box', display: 'box',
initialVelocityY: 0, initialVelocityY: 0,
accelerationY: 0, accelerationY: 2,
restitution:0 restitution: 0
}); });
// block.x = 300; block.x = 300;
this.addChild(block); this.addChild(block);
this.bodys.push(block); this.bodys.push(block);
...@@ -54,14 +77,13 @@ class GameStage extends WidgetBase { ...@@ -54,14 +77,13 @@ class GameStage extends WidgetBase {
//默认从上往下走,碰到第一个就停止 //默认从上往下走,碰到第一个就停止
for (let i = 0; i < this.grounds.length; i++) { for (let i = 0; i < this.grounds.length; i++) {
const ground = this.grounds[i]; const ground = this.grounds[i];
// console.log(y0, ground.y)
if (y0 > ground.y) { if (y0 > ground.y) {
body.y = ground.y - body.height; body.y = ground.y - body.height;
body.velocityY = -body.velocityY * body.restitution; body.velocityY = -body.velocityY * body.restitution;
break; break;
} }
} }
} }
} }
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
}, },
{ {
"name": "ball", "name": "ball",
"url": "//yun.duiba.com.cn/aurora/assets/b172bfd984e9acb8d6141ef0a978555dd86056bc.png", "url": "//yun.duiba.com.cn/aurora/assets/7dc4fe037846b7b7078c4170d8c947faf36d8df3.png",
"uuid": "ball", "uuid": "ball",
"ext": ".png" "ext": ".png"
}, },
......
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