- 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.
- 漫話大數據
- MongoDB管理與開發精要
- Modern Programming: Object Oriented Programming and Best Practices
- Visual Studio 2015 Cookbook(Second Edition)
- Neural Network Programming with TensorFlow
- 數據庫系統原理及應用教程(第4版)
- Creating Dynamic UIs with Android Fragments(Second Edition)
- Learn Unity ML-Agents:Fundamentals of Unity Machine Learning
- Flutter Projects
- 云數據中心網絡與SDN:技術架構與實現
- 探索新型智庫發展之路:藍迪國際智庫報告·2015(上冊)
- Oracle數據庫管理、開發與實踐
- Unity 2018 By Example(Second Edition)
- 大數據數學基礎(R語言描述)
- 云工作時代:科技進化必將帶來的新工作方式