From 7faf33349c4841448b5f030f246046759baa8417 Mon Sep 17 00:00:00 2001 From: Logan Date: Mon, 20 Jul 2020 00:06:53 -0500 Subject: [PATCH] Projectiles do damage --- ai/Enemy.gd | 1 + magic/Projectiles/Projectile.gd | 5 +++++ project.godot | 1 + 3 files changed, 7 insertions(+) diff --git a/ai/Enemy.gd b/ai/Enemy.gd index 72dc6b6..753ef10 100644 --- a/ai/Enemy.gd +++ b/ai/Enemy.gd @@ -8,6 +8,7 @@ var health = 5 const UP = Vector2(0, -1) var velocity = Vector2() + func get_type(): return "enemy" diff --git a/magic/Projectiles/Projectile.gd b/magic/Projectiles/Projectile.gd index 06b8f0e..3c279c8 100644 --- a/magic/Projectiles/Projectile.gd +++ b/magic/Projectiles/Projectile.gd @@ -4,6 +4,7 @@ class_name Projectile export var speed = 300 var velocity = Vector2.ZERO var energy_cost = 1 +var damage = 1 onready var Hit = get_node("Node/Hit") onready var Hit_Wall = get_node("Node/Hit Wall") @@ -17,4 +18,8 @@ func launch(wand, effect): return energy_cost func on_impact(collision): + if collision.collider.has_method("get_type") && collision.collider.get_type() == "enemy": + var c = collision.collider + print(c.health) + c.health -= damage queue_free() diff --git a/project.godot b/project.godot index 7773123..3f85285 100644 --- a/project.godot +++ b/project.godot @@ -100,6 +100,7 @@ texture={ up={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) ] } down={