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
66f73525
Commit
66f73525
authored
Apr 05, 2021
by
honingwon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
fbd059e5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
13 deletions
+24
-13
main.js
test/src/game/main.js
+24
-13
No files found.
test/src/game/main.js
View file @
66f73525
import
{
WidgetBase
,
Event
}
from
'spark-wrapper-fyge'
;
import
metaConfig
from
'../meta.json'
;
import
Body
from
'./Body'
;
let
ground
;
class
GameStage
extends
WidgetBase
{
onLaunched
()
{
this
.
bodys
=
[];
...
...
@@ -11,25 +10,31 @@ class GameStage extends WidgetBase {
this
);
this
.
addbodys
();
ground
=
this
.
stage
.
viewRect
.
height
;
// this.addGround({x:0,y:500, width:300,height:10});
this
.
addGround
({
x
:
0
,
y
:
this
.
stage
.
viewRect
.
height
,
width
:
300
,
height
:
10
});
// ground = this.stage.viewRect.height;
}
grounds
;
addGround
(
ground
){
this
.
grounds
=
this
.
grounds
||
[];
this
.
grounds
.
push
(
ground
);
}
addbodys
()
{
const
ball
=
new
Body
({
display
:
'ball'
,
initialVelocityY
:
2
,
initialVelocityY
:
0
,
accelerationY
:
2
,
restitution
:
0
.85
restitution
:
0
});
const
block
=
new
Body
({
display
:
'box'
,
initialVelocityY
:
2
,
accelerationY
:
2
,
restitution
:
0
.4
initialVelocityY
:
0
,
accelerationY
:
0
,
restitution
:
0
});
block
.
x
=
300
;
//
block.x = 300;
this
.
addChild
(
block
);
this
.
bodys
.
push
(
block
);
...
...
@@ -46,12 +51,18 @@ class GameStage extends WidgetBase {
checkCollideGround
(
body
)
{
const
y0
=
body
.
y
+
body
.
height
;
if
(
y0
>
ground
)
{
body
.
y
=
ground
-
body
.
height
;
//默认从上往下走,碰到第一个就停止
for
(
let
i
=
0
;
i
<
this
.
grounds
.
length
;
i
++
)
{
const
ground
=
this
.
grounds
[
i
];
if
(
y0
>
ground
.
y
)
{
body
.
y
=
ground
.
y
-
body
.
height
;
body
.
velocityY
=
-
body
.
velocityY
*
body
.
restitution
;
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