From ee24fa535275a8ee0e7845ea798d5532e16aaf88 Mon Sep 17 00:00:00 2001 From: Logan Date: Tue, 21 Jul 2020 19:50:43 -0500 Subject: [PATCH] All magic done --- ai/ogre.gd | 2 +- magic/Projectiles/ExplosiveProjectile.gd | 2 +- magic/Projectiles/Projectile.gd | 7 +++++- magic/Wands/ChargedWand.gd | 30 ++++++++++++++++++++++++ magic/Wands/ChargedWand.tscn | 9 +++++-- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/ai/ogre.gd b/ai/ogre.gd index 4c14e68..edfed2b 100644 --- a/ai/ogre.gd +++ b/ai/ogre.gd @@ -8,7 +8,7 @@ onready var Hurtbox = $Area2D func _ready(): speed = 50 - health = 3.5 + health = 3 func _physics_process(delta): Player.current_scene = "res://levels/World.tscn" diff --git a/magic/Projectiles/ExplosiveProjectile.gd b/magic/Projectiles/ExplosiveProjectile.gd index 04a3478..3b7ecc1 100644 --- a/magic/Projectiles/ExplosiveProjectile.gd +++ b/magic/Projectiles/ExplosiveProjectile.gd @@ -19,7 +19,7 @@ func on_impact(collision): func explode(): for body in $Area2D.get_overlapping_bodies(): if body.get("health") != null and body.get_type() != "player": - body.health -= damage + body.health -= damage * damage_mod if body.has_method("play_hit"): body.play_hit() $Explosion.play(0.0) diff --git a/magic/Projectiles/Projectile.gd b/magic/Projectiles/Projectile.gd index 905198a..c27c265 100644 --- a/magic/Projectiles/Projectile.gd +++ b/magic/Projectiles/Projectile.gd @@ -15,6 +15,8 @@ var is_charge = false var is_prism = false var is_triple = false +onready var Spr: Sprite = $Sprite + func get_wand_type(wand_id): match wand_id: Globals.Conduit1: @@ -37,8 +39,11 @@ func _physics_process(delta): if collision != null: on_impact(collision) -func launch(wand): +func launch(wand, mod = 1): velocity = (Vector2(speed, 0)).rotated(rotation) + damage_mod = mod + scale = Vector2(1, 1) + Spr.scale = Vector2(mod, mod) get_wand_type(wand) return energy_cost * energy_mod diff --git a/magic/Wands/ChargedWand.gd b/magic/Wands/ChargedWand.gd index 111b859..615ca14 100644 --- a/magic/Wands/ChargedWand.gd +++ b/magic/Wands/ChargedWand.gd @@ -1 +1,31 @@ extends Wand + +var charge_level = 0 +var max_charge = 3 +var projectile = null + +onready var ChargeTimer: Timer = $ChargeTimer + +func fire(p): + projectile = p + if ChargeTimer.is_stopped(): + ChargeTimer.start() + +func _process(delta): + print(charge_level) + scale = Vector2(charge_level / 2 + 1, charge_level / 2 + 1) + +func _on_ChargeTimer_timeout(): + charge_level = clamp(charge_level + 0.5, 0, max_charge) + +func _input(event): + if event.is_action_released("shoot"): + ChargeTimer.stop() + if charge_level <= 0: + charge_level = 0 + return + var temp = projectile.instance() + get_tree().current_scene.add_child(temp) + temp.global_transform = $ProjectileSpawn.global_transform + var energy_cost = temp.launch(wand_type, charge_level) + charge_level = 0 diff --git a/magic/Wands/ChargedWand.tscn b/magic/Wands/ChargedWand.tscn index e30585c..16c0339 100644 --- a/magic/Wands/ChargedWand.tscn +++ b/magic/Wands/ChargedWand.tscn @@ -1,10 +1,10 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://magic/Wands/WandClass.gd" type="Script" id=1] +[ext_resource path="res://magic/Wands/ChargedWand.gd" type="Script" id=1] [ext_resource path="res://art/Wand.png" type="Texture" id=2] [node name="ChargedWand" type="Sprite"] -position = Vector2( 9, 0 ) +position = Vector2( 11, 0 ) rotation = 1.5708 texture = ExtResource( 2 ) script = ExtResource( 1 ) @@ -16,3 +16,8 @@ rotation = -1.5708 [node name="ShootDelay" type="Timer" parent="."] wait_time = 0.3 one_shot = true + +[node name="ChargeTimer" type="Timer" parent="."] +wait_time = 0.4 +one_shot = true +[connection signal="timeout" from="ChargeTimer" to="." method="_on_ChargeTimer_timeout"]