Skip to content

Instantly share code, notes, and snippets.

@codetravis
Created January 2, 2017 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codetravis/cebe658d2bcc5b1483ee398609e9deeb to your computer and use it in GitHub Desktop.
Save codetravis/cebe658d2bcc5b1483ee398609e9deeb to your computer and use it in GitHub Desktop.
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