
上QQ阅读APP看书,第一时间看更新
Time for action — creating some launchers in the game
To create launchers follow the ensuing steps:
- Open the
mainClass.monkey
file. - Inside the
SetupGame
method, add the left launcher by callingCreateLauncher
. Itsx
position is30
pixels and it has the A key as a trigger and15
rockets to start with.Next CreateLauncher(30.0, KEY_A, 15)
- Add the right launcher using a different
x
position and S as the trigger key, but also specify that there are15
rockets.CreateLauncher(cWidth - 30.0, KEY_S, 15)
What just happened?
You told the game to create two rocket launchers at the beginning of the game. Easy, isn't it? Creating those classes pays off now.