- XNA 4.0 Game Development by Example Beginner's Guide(Visual Basic Edition)
- Kurt Jaegers
- 253字
- 2021-08-20 15:50:41
Time for action – letting the player play
- Modify the
Update()
method ofGame1.vb
, by adding the following before the call toMyBase.Update(gameTime)
:Select Case gameState Case GameStates.TitleScreen If Keyboard.GetState().IsKeyDown(Keys.Space) Then _gameBoard.ClearBoard() _gameBoard.GenerateNewPieces(False) playerScore = 0 gameState = GameStates.Playing End If Case GameStates.Playing timeSinceLastInput += (CSng(gameTime.ElapsedGameTime.TotalSeconds)) If timeSinceLastInput >= MinTimeSinceLastInput Then HandleMouseInput(Mouse.GetState()) End If _gameBoard.ResetWater() Dim y As Integer For y = 0 To GameBoard.GameBoardHeight CheckScoringChain(_gameBoard.GetWaterChain(y)) Next _gameBoard.GenerateNewPieces(True) End Select
What just happened?
The Update()
method performs two different functions, depending on the current gameState
value. If the game is in TitleScreen
state, Update()
examines the keyboard, waiting for the Space bar to be pressed. When it is, Update()
clears the _gameBoard
, generates a new set of pieces, resets the player's score, and changes gameState
to Playing
.
While in the Playing
state, Update()
accumulates time in timeSinceLastInput
in order to pace the game play properly. If enough time has passed, the HandleMouseInput()
method is called to allow the player to rotate game pieces.
Update()
then calls ResetWater()
to clear the water flags for all pieces on the game board. This is followed by a loop that processes each row, starting at the top and working downward, using CheckScoringChain()
and GetWaterChain()
, to fill any pieces that should have water in them and check the results of each row for completed chains.
Finally, GenerateNewPieces()
is called with the true
parameter for dropSquares
, which will cause GenerateNewPieces()
to fill the empty holes from the squares above, and then generate new pipes to replace the empty squares.
- PyTorch深度學習實戰(zhàn):從新手小白到數(shù)據(jù)科學家
- 文本挖掘:基于R語言的整潔工具
- Microsoft Power BI數(shù)據(jù)可視化與數(shù)據(jù)分析
- 數(shù)據(jù)庫技術(shù)及應(yīng)用教程
- 跟老男孩學Linux運維:MySQL入門與提高實踐
- Hadoop大數(shù)據(jù)開發(fā)案例教程與項目實戰(zhàn)(在線實驗+在線自測)
- Hadoop集群與安全
- 實用數(shù)據(jù)結(jié)構(gòu)
- Visual FoxPro數(shù)據(jù)庫技術(shù)基礎(chǔ)
- 數(shù)據(jù)指標體系:構(gòu)建方法與應(yīng)用實踐
- 企業(yè)級大數(shù)據(jù)項目實戰(zhàn):用戶搜索行為分析系統(tǒng)從0到1
- Learn Selenium
- 數(shù)據(jù)時代的品牌智造
- Kafka權(quán)威指南(第2版)
- 反饋:化解不確定性的數(shù)字認知論