- XNA 4.0 Game Development by Example Beginner's Guide(Visual Basic Edition)
- Kurt Jaegers
- 272字
- 2021-08-20 15:50:38
Time for action – GamePiece class methods – part 2 – rotation
- Add the
RotatePiece()
method to theGamePiece
class:Public Sub RotatePiece(clockwise As Boolean) Select Case _pieceType Case "Left,Right" _pieceType = "Top,Bottom" Case "Top,Bottom" _pieceType = "Left,Right" Case "Left,Top" If (clockwise) Then _pieceType = "Top,Right" Else _pieceType = "Bottom,Left" End If Case "Top,Right" If (clockwise) Then _pieceType = "Right,Bottom" Else _pieceType = "Left,Top" End If Case "Right,Bottom" If (clockwise) Then _pieceType = "Bottom,Left" Else _pieceType = "Top,Right" End If Case "Bottom,Left" If clockwise Then _pieceType = "Left,Top" Else _pieceType = "Right,Bottom" End If End Select End Sub
What just happened?
The only information the RotatePiece()
method needs is a rotation direction. For straight pieces, rotation direction does not matter (a left/right piece will always become a top/bottom piece and vice-versa).
For angled pieces, the piece type is updated based on the rotation direction and the previous screenshot.
Tip
Why all the strings?
It would certainly be reasonable to create constants that represent the various piece positions, instead of fully spelling out things, such as Bottom,Left
as strings. However, because the Flood Control game is not taxing on the system, the additional processing time required for string manipulation will not impact the game negatively and helps clarify how the logic works, especially when we get to determine which pipes are filled with water.
Pipe connectors
Our GamePiece
class will need to be able to provide information about the connectors it contains (top, bottom, left, and right) to the rest of the game. Since we have represented the piece types as simple strings, a string comparison will determine what connectors the piece contains.
- Java Data Science Cookbook
- Creating Mobile Apps with Sencha Touch 2
- 大數(shù)據(jù)可視化
- 大數(shù)據(jù)可視化
- R數(shù)據(jù)科學實戰(zhàn):工具詳解與案例分析(鮮讀版)
- Python數(shù)據(jù)分析:基于Plotly的動態(tài)可視化繪圖
- 軟件成本度量國家標準實施指南:理論、方法與實踐
- OracleDBA實戰(zhàn)攻略:運維管理、診斷優(yōu)化、高可用與最佳實踐
- 深入淺出Greenplum分布式數(shù)據(jù)庫:原理、架構和代碼分析
- 數(shù)據(jù)科學實戰(zhàn)指南
- SQL Server深入詳解
- 區(qū)塊鏈+:落地場景與應用實戰(zhàn)
- 數(shù)據(jù)賦能
- Access 2016數(shù)據(jù)庫應用基礎
- 數(shù)據(jù)庫原理及應用:SQL Server 2016