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
Hide 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'
;
import
{
Sprite
,
TextureCache
}
from
'spark-wrapper-fyge'
;
export
default
class
Ground
extends
Sprite
{
export
default
class
StaticBody
extends
Sprite
{
constructor
(
props
)
{
constructor
(
props
)
{
super
();
super
();
this
.
data
=
props
.
data
;
this
.
data
=
props
.
data
;
...
...
test/src/game/main.js
View file @
ec830ad7
import
{
WidgetBase
,
Event
,
Shape
}
from
'spark-wrapper-fyge'
;
import
{
WidgetBase
,
Event
,
Shape
}
from
'spark-wrapper-fyge'
;
import
metaConfig
from
'../meta.json'
;
import
metaConfig
from
'../meta.json'
;
import
Body
from
'./Body'
;
import
Body
from
'./Body'
;
import
Ground
from
'./Ground
'
;
import
StaticBody
from
'./StaticBody
'
;
const
create
GroundDisplay
=
(
ground
)
=>
{
const
create
StaticBodyDisplay
=
(
staticBody
)
=>
{
const
shape
=
new
Shape
();
const
shape
=
new
Shape
();
shape
.
beginFill
(
0
,
1
);
shape
.
beginFill
(
0
,
1
);
shape
.
drawRect
(
0
,
0
,
ground
.
width
,
ground
.
height
);
shape
.
drawRect
(
0
,
0
,
staticBody
.
width
,
staticBody
.
height
);
shape
.
endFill
();
shape
.
endFill
();
return
shape
;
return
shape
;
}
}
...
@@ -20,32 +20,31 @@ class GameStage extends WidgetBase {
...
@@ -20,32 +20,31 @@ class GameStage extends WidgetBase {
this
this
);
);
const
ground
Data
=
{
x
:
0
,
y
:
this
.
stage
.
viewRect
.
height
/
2
,
width
:
100
,
height
:
10
};
const
staticBody
Data
=
{
x
:
0
,
y
:
this
.
stage
.
viewRect
.
height
/
2
,
width
:
100
,
height
:
10
};
const
ground
=
new
Ground
({
data
:
groundData
,
display
:
createGroundDisplay
(
ground
Data
)
})
const
staticBody
=
new
StaticBody
({
data
:
staticBodyData
,
display
:
createStaticBodyDisplay
(
staticBody
Data
)
})
this
.
add
Ground
(
ground
);
this
.
add
StaticBoy
(
staticBody
);
const
ground
Data1
=
{
x
:
100
,
y
:
this
.
stage
.
viewRect
.
height
/
3
*
2
,
width
:
100
,
height
:
10
};
const
staticBody
Data1
=
{
x
:
100
,
y
:
this
.
stage
.
viewRect
.
height
/
3
*
2
,
width
:
100
,
height
:
10
};
const
ground1
=
new
Ground
({
data
:
groundData1
,
display
:
createGroundDisplay
(
ground
Data1
)
})
const
staticBody1
=
new
StaticBody
({
data
:
staticBodyData1
,
display
:
createStaticBodyDisplay
(
staticBody
Data1
)
})
this
.
add
Ground
(
ground
1
);
this
.
add
StaticBoy
(
staticBody
1
);
const
ground
Data2
=
{
x
:
200
,
y
:
this
.
stage
.
viewRect
.
height
/
3
*
2
*
1.2
,
width
:
200
,
height
:
10
};
const
staticBody
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
)
})
const
staticBody2
=
new
StaticBody
({
data
:
staticBodyData2
,
display
:
createStaticBodyDisplay
(
staticBody
Data2
)
})
this
.
add
Ground
(
ground
2
);
this
.
add
StaticBoy
(
staticBody
2
);
this
.
addbodys
();
this
.
addbodys
();
}
}
grounds
;
addStaticBoy
(
staticBody
)
{
addGround
(
ground
)
{
this
.
staticBodys
=
this
.
staticBodys
||
[];
this
.
grounds
=
this
.
grounds
||
[];
this
.
staticBodys
.
push
(
staticBody
);
this
.
grounds
.
push
(
ground
);
this
.
addChild
(
staticBody
)
this
.
addChild
(
ground
)
}
}
remove
Ground
(
ground
)
{
remove
StaticBody
(
staticBody
)
{
const
index
=
this
.
grounds
.
indexOf
(
ground
);
const
index
=
this
.
staticBodys
.
indexOf
(
staticBody
);
if
(
index
!=
-
1
)
{
if
(
index
!=
-
1
)
{
this
.
removeChild
(
ground
);
this
.
removeChild
(
staticBody
);
this
.
ground
s
.
splice
(
index
,
1
);
this
.
staticBody
s
.
splice
(
index
,
1
);
}
}
}
}
addbodys
()
{
addbodys
()
{
...
@@ -65,19 +64,19 @@ class GameStage extends WidgetBase {
...
@@ -65,19 +64,19 @@ class GameStage extends WidgetBase {
onEnterFrame
()
{
onEnterFrame
()
{
this
.
bodys
.
forEach
(
i
=>
{
this
.
bodys
.
forEach
(
i
=>
{
i
.
onEnterFrame
();
i
.
onEnterFrame
();
this
.
checkCollide
Ground
(
i
);
this
.
checkCollide
StaticBody
(
i
);
});
});
}
}
checkCollide
Ground
(
body
)
{
checkCollide
StaticBody
(
body
)
{
const
y0
=
body
.
y
+
body
.
bodyData
.
height
;
const
y0
=
body
.
y
+
body
.
bodyData
.
height
;
//默认从上往下走,碰到第一个就停止
//默认从上往下走,碰到第一个就停止
for
(
let
i
=
0
;
i
<
this
.
ground
s
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
this
.
staticBody
s
.
length
;
i
++
)
{
const
ground
=
this
.
ground
s
[
i
];
const
staticBody
=
this
.
staticBody
s
[
i
];
const
dis0
=
body
.
bodyData
.
width
/
2
+
ground
.
data
.
width
/
2
;
const
dis0
=
body
.
bodyData
.
width
/
2
+
staticBody
.
data
.
width
/
2
;
const
dis1
=
Math
.
abs
(
body
.
x
+
body
.
bodyData
.
width
/
2
-
ground
.
data
.
x
-
ground
.
data
.
width
/
2
);
const
dis1
=
Math
.
abs
(
body
.
x
+
body
.
bodyData
.
width
/
2
-
staticBody
.
data
.
x
-
staticBody
.
data
.
width
/
2
);
if
(
y0
>
ground
.
y
&&
dis1
<
dis0
)
{
if
(
y0
>
staticBody
.
y
&&
dis1
<
dis0
)
{
body
.
y
=
ground
.
y
-
body
.
bodyData
.
height
;
body
.
y
=
staticBody
.
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