Created
March 14, 2017 22:54
-
-
Save codetravis/a5243aad4f68126f60e2e869fae04a96 to your computer and use it in GitHub Desktop.
14.6 Shoot and Scoot pattern
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
' 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