Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
db-game-template
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
崔立强
db-game-template
Commits
1db3ea86
Commit
1db3ea86
authored
Aug 18, 2021
by
Joker Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
bacfa764
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
39 deletions
+122
-39
Game.ts
egret/src/playScene/Game/Game.ts
+87
-22
GameConst.ts
egret/src/playScene/Game/GameConst.ts
+7
-0
PlayScene.ts
egret/src/playScene/PlayScene.ts
+28
-17
No files found.
egret/src/playScene/Game/Game.ts
View file @
1db3ea86
import
{
tipsType
}
from
"./GameConst"
;
const
BABYLON
=
window
[
'BABYLON'
];
export
default
class
Game
{
...
...
@@ -7,11 +8,16 @@ export default class Game {
beyondFriends
=
[]
// 超越好友配置
targetScene
meshMatUrl
addScoreConfig
=
{
score
:
1
,
continuouslyScore
:
1
}
constructor
(
config
,
targetScene
){
let
{
spFall
,
beyondFriends
,
meshMatUrl
}
=
config
let
{
spFall
,
beyondFriends
,
meshMatUrl
,
addScoreConfig
}
=
config
this
.
spFall
=
spFall
this
.
beyondFriends
=
beyondFriends
this
.
addScoreConfig
=
addScoreConfig
this
.
targetScene
=
targetScene
this
.
meshMatUrl
=
meshMatUrl
this
.
initScene
()
...
...
@@ -55,9 +61,13 @@ export default class Game {
public
unitAngle
=
Math
.
PI
/
6
;
// 单个元素所占原型的角度
public
redMaterial
:
any
;
// 红色材质
public
maxDepth
:
number
=
0
;
// 最大深度
private
_score
:
number
=
0
private
_layerNum
:
number
=
0
// 层数
private
_score
:
number
=
0
// 分数
private
isPause
:
boolean
=
false
// 是否暂停
private
isCollision
:
boolean
=
true
// 默认进行碰撞检测
private
degree
:
number
=
1
private
offScreen
private
offScreenContext
async
initScene
()
{
let
container
=
document
.
getElementById
(
"egretContainer"
);
...
...
@@ -77,6 +87,20 @@ export default class Game {
return
window
[
'canvasWebgl'
]
};
// let canvas=document.createElement("canvas");
// this.offScreen = canvas.transferControlToOffscreen()
// this.offScreenContext = this.offScreen.getContext("2d")
// let grad=this.offScreenContext.createLinearGradient(0,0,300,0);
// grad.addColorStop(0,"yellow");
// grad.addColorStop(1,"green");
// this.offScreenContext.fillStyle=grad;
// this.offScreenContext.fillRect(0,0,1000,1000);
// let skyBox = BABYLON.MeshBuilder.CreateBox("skyBox",{width:10000,height:10000,depth:10000,sideOrientation:2},this.scene)
// let skyMat = new BABYLON.StandardMaterial("sky",this.scene)
// // skyMat.diffuseTexture = new BABYLON.Texture( this.offScreen.toDataURL("image/png"), this.scene);
// skyMat.diffuseColor = BABYLON.Color3.FromHexString("#36b2f8");
// skyBox.material=skyMat
this
.
scene
=
new
BABYLON
.
Scene
(
engine
);
// this.scene.ambientColor = BABYLON.Color3.FromHexString("#ffffff");
this
.
scene
.
clearColor
=
BABYLON
.
Color3
.
FromHexString
(
"#ffffff"
);
...
...
@@ -86,18 +110,15 @@ export default class Game {
this
.
light
.
intensity
=
1
;
this
.
light
.
diffuse
=
new
BABYLON
.
Color3
(
1
,
1
,
1
);
this
.
light
.
specular
=
new
BABYLON
.
Color3
(
1
,
1
,
1
);
this
.
light2
=
new
BABYLON
.
HemisphericLight
(
"dir02"
,
new
BABYLON
.
Vector3
(
0
,
-
1
,
-
0.3
),
this
.
scene
);
this
.
light2
.
intensity
=
0.8
;
this
.
light2
.
diffuse
=
new
BABYLON
.
Color3
(
1
,
1
,
1
);
this
.
light2
.
specular
=
new
BABYLON
.
Color3
(
1
,
1
,
1
);
this
.
light
.
position
=
new
BABYLON
.
Vector3
(
20
,
60
,
30
);
// var light = new BABYLON.DirectionalLight("DirectionalLight", new BABYLON.Vector3(0, -1, 1),this.scene);
// light.intensity=1
// light.diffuse = new BABYLON.Color3(1, 1, 1);
// light.specular = new BABYLON.Color3(1, 1, 1);
// this.light2 = new BABYLON.HemisphericLight("dir02", new BABYLON.Vector3(0, 1, 0.3), this.scene);
// this.light2.intensity = 1;
// this.light2.position = new BABYLON.Vector3(20, -60, 30);
this
.
camera
=
new
BABYLON
.
FreeCamera
(
"Camera"
,
new
BABYLON
.
Vector3
(
0
,
35
,
50
),
this
.
scene
);
this
.
camera
=
new
BABYLON
.
FreeCamera
(
"Camera"
,
new
BABYLON
.
Vector3
(
0
,
28
,
45
),
this
.
scene
);
// this.glowLayer = new BABYLON.GlowLayer("glow", this.scene);
// this.glowLayer.intensity = 2;
...
...
@@ -118,7 +139,7 @@ export default class Game {
// 用户球体
this
.
userMesh
=
BABYLON
.
Mesh
.
CreateSphere
(
'user'
,
16
,
1.8
,
this
.
scene
);
this
.
userMesh
=
BABYLON
.
Mesh
.
CreateSphere
(
'user'
,
16
,
2
,
this
.
scene
);
// this.userMesh.visibility = 0;
this
.
rocket
=
BABYLON
.
Mesh
.
CreateBox
(
'rocket'
,
2
,
this
.
scene
);
this
.
rocketP
=
BABYLON
.
Mesh
.
CreateBox
(
'rocketP'
,
2
,
this
.
scene
);
...
...
@@ -150,8 +171,9 @@ export default class Game {
this
.
cylinder
=
BABYLON
.
MeshBuilder
.
CreateCylinder
(
"cy"
,
{
diameter
:
13.5
,
height
:
500
},
this
.
scene
)
let
cylinderMaterial
=
new
BABYLON
.
StandardMaterial
(
"cylinderMaterial"
,
this
.
scene
);
cylinderMaterial
.
diffuseColor
=
BABYLON
.
Color3
.
FromHexString
(
"#d5e4e4"
);
cylinderMaterial
.
specularColor
=
BABYLON
.
Color3
.
FromHexString
(
"#d8f5f0"
);
cylinderMaterial
.
diffuseColor
=
BABYLON
.
Color3
.
FromHexString
(
"#bcfefa"
);
cylinderMaterial
.
specularColor
=
BABYLON
.
Color3
.
FromHexString
(
"#bcfefa"
);
cylinderMaterial
.
ambientColor
=
BABYLON
.
Color3
.
FromHexString
(
"#bcfefa"
);
this
.
cylinder
.
material
=
cylinderMaterial
let
inputManager
=
this
.
camera
.
inputs
;
...
...
@@ -309,6 +331,7 @@ export default class Game {
this
.
touchSpeed
=
0.1
}
continuouslyScoreFlag
=
0
private
onBeforeRender
(){
let
now
=
Date
.
now
()
...
...
@@ -365,14 +388,27 @@ export default class Game {
if
(
this
.
rocketP
.
position
.
y
<
this
.
maxDepth
)
{
if
(
Math
.
abs
(
this
.
rocketP
.
position
.
y
-
this
.
maxDepth
)
>
this
.
elementInterval
)
{
this
.
_score
+=
1
this
.
targetScene
.
addScore
(
1
);
this
.
_layerNum
+=
1
let
addScore
=
1
if
(
this
.
continuouslyScoreFlag
>
0
){
if
(
this
.
continuouslyScoreFlag
>
3
){
addScore
=
2
*
this
.
_layerNum
}
else
{
addScore
=
this
.
addScoreConfig
.
continuouslyScore
}
}
else
{
addScore
=
this
.
addScoreConfig
.
score
}
this
.
targetScene
.
addScore
&&
this
.
targetScene
.
addScore
(
addScore
,
this
.
_layerNum
);
this
.
_score
+=
addScore
this
.
continuouslyScoreFlag
++
if
(
this
.
beyondFriends
.
length
>
0
)
{
for
(
let
i
=
this
.
beyondFriends
.
length
-
1
;
i
>=
0
;
i
--
)
{
let
f
=
this
.
beyondFriends
[
i
]
if
(
f
.
score
<
this
.
_
score
)
{
if
(
f
.
score
<
this
.
_
layerNum
)
{
this
.
removeEle
(
f
,
this
.
beyondFriends
)
this
.
targetScene
.
beyondFriend
(
f
.
id
)
this
.
handleTips
(
tipsType
.
beyondFriend
)
}
}
}
...
...
@@ -394,13 +430,12 @@ export default class Game {
this
.
maxDepth
=
this
.
rocketP
.
position
.
y
;
}
}
}
if
(
this
.
isCollision
)
{
// 碰撞检测
for
(
let
element
of
this
.
elementPool
)
{
if
(
element
.
intersectsMesh
(
this
.
userMesh
,
true
))
{
this
.
continuouslyScoreFlag
=
0
if
(
element
.
gameType
==
'redElement'
)
{
// 撞到了黑云 游戏结束
this
.
isPause
=
true
...
...
@@ -408,6 +443,7 @@ export default class Game {
// 派发结束事件
}
else
{
// 如果碰到了就让速度反向
this
.
downSpeed
=
-
.
7
;
this
.
startTimestamp
=
Date
.
now
()
//
...
...
@@ -419,7 +455,6 @@ export default class Game {
// 道具碰撞
for
(
let
sp
of
this
.
spPool
)
{
if
(
sp
.
intersectsMesh
(
this
.
userMesh
,
true
))
{
// TODO
sp
.
visibility
=
0
this
.
TailSystem
.
start
()
this
.
downSpeed
=
this
.
downMaxSpeed
...
...
@@ -442,11 +477,11 @@ export default class Game {
this
.
isCollision
=
true
}
restart
(
config
,
targetScene
)
{
let
{
spFall
,
beyondFriends
}
=
config
restart
(
config
)
{
let
{
spFall
,
beyondFriends
,
meshMatUrl
}
=
config
?
config
:
this
.
config
this
.
spFall
=
spFall
this
.
beyondFriends
=
beyondFriends
this
.
targetScene
=
targetScene
this
.
meshMatUrl
=
meshMatUrl
this
.
disposeAll
()
this
.
rocketP
.
position
.
y
=
10
;
this
.
lastY
=
0
;
...
...
@@ -457,6 +492,36 @@ export default class Game {
this
.
isCollision
=
true
}
tiping
=
false
handleTips
(
type
){
if
(
this
.
tiping
){
return
}
let
idx
=
5
switch
(
type
){
case
tipsType
.
beyondFriend
:
idx
=
1
break
case
tipsType
.
degreeChange
:
idx
=
2
break
case
tipsType
.
during200
:
idx
=
3
break
case
tipsType
.
pickRocket
:
idx
=
4
break
case
tipsType
.
bigScore
:
idx
=
5
break
}
this
.
tiping
=
true
this
.
targetScene
.
handleTips
(
idx
)
setTimeout
(()
=>
{
this
.
tiping
=
false
},
1000
)
}
disposeAll
()
{
for
(
let
e
=
this
.
nElePool
.
length
-
1
;
e
>=
0
;
e
--
)
{
let
element
=
this
.
nElePool
[
e
];
...
...
egret/src/playScene/Game/GameConst.ts
0 → 100644
View file @
1db3ea86
export
enum
tipsType
{
"beyondFriend"
,
"degreeChange"
,
"during200"
,
"pickRocket"
,
"bigScore"
}
\ No newline at end of file
egret/src/playScene/PlayScene.ts
View file @
1db3ea86
...
...
@@ -49,31 +49,32 @@ export default class PlayScene extends PlaySceneBase{
score
:
35
,
id
:
4
}],
addScoreConfig
:{
score
:
1
,
continuouslyScore
:
10
},
gameLevels
:{
level1
:{
endScore
:
20
},
level2
:{
endScore
:
2
0
endScore
:
5
0
},
level3
:{
endScore
:
2
0
endScore
:
8
0
},
level4
:{
endScore
:
20
endScore
:
1
20
},
level5
:{
endScore
:
20
endScore
:
20
0
},
level6
:{
endScore
:
2
0
endScore
:
30
0
},
level7
:{
endScore
:
20
},
level8
:{
endScore
:
20
},
endScore
:
400
}
}
}
if
(
this
.
gameNode
){
...
...
@@ -158,22 +159,32 @@ export default class PlayScene extends PlaySceneBase{
}
// 更新分数
addScore
(
score
?:
number
){
addScore
(
score
?:
number
,
layerNum
?:
number
){
let
_score
=
1
;
if
(
score
){
_score
=
score
;
}
this
.
scoreTip
.
y
=
this
.
stage
.
stageHeight
/
2
;
this
.
scoreTip
.
scaleX
=
0
;
this
.
scoreTip
.
scaleY
=
0
;
this
.
scoreTip
.
alpha
=
1
;
this
.
scoreTip
.
source
=
`+
${
_score
}
_png`
;
let
scoreTw
=
egret
.
Tween
.
get
(
this
.
scoreTip
);
let
scoreTip
=
new
egret
.
TextField
()
scoreTip
.
text
=
"+"
+
score
this
.
addChild
(
scoreTip
)
scoreTip
.
x
=
350
scoreTip
.
y
=
this
.
stage
.
stageHeight
/
2
;
scoreTip
.
textColor
=
0xff0000
;
scoreTip
.
size
=
60
scoreTip
.
scaleX
=
0
;
scoreTip
.
scaleY
=
0
;
scoreTip
.
alpha
=
1
;
let
scoreTw
=
egret
.
Tween
.
get
(
scoreTip
);
scoreTw
.
to
({
scaleX
:
1
,
scaleY
:
1
},
200
).
to
({
y
:
this
.
stage
.
stageHeight
/
2
-
100
,
alpha
:
0
},
100
);
this
.
score
+=
_score
;
this
.
scoreTxt
.
text
=
`
${
this
.
score
}
`
;
}
// 处理提示 最快1秒一次
handleTips
(){
}
// 提交成绩的回调
private
gameSubmitResult
(
success
){
...
...
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