- 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.
- 數據驅動設計:A/B測試提升用戶體驗
- Sybase數據庫在UNIX、Windows上的實施和管理
- 數字媒體交互設計(初級):Web產品交互設計方法與案例
- 基于OPAC日志的高校圖書館用戶信息需求與檢索行為研究
- 數據中心數字孿生應用實踐
- 深入淺出Greenplum分布式數據庫:原理、架構和代碼分析
- 數據科學工程實踐:用戶行為分析與建模、A/B實驗、SQLFlow
- 淘寶、天貓電商數據分析與挖掘實戰(第2版)
- 大數據技術原理與應用:概念、存儲、處理、分析與應用
- Microsoft Dynamics NAV 2015 Professional Reporting
- 數據中臺實戰:手把手教你搭建數據中臺
- Rust High Performance
- 大數據計算系統原理、技術與應用
- 基于數據發布的隱私保護模型研究
- NoSQL數據庫原理(第2版·微課版)