Skip to content

Instantly share code, notes, and snippets.

@bruchmann
Last active March 13, 2024 22:38
Show Gist options
  • Save bruchmann/a2f5ee09ee2254f616b046a78f9eb17e to your computer and use it in GitHub Desktop.
Save bruchmann/a2f5ee09ee2254f616b046a78f9eb17e to your computer and use it in GitHub Desktop.
class_name Damage extends Resource
enum Type {
MAGICAL,
PHYSICAL,
}
@export
var type: Type;
@export_range(1, 1000, 1)
var amount: int = 1;
class_name Actor extends CharacterBody3D
# […]
func take_damage(damage: Damage) -> void:
match damage.type:
Damage.Type.MAGICAL:
_compute_magical_damage(damage.amount);
Damage.Type.PHYSICAL:
_compute_physical_damage(damage.amount);
func _compute_magical_damage(amount: int) -> void:
if self.is_magic_shield_activated():
amount -= 1;
self.health -= amount;
func _compute_physical_damage(amount: int) -> void:
if self.has_shield_in_front_of_body():
amount -= 1;
self.health -= amount;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment