正文

游戏案例:GemDrops(16)

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


 

程序清单8-20  对一对新的由玩家控制的宝石对象进行初始化

/// <summary>

/// Create two new gems for the player to control.

/// </summary>

private void InitPlayerGems()

{

// Instantiate and initialize two new gems for the player to control.

// Set the gem colors to be those colors stored for the next gems.

_playerGems[0] = new CObjGem(this, BOARD_GEMS_ACROSS / 2, 0,

_playerNextGems[0].GemColor);

_playerGems[1] = new CObjGem(this, BOARD_GEMS_ACROSS / 2, 1,

_playerNextGems[1].GemColor);

// These are the player controlled gems

_playerGems[0].GemType = CObjGem.GemTypes.PlayerControlled;

_playerGems[1].GemType = CObjGem.GemTypes.PlayerControlled;

// Set the gems as falling into the position we have set

_playerGems[0].FallDistance = 1;

_playerGems[1].FallDistance = 1;

// Set the drop speed to increase based on the number of pieces already 

// dropped.

_playerGems[0].FallSpeed = 0.02f + (_piecesDropped * 0.0004f);

_playerGems[1].FallSpeed = _playerGems[0].FallSpeed;

// Add the gems to the game

GameObjects.Add(_playerGems[0]);

GameObjects.Add(_playerGems[1]);

// Check that the board space is actually available.

// If not, the game is finished.

CheckGameOver();

if (GameOver)

{

// The game is finished, so no further work is required here

return;

}

// Set two new 'next' gems

_playerNextGems[0].GemColor = GenerateRandomGemColor();

_playerNextGems[1].GemColor = GenerateRandomGemColor();

// Flag the next gems as having moved so that they are re-rendered in 

// their new colors.

_playerNextGems[0].HasMoved = true;

_playerNextGems[1].HasMoved = true;

// Increase the pieces dropped count

_piecesDropped += 1;

}


上一章目录下一章

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