Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
playground
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
wildfirecode13
playground
Commits
8c416f7e
Commit
8c416f7e
authored
Feb 15, 2021
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
9abebb1e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
19 deletions
+59
-19
Body.js
test/src/game/Body.js
+2
-2
main.js
test/src/game/main.js
+50
-16
meta.json
test/src/meta.json
+7
-1
No files found.
test/src/game/
DropItem
.js
→
test/src/game/
Body
.js
View file @
8c416f7e
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
;
...
...
test/src/game/main.js
View file @
8c416f7e
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
.
drop
s
=
[];
this
.
body
s
=
[];
this
.
stage
.
addEventListener
(
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
,
this
);
this
.
add
Drop
s
();
this
.
add
body
s
();
}
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
);
}
/**
...
...
test/src/meta.json
View file @
8c416f7e
...
...
@@ -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"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment