基本跑酷遊戲的框架搭建完畢,開發者會根據開發的遊戲特性,增設一些額外功能,使遊戲具備可玩性性和畫面感。下面咱們以角色的二段跳爲例,來了解在跑酷遊戲中增設其它功能的流程。二段跳的設定,不只增長遊戲的華麗感而且能夠經過二段跳遊戲的道路和關卡轉換。框架
如圖5-1所示。ide
步驟1:函數
二段跳能夠參考SecondJumpMgr.cs 文件,表現層經過邏輯中二段跳不一樣的狀態,來播不一樣的動畫。首先把二段跳拆下述的分紅幾種線性狀態, 以下所示。動畫
1 |
public enum Status |
2 |
{ |
3 |
Lifting, |
4 |
PreRush, |
5 |
Rushing, |
6 |
CD, |
7 |
Ready, |
8 |
} |
步驟2:網站
在邏輯層的Player.cs文件中,當收到操做指令向上跳以後,又收到一次向上跳,會嘗試進行二段跳。spa
01 |
public override bool Jump() |
02 |
{ |
03 |
bool success = false ; |
04 |
if (PlayerDataMgr.Singleton.IsOnGround == true ) |
05 |
{ |
06 |
DoJump(); |
07 |
_callback.PlaySound( "asset:Media/Sound/Jump1.mp3" ); |
08 |
PlayerDataMgr.Singleton._isBeginJump = true ; |
09 |
success = true ; |
10 |
} |
11 |
else // 在空中則嘗試二段跳 |
12 |
{ |
13 |
if (SecondJumpMgr.Singleton.CanSecondJump()&& (PlayerDataMgr.Singleton.YSpeed > 0.0f || GetDisFromGround() > 1.2f)) |
14 |
{ |
15 |
SecondJumpMgr.Singleton.Begin(GetDisFromGround()); |
16 |
success = true ; |
17 |
_callback.OnSecondJump(); |
18 |
_callback.PlaySound( "asset:Media/Sound/SecondJump.mp3" ) |
19 |
} |
20 |
} |
21 |
_isPlayJumpEndSound = true ; |
22 |
return success; |
23 |
} |
步驟3:3d
成功的狀況下,就會調用SecondJumpMgr裏面的Begin函數開始二段跳。code
01 |
public void Begin ( float disFromGround) |
02 |
{ |
03 |
_ySpeedWhenLifting = (StaticData.SecondJump_High - disFromGround) / StaticData.SecondJump_LiftTime; |
04 |
SecondJumpCostEnergy (); |
05 |
_status = Status.Lifting; |
06 |
_stageProcessTime = 0.0f; |
07 |
_speedUpProcessTime = 0.0f; |
08 |
} |
09 |
//LogicMgr的Tick裏會對二段跳進行單獨的Tick,二段跳的Tick以下: |
10 |
public void Tick ( float elapse) |
11 |
{ |
12 |
Tick_RenewEnergy(elapse); |
13 |
Tikc_SecondJumpLogic(elapse); |
14 |
Tick_PlayParticle (elapse); |
15 |
Tick_SpeedUp(elapse); |
16 |
} |
17 |
//其中Tikc_SecondJumpLogic(elapse)會針對二段跳的狀態變換進行邏輯斷定: |
18 |
void Tikc_SecondJumpLogic ( float elapse) |
19 |
{ |
20 |
if (_status == Status.Ready || _status == Status.CD) |
21 |
{ return ;} |
22 |
_stageProcessTime += elapse; |
23 |
if (_status == Status.Lifting) |
24 |
{ |
25 |
if (_stageProcessTime > StaticData.SecondJump_LiftTime) |
26 |
{ |
27 |
_status = Status.PreRush; |
28 |
_stageProcessTime = 0.0f;} |
29 |
} |
30 |
else if (_status == Status.PreRush) |
31 |
{ |
32 |
if (_stageProcessTime > StaticData.SecondJump_PreRushTime) |
33 |
{ |
34 |
_status = Status.Rushing; |
35 |
_stageProcessTime = 0.0f; |
36 |
} |
37 |
} |
38 |
else if (_status == Status.Rushing) |
39 |
{ |
40 |
if (_stageProcessTime > StaticData.SecondJump_RushTime) |
41 |
{ |
42 |
_status = Status.CD; |
43 |
_stageProcessTime = 0.0f; |
44 |
} |
45 |
} |
46 |
} |
47 |
} |
引擎官方網站:http://www.genesis-3d.com.cn/遊戲
官方論壇:http://bbs.9tech.cn/genesis-3d/遊戲開發
官方千人大羣:59113309 135439306
YY頻道-遊戲開發大講堂(徹底免費,按期開課):51735288
Genesis-3D開源遊戲引擎:遊戲起源,皆因有我!!!