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
f9df87f4
Commit
f9df87f4
authored
Apr 06, 2021
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
f56db825
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
19 deletions
+15
-19
main.js
test/src/game/main.js
+15
-19
No files found.
test/src/game/main.js
View file @
f9df87f4
...
@@ -20,17 +20,17 @@ class GameStage extends WidgetBase {
...
@@ -20,17 +20,17 @@ class GameStage extends WidgetBase {
this
this
);
);
this
.
addbodys
();
this
.
addbodys
();
const
groundData
=
{
x
:
0
,
y
:
this
.
stage
.
viewRect
.
height
/
2
,
width
:
3
00
,
height
:
10
};
const
groundData
=
{
x
:
0
,
y
:
this
.
stage
.
viewRect
.
height
/
2
,
width
:
1
00
,
height
:
10
};
const
ground
=
new
Ground
({
data
:
groundData
,
display
:
createGroundDisplay
(
groundData
)
})
const
ground
=
new
Ground
({
data
:
groundData
,
display
:
createGroundDisplay
(
groundData
)
})
this
.
addGround
(
ground
);
this
.
addGround
(
ground
);
const
groundData1
=
{
x
:
400
,
y
:
this
.
stage
.
viewRect
.
height
/
3
*
2
,
width
:
2
00
,
height
:
10
};
const
groundData1
=
{
x
:
100
,
y
:
this
.
stage
.
viewRect
.
height
/
3
*
2
,
width
:
1
00
,
height
:
10
};
const
ground1
=
new
Ground
({
data
:
groundData1
,
display
:
createGroundDisplay
(
groundData1
)
})
const
ground1
=
new
Ground
({
data
:
groundData1
,
display
:
createGroundDisplay
(
groundData1
)
})
this
.
addGround
(
ground1
);
this
.
addGround
(
ground1
);
// setTimeout(() => {
const
groundData2
=
{
x
:
200
,
y
:
this
.
stage
.
viewRect
.
height
/
3
*
2
*
1.2
,
width
:
200
,
height
:
10
};
// this.removeGround(ground
)
const
ground2
=
new
Ground
({
data
:
groundData2
,
display
:
createGroundDisplay
(
groundData2
)
}
)
// }, 3000
);
this
.
addGround
(
ground2
);
}
}
grounds
;
grounds
;
...
@@ -50,22 +50,10 @@ class GameStage extends WidgetBase {
...
@@ -50,22 +50,10 @@ class GameStage extends WidgetBase {
const
ball
=
new
Body
({
const
ball
=
new
Body
({
display
:
'box'
,
display
:
'box'
,
initialVelocityY
:
0
,
initialVelocityY
:
0
,
initialVelocityX
:
2
,
initialVelocityX
:
1
,
accelerationY
:
2
,
accelerationY
:
2
,
restitution
:
0
restitution
:
0
});
});
const
block
=
new
Body
({
display
:
'box'
,
initialVelocityY
:
0
,
accelerationY
:
2
,
restitution
:
0
});
block
.
x
=
620
;
this
.
addChild
(
block
);
this
.
bodys
.
push
(
block
);
this
.
addChild
(
ball
);
this
.
addChild
(
ball
);
this
.
bodys
.
push
(
ball
);
this
.
bodys
.
push
(
ball
);
}
}
...
@@ -82,13 +70,21 @@ class GameStage extends WidgetBase {
...
@@ -82,13 +70,21 @@ 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)
const
dis0
=
body
.
width
/
2
+
ground
.
data
.
width
/
2
;
const
dis0
=
body
.
width
/
2
+
ground
.
data
.
width
/
2
;
const
dis1
=
Math
.
abs
(
body
.
x
+
body
.
width
/
2
-
ground
.
data
.
x
-
ground
.
data
.
width
/
2
);
const
dis1
=
Math
.
abs
(
body
.
x
+
body
.
width
/
2
-
ground
.
data
.
x
-
ground
.
data
.
width
/
2
);
if
(
y0
>
ground
.
y
&&
dis1
<
dis0
)
{
if
(
y0
>
ground
.
y
&&
dis1
<
dis0
)
{
// if (!body.checkCollideGround) {
// body.checkCollideGround = ground;
// console.log('碰撞了地面', JSON.stringify(ground.data));
// }
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
;
}
else
{
// if (body.checkCollideGround) {
// console.log('取消碰撞地面', JSON.stringify(ground.data));
// }
// body.checkCollideGround = null;
}
}
}
}
}
}
...
...
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