Commit 8c416f7e authored by wildfirecode13's avatar wildfirecode13

1

parent 9abebb1e
import { Sprite, TextureCache } from 'spark-wrapper-fyge';
export default class DropItem extends Sprite {
export default class Body extends Sprite {
constructor(props) {
super();
this.texture = TextureCache['box'];
this.texture = TextureCache[props.display || 'box'];
this.velocityX = this.initialVelocityX = props.initialVelocityX || 0;
this.velocityY = this.initialVelocityY = props.initialVelocityY || 0;
......
import { WidgetBase, Event } from 'spark-wrapper-fyge';
import metaConfig from '../meta.json';
import DropItem from './DropItem';
/**
*
*
*/
import Body from './Body';
class GameStage extends WidgetBase {
onLaunched() {
this.drops = [];
this.bodys = [];
this.stage.addEventListener(
Event.ENTER_FRAME,
this.onEnterFrame,
this
);
this.addDrops();
this.addbodys();
}
addDrops() {
const drop = new DropItem({
initialVelocityY: -50,
initialVelocityX: 10,
accelerationY:2
addbodys() {
const ball1 = new Body({
display: 'ball',
initialVelocityX: 2,
initialVelocityY: 2
});
const ball2 = new Body({
display: 'ball',
initialVelocityX: -2,
initialVelocityY: -2
});
drop.y = 1000;
this.addChild(drop);
this.drops.push(drop);
ball1.x = 0;
ball1.y = 0;
ball2.x = 600;
ball2.y = 600;
this.addChild(ball1);
this.bodys.push(ball1);
this.addChild(ball2);
this.bodys.push(ball2);
}
onEnterFrame() {
this.drops.forEach(i => i.onEnterFrame());
this.bodys.forEach(i => i.onEnterFrame());
const isCollide = this.checkCollide(this.bodys[0], this.bodys[1])
if (isCollide)
this.stopGame();
}
checkCollide(A, B) {
const d = A.width;
const r = d / 2;
const pointA = [A.x + r, A.y + r];
const pointB = [B.x + r, B.y + r];
const distanceX = Math.abs(pointA[0] - pointB[0]);
const distanceY = Math.abs(pointA[1] - pointB[1]);
const distanceAB = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
return distanceAB < d;
}
stopGame() {
this.stage.removeEventListener(
Event.ENTER_FRAME,
this.onEnterFrame,
this
);
}
/**
......
......@@ -17,10 +17,16 @@
},
{
"name": "box",
"url": "//yun.duiba.com.cn/spark/assets/022e25a3984ff122fbf960bd0cb87bff48f8c3bf.png",
"url": "//yun.duiba.com.cn/aurora/assets/6fb4612326d4e78b715a83d1114fa2d96fb8adcb.png",
"uuid": "box",
"ext": ".png"
},
{
"name": "ball",
"url": "//yun.duiba.com.cn/aurora/assets/b172bfd984e9acb8d6141ef0a978555dd86056bc.png",
"uuid": "ball",
"ext": ".png"
},
{
"name": "bg",
"url": "//yun.duiba.com.cn/spark/assets/bg.c4359b9ea9e843cd8d929567b2fb52ed5518e105.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