Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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) = 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()
' 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
Return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment