正文

游戏案例:GemDrops(13)

Windows移动游戏开发实战 作者:(美)Adam Dawes


 

我们还没有对当宝石的下落距离达到0时发生的情况进行规定。游戏自身必须进行检测并对这种情形做出处理。稍后您将看到结果。

为了使下落距离具有一点视觉效果,我们需要对YPos属性进行修改。不只是根据_boardYPos来计算位置,现在还要考虑_fallDistance,这样就可以将下落过程中宝石的最终位置计算出来。

接下来要对显示在Nextpiece中的宝石进行处理。由于它们不显示在游戏区域中,对其XPos属性及YPos属性都进行修改可以使宝石显示在游戏窗体的右边,就在窗体设计时创建的lblNextPiece标签下方。对于这种类型的宝石,令其YPos属性根据_boardYPos值进行计算,这样可以指定一个宝石位于另一个宝石的下方。

修改后的XPos及YPos属性如程序清单8-16所示。

程序清单8-16 修改后的YPos属性考虑了_fallDistance及_gemType

/// <summary>

/// Override the XPos property to calculate our actual position on demand

/// </summary>

public override float XPos

{

get

{

switch (_gemType)

{

case GemTypes.NextGem:

// This is a "next piece" gem so determine its position

// within the form

return ((MainForm)(_game.GameForm)).ClientRectangle.

Width - Width;

default:

// This is an "in-board" gem so determine its position

// within the board

return _game.BoardLeft + (_boardXPos * Width);

}

}

}

/// <summary>

/// Override the YPos property to calculate our actual position on demand

/// </summary>

public override float YPos

{

get

{

switch (_gemType)

{

case GemTypes.NextGem:

// This is a "next piece" gem so determine its position

within the form

return ((MainForm)( _game.GameForm)).lblNextPiece.

ClientRectangle.Bottom

+ (_boardYPos * Height);

default:

// This is an "in-board" gem so determine its position

within the board

return _game.BoardTop + ((_boardYPos - _fallDistance)

* Height);

}

}

}


上一章目录下一章

Copyright © 读书网 www.dushu.com 2005-2020, All Rights Reserved.
鄂ICP备15019699号 鄂公网安备 42010302001612号