- 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.
推薦閱讀
- 我們都是數(shù)據(jù)控:用大數(shù)據(jù)改變商業(yè)、生活和思維方式
- 大規(guī)模數(shù)據(jù)分析和建模:基于Spark與R
- Python數(shù)據(jù)分析與挖掘?qū)崙?zhàn)
- SQL Server 2012數(shù)據(jù)庫技術(shù)與應(yīng)用(微課版)
- 輕松學(xué)大數(shù)據(jù)挖掘:算法、場景與數(shù)據(jù)產(chǎn)品
- 使用GitOps實(shí)現(xiàn)Kubernetes的持續(xù)部署:模式、流程及工具
- InfluxDB原理與實(shí)戰(zhàn)
- 數(shù)據(jù)驅(qū)動:從方法到實(shí)踐
- “互聯(lián)網(wǎng)+”時代立體化計算機(jī)組
- SQL優(yōu)化最佳實(shí)踐:構(gòu)建高效率Oracle數(shù)據(jù)庫的方法與技巧
- Hands-On Mathematics for Deep Learning
- 實(shí)用數(shù)據(jù)結(jié)構(gòu)
- 貫通SQL Server 2008數(shù)據(jù)庫系統(tǒng)開發(fā)
- Web Services Testing with soapUI
- Python 3爬蟲、數(shù)據(jù)清洗與可視化實(shí)戰(zhàn)