基本跑酷游戏的框架搭建完毕,开发者会根据开发的游戏特性,增设一些额外功能,使游戏具备可玩性性和画面感。下面咱们以角色的二段跳为例,来了解在跑酷游戏中增设其它功能的流程。二段跳的设定,不只增长游戏的华丽感而且能够经过二段跳游戏的道路和关卡转换。框架
如图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开源游戏引擎:游戏起源,皆因有我!!!