Last active
December 21, 2016 14:40
-
-
Save codetravis/763e3e5d0403ad644d621f202979da66 to your computer and use it in GitHub Desktop.
8.14 Modify OnObjectCollision method in CustomEngine Class
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 | |
Class CustomEngine Extends ftEngine | |
Method OnObjectCollision:Int(obj_one:ftObject, obj_two:ftObject) | |
' Refactor character collision checks to use method | |
If (obj_one.GetText() = "PLAYER" And obj_two.GetText() = "ENEMY") | |
CharacterCollision(obj_one, obj_two) | |
Else If (obj_two.GetText() = "PLAYER" And obj_one.GetText() = "ENEMY") | |
CharacterCollision(obj_two, obj_one) | |
End | |
' Check for projectile collision with enemies | |
If (obj_one.GetText() = "PROJECTILE" And obj_two.GetText() = "ENEMY") | |
ProjectileCollision(obj_one, obj_two) | |
Else If (obj_two.GetText() = "PROJECTILE" And obj_one.GetText() = "ENEMY") | |
ProjectileCollision(obj_two, obj_one) | |
End | |
Return 0 | |
End | |
' add projectile collison behavior | |
Method ProjectileCollision(projectile_box:ftObject, enemy_box:ftObject) | |
projectile_box.SetText("DESTROYED") | |
enemy_box.SetText("DAMAGED") | |
projectile_box.SetColWith(enemy_box.GetColGroup(), False) | |
End | |
' refactor character collision behavior to a method | |
Method CharacterCollision(player_box:ftObject, enemy_box:ftObject) | |
player_box.SetText("DAMAGED") | |
enemy_box.SetText("DAMAGED") | |
enemy_box.SetColWith(player_box.GetColGroup(), False) | |
End | |
End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment