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
4ade1232
Commit
4ade1232
authored
Feb 15, 2021
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
454cb6a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
47 deletions
+29
-47
Body.js
test/src/game/Body.js
+1
-0
main.js
test/src/game/main.js
+28
-47
No files found.
test/src/game/Body.js
View file @
4ade1232
...
@@ -5,6 +5,7 @@ export default class Body extends Sprite {
...
@@ -5,6 +5,7 @@ export default class Body extends Sprite {
this
.
texture
=
TextureCache
[
props
.
display
||
'box'
];
this
.
texture
=
TextureCache
[
props
.
display
||
'box'
];
this
.
restitution
=
props
.
restitution
||
1
this
.
velocityX
=
this
.
initialVelocityX
=
props
.
initialVelocityX
||
0
;
this
.
velocityX
=
this
.
initialVelocityX
=
props
.
initialVelocityX
||
0
;
this
.
velocityY
=
this
.
initialVelocityY
=
props
.
initialVelocityY
||
0
;
this
.
velocityY
=
this
.
initialVelocityY
=
props
.
initialVelocityY
||
0
;
...
...
test/src/game/main.js
View file @
4ade1232
import
{
WidgetBase
,
Event
}
from
'spark-wrapper-fyge'
;
import
{
WidgetBase
,
Event
}
from
'spark-wrapper-fyge'
;
import
metaConfig
from
'../meta.json'
;
import
metaConfig
from
'../meta.json'
;
import
Body
from
'./Body'
;
import
Body
from
'./Body'
;
let
ground
;
class
GameStage
extends
WidgetBase
{
class
GameStage
extends
WidgetBase
{
onLaunched
()
{
onLaunched
()
{
this
.
bodys
=
[];
this
.
bodys
=
[];
...
@@ -11,65 +11,46 @@ class GameStage extends WidgetBase {
...
@@ -11,65 +11,46 @@ class GameStage extends WidgetBase {
this
this
);
);
this
.
addbodys
();
this
.
addbodys
();
ground
=
this
.
stage
.
viewRect
.
height
;
}
}
addbodys
()
{
addbodys
()
{
const
enemy
=
new
Body
({
const
ball
=
new
Body
({
display
:
'enemy'
,
display
:
'ball'
,
initialVelocityY
:
1
initialVelocityY
:
2
,
accelerationY
:
2
,
restitution
:
0.85
});
});
const
bullet
=
new
Body
({
const
block
=
new
Body
({
display
:
'bullet'
,
display
:
'box'
,
initialVelocityY
:
-
4
initialVelocityY
:
2
,
accelerationY
:
2
,
restitution
:
0.4
});
});
enemy
.
x
=
150
;
block
.
x
=
300
;
enemy
.
y
=
0
;
bullet
.
x
=
170
;
bullet
.
y
=
600
;
this
.
addChild
(
enemy
);
this
.
bodys
.
push
(
enemy
);
this
.
addChild
(
bullet
);
this
.
addChild
(
block
);
this
.
bodys
.
push
(
bullet
);
this
.
bodys
.
push
(
block
);
this
.
addChild
(
ball
);
this
.
bodys
.
push
(
ball
);
}
}
onEnterFrame
()
{
onEnterFrame
()
{
this
.
bodys
.
forEach
(
i
=>
i
.
onEnterFrame
());
this
.
bodys
.
forEach
(
i
=>
{
i
.
onEnterFrame
();
const
isCollide
=
this
.
checkCollide
(
this
.
bodys
[
0
],
this
.
bodys
[
1
])
this
.
checkCollideGround
(
i
);
if
(
isCollide
)
});
this
.
stopGame
();
}
checkCollide
(
A
,
B
)
{
const
pointA
=
[
A
.
x
+
A
.
width
/
2
,
A
.
y
+
A
.
height
/
2
];
const
pointB
=
[
B
.
x
+
B
.
width
/
2
,
B
.
y
+
B
.
height
/
2
];
const
x0
=
Math
.
abs
(
pointA
[
0
]
-
pointB
[
0
]);
const
y0
=
Math
.
abs
(
pointA
[
1
]
-
pointB
[
1
]);
const
x1
=
A
.
width
/
2
+
B
.
width
/
2
;
const
y1
=
A
.
height
/
2
+
B
.
height
/
2
;
return
x0
<
x1
&&
y0
<
y1
;
}
stopGame
()
{
this
.
stage
.
removeEventListener
(
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
,
this
);
}
}
/**
checkCollideGround
(
body
)
{
* 销毁回调
const
y0
=
body
.
y
+
body
.
height
;
*/
if
(
y0
>
ground
)
{
onDestroy
()
{
body
.
y
=
ground
-
body
.
height
;
}
body
.
velocityY
=
-
body
.
velocityY
*
body
.
restitution
;
start
()
{
}
}
stop
()
{
}
}
}
}
...
...
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