Skip to content

Instantly share code, notes, and snippets.

@codetravis
Last active December 16, 2016 23:36
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/dfe1617de6b87d1c8ffaf8eccca87771 to your computer and use it in GitHub Desktop.
Save codetravis/dfe1617de6b87d1c8ffaf8eccca87771 to your computer and use it in GitHub Desktop.
8.4 Modify Character class to handle taking damage
Class Character
' ........................
Method Update
' ......................
' Every update, check to see if the character was damaged
If (Self.box.GetText() = "DAMAGED")
Self.TakeDamage(1)
End
End
' Add a method that handles lowering character health
' and tags characters with 0 health as destroyed
Method TakeDamage(amount:Int=0)
Self.current_health -= amount
If (Self.current_health <= 0)
Self.box.SetText("DESTROYED")
Else If (Self.is_player)
Self.box.SetText("PLAYER")
Else
Self.box.SetText("ENEMY")
End
End
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment