Skip to content

Instantly share code, notes, and snippets.

@codetravis
Created March 14, 2017 22:54
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/a5243aad4f68126f60e2e869fae04a96 to your computer and use it in GitHub Desktop.
Save codetravis/a5243aad4f68126f60e2e869fae04a96 to your computer and use it in GitHub Desktop.
14.6 Shoot and Scoot pattern
' Fire and run pattern
Function ShootAndScootPattern(box:ftObject, game_width:Float, game_height:Float, max_y_speed:Float=5.0)
If (box.GetSpeedY() < 0.1 And box.GetSpeedY() > -0.1)
If (box.GetPosX() < game_width/1.5)
' Using the boxes Tag property to tell enemies to fire
box.SetTag(1)
If (box.GetPosY() > game_height/2)
box.SetSpeedY(max_y_speed * -1)
Else
box.SetSpeedY(max_y_speed)
End
End
End
End
'.....................
' We add some checks to our OnUpdate method in the main game loop
Method OnUpdate
'...................
For Local enemy:Character = Eachin Self.enemies
enemy.Update(engine.GetCanvasWidth(), engine.GetCanvasHeight())
' Adding a way to tell enemies to fire projectiles
If (enemy.box.GetTag() = 1 And enemy.FireProjectile())
enemy.box.SetTag(0)
CreateProjectile(enemy)
End
If (enemy.box.GetText() = "DESTROYED")
If (enemy.current_health <= 0)
Self.player.IncreaseScore(enemy.point_value)
End
enemy.box.Remove()
Self.enemies.RemoveFirst(enemy)
End
End
End
'...........
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment