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
ec830ad7
Commit
ec830ad7
authored
Apr 06, 2021
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
cc8ebb4c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
30 deletions
+29
-30
StaticBody.js
test/src/game/StaticBody.js
+1
-1
main.js
test/src/game/main.js
+28
-29
No files found.
test/src/game/
Ground
.js
→
test/src/game/
StaticBody
.js
View file @
ec830ad7
import
{
Sprite
,
TextureCache
}
from
'spark-wrapper-fyge'
;
export
default
class
Ground
extends
Sprite
{
export
default
class
StaticBody
extends
Sprite
{
constructor
(
props
)
{
super
();
this
.
data
=
props
.
data
;
...
...
test/src/game/main.js
View file @
ec830ad7
import
{
WidgetBase
,
Event
,
Shape
}
from
'spark-wrapper-fyge'
;
import
metaConfig
from
'../meta.json'
;
import
Body
from
'./Body'
;
import
Ground
from
'./Ground
'
;
import
StaticBody
from
'./StaticBody
'
;
const
create
GroundDisplay
=
(
ground
)
=>
{
const
create
StaticBodyDisplay
=
(
staticBody
)
=>
{
const
shape
=
new
Shape
();
shape
.
beginFill
(
0
,
1
);
shape
.
drawRect
(
0
,
0
,
ground
.
width
,
ground
.
height
);
shape
.
drawRect
(
0
,
0
,
staticBody
.
width
,
staticBody
.
height
);
shape
.
endFill
();
return
shape
;
}
...
...
@@ -20,32 +20,31 @@ class GameStage extends WidgetBase {
this
);
const
ground
Data
=
{
x
:
0
,
y
:
this
.
stage
.
viewRect
.
height
/
2
,
width
:
100
,
height
:
10
};
const
ground
=
new
Ground
({
data
:
groundData
,
display
:
createGroundDisplay
(
ground
Data
)
})
this
.
add
Ground
(
ground
);
const
staticBody
Data
=
{
x
:
0
,
y
:
this
.
stage
.
viewRect
.
height
/
2
,
width
:
100
,
height
:
10
};
const
staticBody
=
new
StaticBody
({
data
:
staticBodyData
,
display
:
createStaticBodyDisplay
(
staticBody
Data
)
})
this
.
add
StaticBoy
(
staticBody
);
const
ground
Data1
=
{
x
:
100
,
y
:
this
.
stage
.
viewRect
.
height
/
3
*
2
,
width
:
100
,
height
:
10
};
const
ground1
=
new
Ground
({
data
:
groundData1
,
display
:
createGroundDisplay
(
ground
Data1
)
})
this
.
add
Ground
(
ground
1
);
const
staticBody
Data1
=
{
x
:
100
,
y
:
this
.
stage
.
viewRect
.
height
/
3
*
2
,
width
:
100
,
height
:
10
};
const
staticBody1
=
new
StaticBody
({
data
:
staticBodyData1
,
display
:
createStaticBodyDisplay
(
staticBody
Data1
)
})
this
.
add
StaticBoy
(
staticBody
1
);
const
ground
Data2
=
{
x
:
200
,
y
:
this
.
stage
.
viewRect
.
height
/
3
*
2
*
1.2
,
width
:
200
,
height
:
10
};
const
ground2
=
new
Ground
({
data
:
groundData2
,
display
:
createGroundDisplay
(
ground
Data2
)
})
this
.
add
Ground
(
ground
2
);
const
staticBody
Data2
=
{
x
:
200
,
y
:
this
.
stage
.
viewRect
.
height
/
3
*
2
*
1.2
,
width
:
200
,
height
:
10
};
const
staticBody2
=
new
StaticBody
({
data
:
staticBodyData2
,
display
:
createStaticBodyDisplay
(
staticBody
Data2
)
})
this
.
add
StaticBoy
(
staticBody
2
);
this
.
addbodys
();
}
grounds
;
addGround
(
ground
)
{
this
.
grounds
=
this
.
grounds
||
[];
this
.
grounds
.
push
(
ground
);
this
.
addChild
(
ground
)
addStaticBoy
(
staticBody
)
{
this
.
staticBodys
=
this
.
staticBodys
||
[];
this
.
staticBodys
.
push
(
staticBody
);
this
.
addChild
(
staticBody
)
}
remove
Ground
(
ground
)
{
const
index
=
this
.
grounds
.
indexOf
(
ground
);
remove
StaticBody
(
staticBody
)
{
const
index
=
this
.
staticBodys
.
indexOf
(
staticBody
);
if
(
index
!=
-
1
)
{
this
.
removeChild
(
ground
);
this
.
ground
s
.
splice
(
index
,
1
);
this
.
removeChild
(
staticBody
);
this
.
staticBody
s
.
splice
(
index
,
1
);
}
}
addbodys
()
{
...
...
@@ -65,19 +64,19 @@ class GameStage extends WidgetBase {
onEnterFrame
()
{
this
.
bodys
.
forEach
(
i
=>
{
i
.
onEnterFrame
();
this
.
checkCollide
Ground
(
i
);
this
.
checkCollide
StaticBody
(
i
);
});
}
checkCollide
Ground
(
body
)
{
checkCollide
StaticBody
(
body
)
{
const
y0
=
body
.
y
+
body
.
bodyData
.
height
;
//默认从上往下走,碰到第一个就停止
for
(
let
i
=
0
;
i
<
this
.
ground
s
.
length
;
i
++
)
{
const
ground
=
this
.
ground
s
[
i
];
const
dis0
=
body
.
bodyData
.
width
/
2
+
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
)
{
body
.
y
=
ground
.
y
-
body
.
bodyData
.
height
;
for
(
let
i
=
0
;
i
<
this
.
staticBody
s
.
length
;
i
++
)
{
const
staticBody
=
this
.
staticBody
s
[
i
];
const
dis0
=
body
.
bodyData
.
width
/
2
+
staticBody
.
data
.
width
/
2
;
const
dis1
=
Math
.
abs
(
body
.
x
+
body
.
bodyData
.
width
/
2
-
staticBody
.
data
.
x
-
staticBody
.
data
.
width
/
2
);
if
(
y0
>
staticBody
.
y
&&
dis1
<
dis0
)
{
body
.
y
=
staticBody
.
y
-
body
.
bodyData
.
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