Last active
December 16, 2016 23:36
-
-
Save codetravis/dfe1617de6b87d1c8ffaf8eccca87771 to your computer and use it in GitHub Desktop.
8.4 Modify Character class to handle taking damage
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
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