Skip to content

Instantly share code, notes, and snippets.

@codetravis
Created January 6, 2017 13:46
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/c7169e4beaf04859d0c7fd490b462bfb to your computer and use it in GitHub Desktop.
Save codetravis/c7169e4beaf04859d0c7fd490b462bfb to your computer and use it in GitHub Desktop.
11.5 Modify character class to handle more character types
Import fantomX
Import projectile_type
Class Character
Field box:ftObject
Field current_health:Int
Field max_health:Int
' changing is_player to character_type
Field character_type:String
Field projectile_type:ProjectileType
Field last_projectile_time:Float
Field point_value:Int
Field points_earned:Int
' change the constructor to use the new field and default it to enemy
Method New(box:ftObject, projectile_type:ProjectileType, point_value:Int=5, health:Int=1, character_type:String="ENEMY")
Self.box = box
Self.current_health = health
Self.max_health = health
Self.character_type = character_type
Self.projectile_type = projectile_type
Self.last_projectile_time = Millisecs()
Self.point_value = point_value
Self.points_earned = 0
End
Method Update(game_width:Float, game_height:Float)
Local x_speed:Float = Self.box.GetSpeedX()
Local y_speed:Float = Self.box.GetSpeedY()
' change this check from is_player to check the character type
If (Self.character_type = "PLAYER")
' ..................
End
If (Self.box.GetText() = "DAMAGED")
Self.TakeDamage(1)
End
End
Method TakeDamage(amount:Int=0)
Self.current_health -= amount
If (Self.current_health <= 0)
Self.box.SetText("DESTROYED")
' refactor the way characters reset box text
' when taking damage
Else
Self.box.SetText(Self.character_type)
End
End
' ...............................
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment