Skip to content

Instantly share code, notes, and snippets.

@codetravis
Last active December 22, 2016 13:01
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/bc87ae1b9d0a8fa2fd5f6a6aef25b753 to your computer and use it in GitHub Desktop.
Save codetravis/bc87ae1b9d0a8fa2fd5f6a6aef25b753 to your computer and use it in GitHub Desktop.
8.12 Modify Character class with FireProjectile boolean method
Import fantomX
Import projectile_type
Class Character
Field box:ftObject
Field current_health:Int
Field max_health:Int
Field is_player:Bool
Field projectile_type:ProjectileType
' last projectile fired time
Field last_projectile_time:Float
Method New(box:ftObject, projectile_type:ProjectileType, health:Int=1, player:Bool=False)
Self.box = box
Self.current_health = health
Self.max_health = health
Self.is_player = player
Self.projectile_type = projectile_type
' Initialize last projectile time
Self.last_projectile_time = Millisecs()
End
'................................
' Add method to determine whether or not this character can fire a projectile
Method FireProjectile:Bool()
If ((Millisecs() - Self.last_projectile_time) > (1000.0 / Self.projectile_type.rate_of_fire))
Self.last_projectile_time = Millisecs()
Return True
Else
Return False
End
End
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment