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
cc8ebb4c
Commit
cc8ebb4c
authored
Apr 06, 2021
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
c7e435f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
12 deletions
+20
-12
Body.js
test/src/game/Body.js
+8
-4
main.js
test/src/game/main.js
+12
-8
No files found.
test/src/game/Body.js
View file @
cc8ebb4c
import
{
Sprite
,
TextureCache
}
from
'spark-wrapper-fyge'
;
import
{
Sprite
,
TextureCache
}
from
'spark-wrapper-fyge'
;
export
default
class
Body
extends
Sprite
{
export
default
class
Body
extends
Sprite
{
constructor
(
props
)
{
constructor
(
props
)
{
super
();
super
();
if
(
typeof
(
props
.
display
)
===
'string'
)
this
.
bodyData
=
props
.
bodyData
;
this
.
texture
=
TextureCache
[
props
.
display
||
'box'
];
else
const
img
=
new
Sprite
();
this
.
addChild
(
props
.
display
);
img
.
texture
=
TextureCache
[
props
.
display
];
img
.
x
=
props
.
offset
[
0
];
img
.
y
=
props
.
offset
[
1
];
this
.
addChild
(
img
);
this
.
restitution
=
props
.
restitution
;
this
.
restitution
=
props
.
restitution
;
this
.
velocityX
=
this
.
initialVelocityX
=
props
.
initialVelocityX
||
0
;
this
.
velocityX
=
this
.
initialVelocityX
=
props
.
initialVelocityX
||
0
;
...
...
test/src/game/main.js
View file @
cc8ebb4c
...
@@ -19,7 +19,7 @@ class GameStage extends WidgetBase {
...
@@ -19,7 +19,7 @@ class GameStage extends WidgetBase {
this
.
onEnterFrame
,
this
.
onEnterFrame
,
this
this
);
);
this
.
addbodys
();
const
groundData
=
{
x
:
0
,
y
:
this
.
stage
.
viewRect
.
height
/
2
,
width
:
100
,
height
:
10
};
const
groundData
=
{
x
:
0
,
y
:
this
.
stage
.
viewRect
.
height
/
2
,
width
:
100
,
height
:
10
};
const
ground
=
new
Ground
({
data
:
groundData
,
display
:
createGroundDisplay
(
groundData
)
})
const
ground
=
new
Ground
({
data
:
groundData
,
display
:
createGroundDisplay
(
groundData
)
})
this
.
addGround
(
ground
);
this
.
addGround
(
ground
);
...
@@ -31,6 +31,8 @@ class GameStage extends WidgetBase {
...
@@ -31,6 +31,8 @@ class GameStage extends WidgetBase {
const
groundData2
=
{
x
:
200
,
y
:
this
.
stage
.
viewRect
.
height
/
3
*
2
*
1.2
,
width
:
200
,
height
:
10
};
const
groundData2
=
{
x
:
200
,
y
:
this
.
stage
.
viewRect
.
height
/
3
*
2
*
1.2
,
width
:
200
,
height
:
10
};
const
ground2
=
new
Ground
({
data
:
groundData2
,
display
:
createGroundDisplay
(
groundData2
)
})
const
ground2
=
new
Ground
({
data
:
groundData2
,
display
:
createGroundDisplay
(
groundData2
)
})
this
.
addGround
(
ground2
);
this
.
addGround
(
ground2
);
this
.
addbodys
();
}
}
grounds
;
grounds
;
...
@@ -49,10 +51,12 @@ class GameStage extends WidgetBase {
...
@@ -49,10 +51,12 @@ class GameStage extends WidgetBase {
addbodys
()
{
addbodys
()
{
const
ball
=
new
Body
({
const
ball
=
new
Body
({
display
:
'box'
,
display
:
'box'
,
offset
:[
-
23
,
0
],
initialVelocityY
:
0
,
initialVelocityY
:
0
,
initialVelocityX
:
2
,
initialVelocityX
:
1
,
accelerationY
:
2
,
accelerationY
:
1
,
restitution
:
0
restitution
:
0
,
bodyData
:{
width
:
34
,
height
:
91
}
});
});
this
.
addChild
(
ball
);
this
.
addChild
(
ball
);
this
.
bodys
.
push
(
ball
);
this
.
bodys
.
push
(
ball
);
...
@@ -66,14 +70,14 @@ class GameStage extends WidgetBase {
...
@@ -66,14 +70,14 @@ class GameStage extends WidgetBase {
}
}
checkCollideGround
(
body
)
{
checkCollideGround
(
body
)
{
const
y0
=
body
.
y
+
body
.
height
;
const
y0
=
body
.
y
+
body
.
bodyData
.
height
;
//默认从上往下走,碰到第一个就停止
//默认从上往下走,碰到第一个就停止
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
];
const
dis0
=
body
.
width
/
2
+
ground
.
data
.
width
/
2
;
const
dis0
=
body
.
bodyData
.
width
/
2
+
ground
.
data
.
width
/
2
;
const
dis1
=
Math
.
abs
(
body
.
x
+
body
.
width
/
2
-
ground
.
data
.
x
-
ground
.
data
.
width
/
2
);
const
dis1
=
Math
.
abs
(
body
.
x
+
body
.
bodyData
.
width
/
2
-
ground
.
data
.
x
-
ground
.
data
.
width
/
2
);
if
(
y0
>
ground
.
y
&&
dis1
<
dis0
)
{
if
(
y0
>
ground
.
y
&&
dis1
<
dis0
)
{
body
.
y
=
ground
.
y
-
body
.
height
;
body
.
y
=
ground
.
y
-
body
.
bodyData
.
height
;
body
.
velocityY
=
-
body
.
velocityY
*
body
.
restitution
;
body
.
velocityY
=
-
body
.
velocityY
*
body
.
restitution
;
break
;
break
;
}
}
...
...
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