Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zeroing-libs
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
zeroing-libs
Commits
7da17f99
Commit
7da17f99
authored
Aug 07, 2020
by
汪欢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
a
parent
d3d3c9d7
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
384 additions
and
153 deletions
+384
-153
main.js
src/custom/basket/debug/main.js
+128
-37
main.js.map
src/custom/basket/debug/main.js.map
+1
-1
GameView.ts
src/custom/basket/src/game/GameView.ts
+255
-115
No files found.
src/custom/basket/debug/main.js
View file @
7da17f99
...
...
@@ -114,8 +114,14 @@
_this
.
toRo
=
180
/
Math
.
PI
;
_this
.
loopMark
=
false
;
_this
.
guideMark
=
false
;
_this
.
ballAddSpeedX
=
1.2
;
_this
.
ballAddSpeedY
=
5.3
;
_this
.
inPointMark
=
false
;
_this
.
outPointMark
=
false
;
_this
.
boardMark
=
false
;
_this
.
pointMark
=
false
;
_this
.
planeMark
=
false
;
_this
.
stringMark
=
""
;
_this
.
ballAddSpeedX
=
-
40
;
_this
.
ballAddSpeedY
=
-
80
;
_this
.
gravity
=
-
5
;
_this
.
stepSpeed
=
[
0.5
,
3.5
];
_this
.
detaTimeEf
=
_this
.
stepSpeed
[
1
];
...
...
@@ -130,7 +136,27 @@
_this
.
clickMark
=
false
;
_this
.
once
(
engine
.
Event
.
ADDED_TO_STAGE
,
_this
.
start
,
_this
);
var
p2
=
window
[
"p2"
];
var
materialBall
=
new
p2
.
Material
(
1
);
_this
.
world
=
new
p2
.
World
();
_this
.
world
.
sleepMode
=
p2
.
World
.
BODY_SLEEPING
;
_this
.
world
.
gravity
=
[
0
,
10
];
var
box
=
new
p2
.
Box
({
width
:
20
,
height
:
200
,
material
:
materialBoard
,
});
_this
.
boxBody
=
new
p2
.
Body
({
mass
:
0
,
type
:
p2
.
Body
.
STATIC
,
position
:
[
20
,
400
],
});
_this
.
boxBody
.
addShape
(
box
);
_this
.
box
=
_this
.
createBox
(
0
,
-
100
,
20
,
200
);
_this
.
boxBody
.
displays
=
[
_this
.
box
];
_this
.
world
.
addBody
(
_this
.
boxBody
);
_this
.
world
.
defaultContactMaterial
.
friction
=
0.1
;
_this
.
world
.
defaultContactMaterial
.
restitution
=
1
;
_this
.
world
.
setGlobalStiffness
(
1
e5
);
var
materialBall
=
new
p2
.
Material
(
2
);
var
materialPoint
=
new
p2
.
Material
(
2
);
var
materialBoard
=
new
p2
.
Material
(
2
);
var
materialPlane
=
new
p2
.
Material
(
2
);
...
...
@@ -139,50 +165,77 @@
restitution
:
0.5
,
});
var
contactMaterialBallBoard
=
new
p2
.
ContactMaterial
(
materialBall
,
materialBoard
,
{
friction
:
0.
3
,
restitution
:
0.5
,
friction
:
0.
1
,
restitution
:
1
,
});
var
contactMaterialBallPlane
=
new
p2
.
ContactMaterial
(
materialBall
,
materialPlane
,
{
friction
:
0.
3
,
restitution
:
0.7
,
friction
:
0.
1
,
restitution
:
1
,
});
_this
.
world
=
new
p2
.
World
();
_this
.
world
.
sleepMode
=
p2
.
World
.
BODY_SLEEPING
;
_this
.
world
.
gravity
=
[
0
,
10
];
var
box
=
new
p2
.
Box
({
width
:
_this
.
config
.
boardBody
.
width
,
height
:
_this
.
config
.
boardBody
.
height
,
material
:
materialBoard
});
_this
.
boxBody
=
new
p2
.
Body
({
mass
:
0
,
type
:
p2
.
Body
.
STATIC
,
position
:
[
20
,
200
]
});
_this
.
boxBody
.
addShape
(
box
);
var
display
=
new
engine
.
Texture
(
getTextureByName
(
'篮板'
));
var
displays
=
new
engine
.
Sprite
(
display
);
_this
.
addChild
(
displays
);
_this
.
boxBody
.
displays
=
[
displays
];
_this
.
world
.
addBody
(
_this
.
boxBody
);
_this
.
world
.
defaultContactMaterial
.
friction
=
0.3
;
_this
.
world
.
defaultContactMaterial
.
restitution
=
0.6
;
_this
.
world
.
setGlobalStiffness
(
1
e5
);
_this
.
world
.
addContactMaterial
(
contactMaterialBallPoint
);
_this
.
world
.
addContactMaterial
(
contactMaterialBallBoard
);
_this
.
world
.
addContactMaterial
(
contactMaterialBallPlane
);
var
ball
=
new
p2
.
Circle
({
radius
:
60
});
_this
.
basketball
=
new
p2
.
Body
({
var
circleShape
=
new
p2
.
Circle
({
radius
:
1
,
material
:
materialPoint
,
});
var
circleBody
=
_this
.
circleBody
=
new
p2
.
Body
({
mass
:
0
,
position
:
[
60
,
500
],
type
:
p2
.
Body
.
STATIC
,
});
circleBody
.
addShape
(
circleShape
);
_this
.
world
.
addBody
(
circleBody
);
var
ellipse
=
_this
.
createBox
(
0
,
0
,
20
,
20
);
circleBody
.
displays
=
[
ellipse
];
var
circleShape1
=
new
p2
.
Circle
({
radius
:
1
,
material
:
materialPoint
,
});
var
circleBody1
=
_this
.
circleBody1
=
new
p2
.
Body
({
mass
:
0
,
position
:
[
200
,
500
],
type
:
p2
.
Body
.
STATIC
,
});
circleBody1
.
addShape
(
circleShape1
);
_this
.
world
.
addBody
(
circleBody1
);
var
ellipse2
=
_this
.
createBox
(
0
,
0
,
20
,
20
);
circleBody1
.
displays
=
[
ellipse2
];
var
ball
=
new
p2
.
Circle
({
radius
:
60
});
var
basketball
=
_this
.
basketball
=
new
p2
.
Body
({
mass
:
1
,
position
:
[
300
,
250
],
velocity
:
[
-
40
,
0
],
material
:
materialBall
velocity
:
[
0
,
4
0
],
material
:
materialBall
,
});
_this
.
basketball
.
addShape
(
ball
);
_this
.
world
.
addBody
(
_this
.
basketball
);
var
balldisplay
=
new
engine
.
Texture
(
getTextureByName
(
'篮球'
)
);
var
balldisplays
=
new
engine
.
Sprite
(
balldisplay
)
;
_this
.
addChild
(
balldisplays
)
;
_this
.
basketball
.
displays
=
[
balldisplays
]
;
_this
.
ball
=
_this
.
createCircle
(
);
_this
.
basketball
.
displays
=
[
_this
.
ball
]
;
var
stringMark
=
_this
.
stringMark
;
var
self
=
_this
;
var
plane
=
new
p2
.
Plane
();
_this
.
planeBody
=
new
p2
.
Body
({
position
:
[
engine
.
gameStage
.
width
/
2
,
engine
.
gameStage
.
height
-
100
]
});
_this
.
planeBody
=
new
p2
.
Body
({
position
:
[
engine
.
gameStage
.
width
,
engine
.
gameStage
.
height
-
200
],
material
:
materialPlane
,
});
_this
.
planeBody
.
angle
=
Math
.
PI
;
_this
.
planeBody
.
addShape
(
plane
);
_this
.
world
.
addBody
(
_this
.
planeBody
);
_this
.
plane
=
_this
.
createPlane
();
_this
.
planeBody
.
displays
=
[
_this
.
plane
];
_this
.
world
.
on
(
'beginContact'
,
function
(
e
)
{
if
(
e
.
bodyA
==
circleBody
||
e
.
bodyA
==
circleBody1
)
{
if
(
basketball
.
position
[
0
]
>
circleBody
.
position
[
0
]
&&
basketball
.
position
[
0
]
<
circleBody1
.
position
[
0
])
{
if
(
basketball
.
position
[
1
]
>
circleBody
.
position
[
1
]
||
basketball
.
position
[
1
]
>
circleBody1
.
position
[
1
])
{
console
.
log
(
"上往下"
);
self
.
isRight
=
!
self
.
isRight
;
self
.
changePosition
();
}
}
}
});
_this
.
addEventListener
(
engine
.
Event
.
ENTER_FRAME
,
_this
.
onEnterFrame
,
_this
);
return
_this
;
}
...
...
@@ -194,21 +247,30 @@
var
display
=
body
.
displays
[
0
];
display
.
x
=
body
.
position
[
0
];
display
.
y
=
body
.
position
[
1
];
display
.
rotation
=
body
.
angle
*
180
/
Math
.
PI
;
display
.
rotation
=
(
body
.
angle
*
180
)
/
Math
.
PI
;
}
if
(
this
.
basketball
.
position
[
0
]
<
-
120
)
{
this
.
basketball
.
position
[
0
]
=
750
;
}
if
(
this
.
basketball
.
position
[
0
]
>
750
+
120
)
{
this
.
basketball
.
position
[
0
]
=
-
120
;
}
};
GameView
.
prototype
.
createBox
=
function
()
{
GameView
.
prototype
.
createBox
=
function
(
x
,
y
,
w
,
h
)
{
var
sp
=
new
engine
.
Shape
();
sp
.
beginFill
(
0x0000ff
);
sp
.
drawRect
(
0
,
0
,
50
,
50
);
sp
.
drawRect
(
x
,
y
,
w
,
h
);
sp
.
endFill
();
sp
.
anchorX
=
sp
.
width
/
2
;
sp
.
anchorY
=
sp
.
height
/
2
;
this
.
addChild
(
sp
);
return
sp
;
};
GameView
.
prototype
.
createPlane
=
function
()
{
var
sp
=
new
engine
.
Shape
();
sp
.
beginFill
(
0x0000ff
,
1
);
sp
.
moveTo
(
0
,
0
);
sp
.
lineTo
(
engine
.
gameStage
.
width
,
0
);
sp
.
drawRect
(
0
,
-
10
,
engine
.
gameStage
.
width
,
1
0
);
sp
.
endFill
(
);
sp
.
anchorX
=
sp
.
width
/
2
;
sp
.
anchorY
=
sp
.
height
/
2
;
this
.
addChild
(
sp
);
...
...
@@ -217,17 +279,46 @@
GameView
.
prototype
.
createCircle
=
function
()
{
var
sp
=
new
engine
.
Shape
();
sp
.
beginFill
(
0xff0000
,
0.7
);
sp
.
drawCircle
(
200
,
15
0
,
60
);
sp
.
drawCircle
(
0
,
0
,
60
);
sp
.
endFill
();
sp
.
anchorX
=
sp
.
width
/
2
;
sp
.
anchorY
=
sp
.
height
/
2
;
this
.
addChild
(
sp
);
return
sp
;
};
GameView
.
prototype
.
createEclipse
=
function
()
{
var
sp
=
new
engine
.
Shape
();
sp
.
beginFill
(
0x00ff00
,
0.4
);
sp
.
drawEllipse
(
0
,
0
,
200
,
80
);
sp
.
endFill
();
this
.
addChild
(
sp
);
return
sp
;
};
GameView
.
prototype
.
changePosition
=
function
()
{
this
.
boxBody
.
position
[
0
]
=
740
;
this
.
boxBody
.
position
[
1
]
=
400
;
this
.
circleBody
.
position
[
0
]
=
540
;
this
.
circleBody
.
position
[
1
]
=
400
;
this
.
circleBody1
.
position
[
0
]
=
700
;
this
.
circleBody1
.
position
[
1
]
=
400
;
};
GameView
.
prototype
.
onMouseDown
=
function
(
e
)
{
var
direction
=
this
.
isRight
?
-
1
:
1
;
this
.
basketball
.
velocity
[
0
]
=
this
.
ballAddSpeedX
*
direction
;
this
.
basketball
.
velocity
[
1
]
=
this
.
ballAddSpeedY
;
this
.
basketball
.
angularVelocity
=
-
2
*
direction
;
};
GameView
.
prototype
.
addEvent
=
function
()
{
this
.
addEventListener
(
engine
.
Event
.
ENTER_FRAME
,
(
this
.
onEnterFrameBind
=
this
.
onEnterFrame
.
bind
(
this
)));
};
GameView
.
prototype
.
removeEvent
=
function
()
{
this
.
removeEventListener
(
engine
.
Event
.
ENTER_FRAME
,
this
.
onEnterFrameBind
);
};
GameView
.
prototype
.
start
=
function
()
{
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
CLICK
,
this
.
onMouseDown
,
this
);
console
.
log
(
this
.
world
);
};
GameView
.
prototype
.
stop
=
function
()
{
};
GameView
.
prototype
.
addEvent
=
function
()
{
};
return
GameView
;
}(
engine
.
Container
));
...
...
src/custom/basket/debug/main.js.map
View file @
7da17f99
This diff is collapsed.
Click to expand it.
src/custom/basket/src/game/GameView.ts
View file @
7da17f99
This diff is collapsed.
Click to expand it.
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