- XNA 4.0 Game Development by Example Beginner's Guide(Visual Basic Edition)
- Kurt Jaegers
- 270字
- 2021-08-20 15:50:43
Time for action – generating falling pieces
- Modify the
FillFromAbove()
method of theGameBoard
class by adding a call to generate falling pieces right before therowLookup = -1
line (inside theIf
block):AddFallingPiece(x, y, GetSquare(x, y), GamePiece.PieceHeight * (y - rowLookup))
- Update the
GenerateNewPieces()
method by adding the following call, right after theRandomPiece(x,y)
line as follows:AddFallingPiece(x, y, GetSquare(x, y), GamePiece.PieceHeight * (GameBoardHeight + 1))
What just happened?
When FillFromAbove()
moves a piece downward, we now create an entry in the FallingPieces
dictionary that is equivalent to the newly moved piece. The vertical offset is set to the height of a piece (40 pixels) times the number of board squares the piece was moved. For example, if the empty space was at location 5, 5 on the board, and the piece above it (5, 4) is being moved down one block, the animated piece is created at 5, 5 with an offset of 40 pixels (5-4 = 1, times 40).
When new pieces are generated for the board, they are added with an offset equal to the height (in pixels) of the game board (recall that we specified the height as one less than the real height, to account for the allocation of the extra element in the boardSquares
array), determined by multiplying the GamePiece.PieceHeight
value by GameBoardHeight +1
. This means they will always start above the playing area and fall into it.
- Microsoft SQL Server企業(yè)級平臺管理實踐
- 數(shù)據(jù)挖掘原理與實踐
- 數(shù)據(jù)分析實戰(zhàn):基于EXCEL和SPSS系列工具的實踐
- Access 2007數(shù)據(jù)庫應(yīng)用上機指導(dǎo)與練習(xí)
- 數(shù)據(jù)化網(wǎng)站運營深度剖析
- Ceph源碼分析
- 數(shù)據(jù)驅(qū)動設(shè)計:A/B測試提升用戶體驗
- Python金融實戰(zhàn)
- SQL Server 2012數(shù)據(jù)庫管理教程
- 云數(shù)據(jù)中心網(wǎng)絡(luò)與SDN:技術(shù)架構(gòu)與實現(xiàn)
- Oracle數(shù)據(jù)庫管理、開發(fā)與實踐
- 企業(yè)大數(shù)據(jù)處理:Spark、Druid、Flume與Kafka應(yīng)用實踐
- 利用Python進(jìn)行數(shù)據(jù)分析(原書第2版)
- 數(shù)據(jù)分析思維:產(chǎn)品經(jīng)理的成長筆記
- Oracle 11g數(shù)據(jù)庫管理員指南