Last active
December 22, 2016 13:01
-
-
Save codetravis/bc87ae1b9d0a8fa2fd5f6a6aef25b753 to your computer and use it in GitHub Desktop.
8.12 Modify Character class with FireProjectile boolean method
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
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