正文

游戲案例:GemDrops(13)

Windows移動(dòng)游戲開發(fā)實(shí)戰(zhàn) 作者:(美)Adam Dawes


 

我們還沒(méi)有對(duì)當(dāng)寶石的下落距離達(dá)到0時(shí)發(fā)生的情況進(jìn)行規(guī)定。游戲自身必須進(jìn)行檢測(cè)并對(duì)這種情形做出處理。稍后您將看到結(jié)果。

為了使下落距離具有一點(diǎn)視覺(jué)效果,我們需要對(duì)YPos屬性進(jìn)行修改。不只是根據(jù)_boardYPos來(lái)計(jì)算位置,現(xiàn)在還要考慮_fallDistance,這樣就可以將下落過(guò)程中寶石的最終位置計(jì)算出來(lái)。

接下來(lái)要對(duì)顯示在Nextpiece中的寶石進(jìn)行處理。由于它們不顯示在游戲區(qū)域中,對(duì)其XPos屬性及YPos屬性都進(jìn)行修改可以使寶石顯示在游戲窗體的右邊,就在窗體設(shè)計(jì)時(shí)創(chuàng)建的lblNextPiece標(biāo)簽下方。對(duì)于這種類型的寶石,令其YPos屬性根據(jù)_boardYPos值進(jìn)行計(jì)算,這樣可以指定一個(gè)寶石位于另一個(gè)寶石的下方。

修改后的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 ? 讀書網(wǎng) hotzeplotz.com 2005-2020, All Rights Reserved.
鄂ICP備15019699號(hào) 鄂公網(wǎng)安備 42010302001612號(hào)