- XNA 4.0 Game Development by Example Beginner's Guide(Visual Basic Edition)
- Kurt Jaegers
- 194字
- 2021-08-20 15:50:42
Time for action – falling pieces
- Add a new class to the Flood Control project called
FallingPiece
. - Add the
Inherits
line after the class declaration as follows:Inherits GamePiece
- Add the following declarations to the
FallingPiece
class:Public VerticalOffset As Integer Public Shared FallRate As Integer = 5
- Add a constructor for the
FallingPiece
class:Public Sub New(type As String, verticalOffset As Integer) MyBase.New(type) Me.VerticalOffset = verticalOffset End Sub
- Add a method to update the piece:
Public Sub UpdatePiece() VerticalOffset = CInt(MathHelper.Max(0, VerticalOffset - FallRate)) End Sub
What just happened?
Simpler than a RotatingPiece
, a FallingPiece
is also a child of the GamePiece
class. A FallingPiece
has an offset (how high above its final destination it is currently located) and a falling speed (the number of pixels it will move per update).
As with a RotatingPiece
, the constructor passes the type parameter to its base class constructor, and uses the verticalOffset
parameter to set the VerticalOffset
member. Again, we use the Me.
notation to differentiate the two identifiers of the same name.
Lastly, the UpdatePiece()
method subtracts FallRate
from VerticalOffset
, again using the MathHelper.Max()
method to ensure that the offset does not fall below zero.
推薦閱讀
- 數據存儲架構與技術
- 數據挖掘原理與實踐
- SQL Server 2008數據庫應用技術(第二版)
- Learning Spring Boot
- 文本數據挖掘:基于R語言
- 大數據Hadoop 3.X分布式處理實戰
- 智能數據時代:企業大數據戰略與實戰
- Splunk智能運維實戰
- 大數據數學基礎(R語言描述)
- Visual Studio 2012 and .NET 4.5 Expert Development Cookbook
- MySQL技術內幕:InnoDB存儲引擎(第2版)
- Tableau數據可視化實戰
- Access數據庫實用教程習題與實驗指導(第2版)
- 數據質量實踐手冊:4步構建高質量數據體系
- SequoiaDB分布式數據庫權威指南