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
48ed6490
Commit
48ed6490
authored
Apr 06, 2021
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
66f73525
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
15 deletions
+55
-15
Body.js
test/src/game/Body.js
+4
-1
Ground.js
test/src/game/Ground.js
+15
-0
main.js
test/src/game/main.js
+35
-13
meta.json
test/src/meta.json
+1
-1
No files found.
test/src/game/Body.js
View file @
48ed6490
...
@@ -3,7 +3,10 @@ export default class Body extends Sprite {
...
@@ -3,7 +3,10 @@ export default class Body extends Sprite {
constructor
(
props
)
{
constructor
(
props
)
{
super
();
super
();
if
(
typeof
(
props
.
display
)
===
'string'
)
this
.
texture
=
TextureCache
[
props
.
display
||
'box'
];
this
.
texture
=
TextureCache
[
props
.
display
||
'box'
];
else
this
.
addChild
(
props
.
display
);
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/Ground.js
0 → 100644
View file @
48ed6490
import
{
Sprite
,
TextureCache
}
from
'spark-wrapper-fyge'
;
export
default
class
Ground
extends
Sprite
{
constructor
(
props
)
{
super
();
this
.
data
=
props
.
data
;
this
.
display
=
props
.
display
;
this
.
addChild
(
this
.
display
);
this
.
x
=
this
.
data
.
x
;
this
.
y
=
this
.
data
.
y
;
}
onEnterFrame
()
{
}
}
test/src/game/main.js
View file @
48ed6490
import
{
WidgetBase
,
Event
}
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'
;
const
createGroundDisplay
=
(
ground
)
=>
{
const
shape
=
new
Shape
();
shape
.
beginFill
(
0
,
1
);
shape
.
drawRect
(
0
,
0
,
ground
.
width
,
ground
.
height
);
shape
.
endFill
();
return
shape
;
}
class
GameStage
extends
WidgetBase
{
class
GameStage
extends
WidgetBase
{
onLaunched
()
{
onLaunched
()
{
this
.
bodys
=
[];
this
.
bodys
=
[];
...
@@ -10,31 +20,44 @@ class GameStage extends WidgetBase {
...
@@ -10,31 +20,44 @@ class GameStage extends WidgetBase {
this
this
);
);
this
.
addbodys
();
this
.
addbodys
();
// this.addGround({x:0,y:500, width:300,height:10});
const
groundData
=
{
x
:
0
,
y
:
this
.
stage
.
viewRect
.
height
/
2
,
width
:
300
,
height
:
10
};
this
.
addGround
({
x
:
0
,
y
:
this
.
stage
.
viewRect
.
height
,
width
:
300
,
height
:
10
});
const
ground
=
new
Ground
({
data
:
groundData
,
display
:
createGroundDisplay
(
groundData
)
})
// ground = this.stage.viewRect.height;
this
.
addGround
(
ground
);
setTimeout
(()
=>
{
this
.
removeGround
(
ground
)
},
3000
);
}
}
grounds
;
grounds
;
addGround
(
ground
){
addGround
(
ground
)
{
this
.
grounds
=
this
.
grounds
||
[];
this
.
grounds
=
this
.
grounds
||
[];
this
.
grounds
.
push
(
ground
);
this
.
grounds
.
push
(
ground
);
this
.
addChild
(
ground
)
}
removeGround
(
ground
)
{
const
index
=
this
.
grounds
.
indexOf
(
ground
);
if
(
index
!=
-
1
)
{
this
.
removeChild
(
ground
);
this
.
grounds
.
splice
(
index
,
1
);
}
}
}
addbodys
()
{
addbodys
()
{
const
ball
=
new
Body
({
const
ball
=
new
Body
({
display
:
'ball'
,
display
:
'ball'
,
initialVelocityY
:
0
,
initialVelocityY
:
0
,
accelerationY
:
2
,
accelerationY
:
2
,
restitution
:
0
restitution
:
0
});
});
const
block
=
new
Body
({
const
block
=
new
Body
({
display
:
'box'
,
display
:
'box'
,
initialVelocityY
:
0
,
initialVelocityY
:
0
,
accelerationY
:
0
,
accelerationY
:
2
,
restitution
:
0
restitution
:
0
});
});
//
block.x = 300;
block
.
x
=
300
;
this
.
addChild
(
block
);
this
.
addChild
(
block
);
this
.
bodys
.
push
(
block
);
this
.
bodys
.
push
(
block
);
...
@@ -54,14 +77,13 @@ class GameStage extends WidgetBase {
...
@@ -54,14 +77,13 @@ class GameStage extends WidgetBase {
//默认从上往下走,碰到第一个就停止
//默认从上往下走,碰到第一个就停止
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
];
// console.log(y0, ground.y)
if
(
y0
>
ground
.
y
)
{
if
(
y0
>
ground
.
y
)
{
body
.
y
=
ground
.
y
-
body
.
height
;
body
.
y
=
ground
.
y
-
body
.
height
;
body
.
velocityY
=
-
body
.
velocityY
*
body
.
restitution
;
body
.
velocityY
=
-
body
.
velocityY
*
body
.
restitution
;
break
;
break
;
}
}
}
}
}
}
}
}
...
...
test/src/meta.json
View file @
48ed6490
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
},
},
{
{
"name"
:
"ball"
,
"name"
:
"ball"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/
b172bfd984e9acb8d6141ef0a978555dd86056bc
.png"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/
7dc4fe037846b7b7078c4170d8c947faf36d8df3
.png"
,
"uuid"
:
"ball"
,
"uuid"
:
"ball"
,
"ext"
:
".png"
"ext"
:
".png"
},
},
...
...
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