Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
game-template-egret
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
劳工
game-template-egret
Commits
911d5997
Commit
911d5997
authored
Sep 18, 2018
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
aac859bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
193 deletions
+3
-193
default.thm.json
resource/default.thm.json
+0
-2
GameView.ts
src/views/components/GameView.ts
+3
-191
No files found.
resource/default.thm.json
View file @
911d5997
...
...
@@ -2,10 +2,8 @@
"skins"
:
{},
"autoGenerateExmlsList"
:
true
,
"exmls"
:
[
"resource/skins/components/PlayerSkin.exml"
,
"resource/skins/components/RankItemSkin.exml"
,
"resource/skins/components/ReadyGoSkin.exml"
,
"resource/skins/components/ScoreEffectSkin.exml"
,
"resource/skins/components/ToastSkin.exml"
,
"resource/skins/LoadingViewSkin.exml"
,
"resource/skins/MainStageSkin.exml"
,
...
...
src/views/components/GameView.ts
View file @
911d5997
...
...
@@ -2,33 +2,10 @@
* Created by rockyl on 2018/8/16.
*/
import
{
EventComponent
}
from
"../../alienlib-cjs/support/EventComponent"
;
import
{
Background
}
from
"../../game/Background"
;
import
Player
from
"../../game/Player"
;
import
{
getHeight
,
getWidth
}
from
"../../alienlib-cjs/support/StageProxy"
;
import
{
getTweenPromise
}
from
"../../alienlib-cjs/tools/EgretUtils"
;
import
{
makeRandomInt
}
from
"../../alienlib-cjs/tools/MathUtils"
;
import
Block
from
"../../game/Block"
;
export
default
class
GameView
extends
EventComponent
{
background
:
Background
;
blockContainer
:
egret
.
DisplayObjectContainer
;
playerContainer
:
egret
.
DisplayObjectContainer
;
player
:
Player
;
currentBlock
:
Block
;
needHitTest
;
index
=
-
1
;
blockComplete
;
offsetY
=
350
;
timer
;
hasPreSetup
;
hasSetup
;
_pos
;
_touchEnabled
;
preSetup
()
{
if
(
this
.
hasPreSetup
)
{
...
...
@@ -36,25 +13,6 @@ export default class GameView extends EventComponent {
}
this
.
hasPreSetup
=
true
;
const
width
=
getWidth
();
const
background
=
this
.
background
=
new
Background
();
background
.
preSetup
();
this
.
addChild
(
background
);
const
blockContainer
=
this
.
blockContainer
=
new
egret
.
DisplayObjectContainer
();
blockContainer
.
x
=
width
/
2
;
this
.
addChild
(
blockContainer
);
const
playerContainer
=
this
.
playerContainer
=
new
egret
.
DisplayObjectContainer
();
playerContainer
.
x
=
width
/
2
;
this
.
addChild
(
playerContainer
);
const
player
=
this
.
player
=
new
Player
();
this
.
playerContainer
.
addChild
(
player
);
this
.
fadePlayer
(
0
,
false
);
this
.
pos
=
0
;
}
setup
()
{
...
...
@@ -63,177 +21,31 @@ export default class GameView extends EventComponent {
}
this
.
hasSetup
=
true
;
this
.
background
.
setup
();
this
.
registerEvent
(
this
,
egret
.
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
,
this
);
}
async
enter
(){
await
this
.
playGround
(
1
);
//this.fadePlayer(1);
}
async
leave
(){
this
.
playGround
(
0
);
this
.
fadePlayer
(
0
);
this
.
playReset
();
}
async
reset
(
revive
=
false
)
{
this
.
background
.
reset
();
await
this
.
playReset
();
await
this
.
resetPlayer
();
this
.
index
=
-
1
;
}
async
resetPlayer
(
index
=
0
){
this
.
player
.
reset
();
this
.
player
.
y
=
-
this
.
offsetY
-
index
*
Block
.
height
;
this
.
player
.
alpha
=
0
;
await
this
.
fadePlayer
(
1
);
}
start
(
revive
=
false
)
{
this
.
_touchEnabled
=
true
;
setTimeout
(()
=>
{
this
.
addBlock
();
},
100
);
}
playGround
(
alpha
)
{
return
this
.
background
.
playGround
(
alpha
)
}
async
revive
()
{
this
.
blockContainer
.
getChildAt
(
this
.
index
).
visible
=
false
;
await
this
.
resetPlayer
(
this
.
index
);
this
.
index
--
;
this
.
start
(
true
);
}
playReset
()
{
const
blockContainer
=
this
.
blockContainer
;
for
(
let
i
=
this
.
index
;
i
>=
0
;
i
--
)
{
const
block
=
<
Block
>
blockContainer
.
getChildAt
(
i
);
block
.
playLeave
();
}
return
getTweenPromise
(
egret
.
Tween
.
get
(
this
,
null
,
null
,
true
)
.
to
({
pos
:
0
},
Math
.
min
(
this
.
_pos
*
2
,
1000
),
egret
.
Ease
.
cubicOut
)
)
}
fadePlayer
(
alpha
,
animation
=
true
){
if
(
animation
){
return
getTweenPromise
(
egret
.
Tween
.
get
(
this
.
player
,
null
,
null
,
true
)
.
to
({
alpha
},
200
));
}
else
{
this
.
player
.
alpha
=
0
;
return
Promise
.
resolve
();
}
}
addBlock
()
{
this
.
index
++
;
const
blockContainer
=
this
.
blockContainer
;
let
block
:
Block
;
if
(
blockContainer
.
numChildren
>
this
.
index
)
{
block
=
<
Block
>
blockContainer
.
getChildAt
(
this
.
index
);
block
.
visible
=
true
;
}
else
{
block
=
new
Block
();
blockContainer
.
addChild
(
block
);
}
block
.
reset
({
type
:
makeRandomInt
(
5
),
});
block
.
y
=
-
this
.
offsetY
-
Block
.
height
*
this
.
index
;
this
.
blockComplete
=
false
;
block
.
playEnter
(
this
.
index
).
then
(
(
data
)
=>
{
this
.
blockComplete
=
true
;
}
);
this
.
needHitTest
=
true
;
this
.
currentBlock
=
block
;
}
get
pos
()
{
return
this
.
_pos
;
}
set
pos
(
v
)
{
this
.
_pos
=
v
;
this
.
updatePos
();
}
updatePos
()
{
this
.
background
.
setViewport
(
this
.
_pos
);
this
.
blockContainer
.
y
=
this
.
playerContainer
.
y
=
getHeight
()
+
this
.
_pos
;
}
private
onEnterFrame
(
event
)
{
if
(
this
.
needHitTest
)
{
if
(
this
.
currentBlock
)
{
const
{
x
:
bx
,
y
:
by
,
dir
}
=
this
.
currentBlock
;
const
{
x
:
px
,
y
:
py
}
=
this
.
player
;
const
{
width
:
bWidth
}
=
Block
;
const
{
width
:
pWidth
}
=
Player
;
let
hitOn
=
false
;
if
(
Math
.
abs
(
px
-
bx
)
<
(
bWidth
+
pWidth
)
/
2
)
{
this
.
player
.
changeBaseY
(
by
-
Block
.
height
);
if
(
py
>
by
-
Block
.
height
)
{
hitOn
=
true
;
}
}
if
(
hitOn
)
{
this
.
onHitOn
(
dir
);
}
}
}
}
async
onHitOn
(
dir
)
{
this
.
_touchEnabled
=
false
;
this
.
needHitTest
=
false
;
clearInterval
(
this
.
timer
);
this
.
currentBlock
.
stop
();
this
.
player
.
stop
();
await
this
.
player
.
playFly
(
dir
);
this
.
_touchEnabled
=
true
;
this
.
dispatchEventWith
(
egret
.
Event
.
COMPLETE
);
}
async
jump
()
{
if
(
!
this
.
_touchEnabled
){
return
;
}
this
.
_touchEnabled
=
false
;
const
result
:
any
=
await
this
.
player
.
playJump
();
if
(
result
)
{
if
(
result
.
aboveBlock
)
{
const
scoreAdd
=
this
.
blockComplete
?
2
:
1
;
this
.
dispatchEventWith
(
egret
.
Event
.
CHANGE
,
false
,
{
scoreAdd
});
this
.
currentBlock
.
stop
();
await
getTweenPromise
(
egret
.
Tween
.
get
(
this
,
null
,
null
,
true
)
.
to
({
pos
:
Block
.
height
*
(
this
.
index
+
1
)},
300
,
egret
.
Ease
.
cubicOut
)
);
this
.
addBlock
();
}
this
.
_touchEnabled
=
true
;
}
}
}
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