Commit 454cb6a3 authored by wildfirecode13's avatar wildfirecode13

1

parent a53839cf
...@@ -14,28 +14,26 @@ class GameStage extends WidgetBase { ...@@ -14,28 +14,26 @@ class GameStage extends WidgetBase {
} }
addbodys() { addbodys() {
const ball1 = new Body({ const enemy = new Body({
display: 'box', display: 'enemy',
initialVelocityX: 2, initialVelocityY: 1
initialVelocityY: 2
}); });
const ball2 = new Body({ const bullet = new Body({
display: 'box', display: 'bullet',
initialVelocityX: -2, initialVelocityY: -4
initialVelocityY: -2
}); });
ball1.x = 0; enemy.x = 150;
ball1.y = 0; enemy.y = 0;
ball2.x = 600; bullet.x = 170;
ball2.y = 600; bullet.y = 600;
this.addChild(ball1); this.addChild(enemy);
this.bodys.push(ball1); this.bodys.push(enemy);
this.addChild(ball2); this.addChild(bullet);
this.bodys.push(ball2); this.bodys.push(bullet);
} }
onEnterFrame() { onEnterFrame() {
...@@ -47,14 +45,13 @@ class GameStage extends WidgetBase { ...@@ -47,14 +45,13 @@ class GameStage extends WidgetBase {
} }
checkCollide(A, B) { checkCollide(A, B) {
const d = A.width; const pointA = [A.x + A.width / 2, A.y + A.height / 2];
const r = d / 2; const pointB = [B.x + B.width / 2, B.y + B.height / 2];
const pointA = [A.x + r, A.y + r]; const x0 = Math.abs(pointA[0] - pointB[0]);
const pointB = [B.x + r, B.y + r]; const y0 = Math.abs(pointA[1] - pointB[1]);
const distanceX = Math.abs(pointA[0] - pointB[0]); const x1 = A.width/2 + B.width/2;
const distanceY = Math.abs(pointA[1] - pointB[1]); const y1 = A.height/2 + B.height/2;
const distanceAB = Math.sqrt(distanceX * distanceX + distanceY * distanceY); return x0 < x1 && y0 < y1;
return distanceAB < d;
} }
stopGame() { stopGame() {
......
...@@ -9,6 +9,18 @@ ...@@ -9,6 +9,18 @@
] ]
}, },
"assets": [ "assets": [
{
"name": "enemy",
"ext": ".png",
"url": "//yun.duiba.com.cn/spark/assets/enemy1_fly1.1cded0d917c44d22ddce058f239e1cfac1b506c2.png",
"uuid": "enemy"
},
{
"name": "bullet",
"ext": ".png",
"url": "//yun.duiba.com.cn/spark/assets/bullet1.63bb85f32cabe5f986366c2d428c5e2aa2435230.png",
"uuid": "bullet"
},
{ {
"name": "齿轮", "name": "齿轮",
"url": "//yun.duiba.com.cn/spark/assets/齿轮8.fce30eaadda192b44a1b80038011947830d45ad8.png", "url": "//yun.duiba.com.cn/spark/assets/齿轮8.fce30eaadda192b44a1b80038011947830d45ad8.png",
...@@ -53,4 +65,4 @@ ...@@ -53,4 +65,4 @@
} }
} }
} }
} }
\ No newline at end of file
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