Instantly share code, notes, and snippets.

Embed
What would you like to do?
10.3 Refactor the player creation code into a method
' 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