- 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.
- GitHub Essentials
- LibGDX Game Development Essentials
- Greenplum:從大數(shù)據(jù)戰(zhàn)略到實現(xiàn)
- 數(shù)據(jù)可視化:從小白到數(shù)據(jù)工程師的成長之路
- 輕松學(xué)大數(shù)據(jù)挖掘:算法、場景與數(shù)據(jù)產(chǎn)品
- 大數(shù)據(jù)算法
- 深入淺出MySQL:數(shù)據(jù)庫開發(fā)、優(yōu)化與管理維護(hù)(第2版)
- Oracle高性能自動化運(yùn)維
- Python醫(yī)學(xué)數(shù)據(jù)分析入門
- OracleDBA實戰(zhàn)攻略:運(yùn)維管理、診斷優(yōu)化、高可用與最佳實踐
- 從0到1:JavaScript 快速上手
- 數(shù)據(jù)庫原理與應(yīng)用
- 視覺大數(shù)據(jù)智能分析算法實戰(zhàn)
- 二進(jìn)制分析實戰(zhàn)
- 改變未來的九大算法