- 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深度學習實戰:從新手小白到數據科學家
- Voice Application Development for Android
- 大數據可視化
- 卷積神經網絡的Python實現
- Libgdx Cross/platform Game Development Cookbook
- 云計算與大數據應用
- 商業分析思維與實踐:用數據分析解決商業問題
- 區塊鏈:看得見的信任
- Spark大數據分析實戰
- 計算機應用基礎教程上機指導與習題集(微課版)
- 云數據中心網絡與SDN:技術架構與實現
- 大數據治理與安全:從理論到開源實踐
- Augmented Reality using Appcelerator Titanium Starter
- Visual Studio 2013 and .NET 4.5 Expert Cookbook
- 數據分析師養成寶典