Created
January 2, 2017 23:52
-
-
Save codetravis/cebe658d2bcc5b1483ee398609e9deeb to your computer and use it in GitHub Desktop.
10.3 Refactor the player creation code into a method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Game class | |
Method OnCreate() | |
Self.engine = New CustomEngine | |
play_scene = engine.GetDefaultScene() | |
play_layer = engine.GetDefaultLayer() | |
play_scene.AddLayer(play_layer) | |
' Create our player | |
CreatePlayer() | |
Self.enemies = New List<Character>() | |
Self.last_enemy_time = Millisecs() | |
Self.next_enemy_interval = 3000 | |
'.... | |
End | |
'....... | |
' Move the player creation code to its own method | |
' for ease in resetting the game | |
Method CreatePlayer() | |
Local box:ftObject = Self.engine.CreateBox(120, 20, engine.GetCanvasWidth()/2, engine.GetCanvasHeight()/2) | |
box.SetColor(0, 70, 70) | |
box.SetMaxSpeed(20.0) | |
box.SetMinSpeed(-20.0) | |
box.SetColGroup(PLAYER_GROUP) | |
box.SetColType(Self.engine.ctBox) | |
box.SetText("PLAYER") | |
Local projectile_type:ProjectileType = New ProjectileType() | |
Self.player = New Character(box, projectile_type, 0, 3, True) | |
End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment