From 8cc87c4b14a01dc64bfc8f7cd8ec85d9da18cd04 Mon Sep 17 00:00:00 2001 From: Logan Date: Tue, 21 Jul 2020 00:13:31 -0500 Subject: [PATCH] Player stores scene --- Player/PlayerVariables.gd | 10 ++++++---- magic/Beams/Beam.gd | 16 ++++++++++++++++ magic/Beams/EcoBeam.tscn | 2 +- project.godot | 6 ++++++ ui/PlayerStats.gd | 9 ++++++--- 5 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 magic/Beams/Beam.gd diff --git a/Player/PlayerVariables.gd b/Player/PlayerVariables.gd index fe790ce..51cb96c 100644 --- a/Player/PlayerVariables.gd +++ b/Player/PlayerVariables.gd @@ -1,13 +1,15 @@ extends Node var position: Vector2 = Vector2() -var health: float = -1 -var energy: float = -1 +var health = null +var energy = null var unlocked: Array = [Globals.Conduit2] +var current_scene: PackedScene func respawn(): - health = -1 - energy = -1 + health = null + energy = null func reset_magic(): unlocked = [] + diff --git a/magic/Beams/Beam.gd b/magic/Beams/Beam.gd new file mode 100644 index 0000000..3f7945c --- /dev/null +++ b/magic/Beams/Beam.gd @@ -0,0 +1,16 @@ +extends Node2D +class_name Beam + +var max_cast = Vector2(400, 0) + +onready var Beam: Sprite = $Beam +onready var Begin: Sprite = $Begin +onready var Ray: RayCast2D = $Raycast2D +onready var End: Position2D = $End + +func _physics_process(delta): + Ray.cast_to = max_cast + if Ray.is_colliding(): + End.global_position = Ray.get_collision_point() + else: + End.position = max_cast diff --git a/magic/Beams/EcoBeam.tscn b/magic/Beams/EcoBeam.tscn index 7982729..a0c1f93 100644 --- a/magic/Beams/EcoBeam.tscn +++ b/magic/Beams/EcoBeam.tscn @@ -17,6 +17,6 @@ region_rect = Rect2( 0, 0, 8, 8 ) [node name="RayCast2D" type="RayCast2D" parent="."] enabled = true -cast_to = Vector2( 100, 0 ) +cast_to = Vector2( 400, 0 ) [node name="End" type="Position2D" parent="."] diff --git a/project.godot b/project.godot index 4fe307e..f635f4f 100644 --- a/project.godot +++ b/project.godot @@ -9,6 +9,11 @@ config_version=4 _global_script_classes=[ { +"base": "Node2D", +"class": "Beam", +"language": "GDScript", +"path": "res://magic/Beams/Beam.gd" +}, { "base": "Area2D", "class": "Collectable", "language": "GDScript", @@ -40,6 +45,7 @@ _global_script_classes=[ { "path": "res://magic/Wands/WandClass.gd" } ] _global_script_class_icons={ +"Beam": "", "Collectable": "", "Enemy": "", "EnemyProjectile": "", diff --git a/ui/PlayerStats.gd b/ui/PlayerStats.gd index dd78f28..9c2d632 100644 --- a/ui/PlayerStats.gd +++ b/ui/PlayerStats.gd @@ -10,10 +10,9 @@ var energy = 5 setget set_energy, get_energy var is_burnout = false func _ready(): - print(Player.energy) - if Player.health == -1: + if Player.health == null: Player.health = Hearts.max_value - if Player.energy == -1: + if Player.energy == null: Player.energy = Energybar.max_value print("max") set_health(Player.health) @@ -25,6 +24,10 @@ func _on_Regen_timeout(): is_burnout = false func _process(delta): + if Player.health == null: + Player.health = Hearts.max_value + if Player.energy == null: + Player.energy = Energybar.max_value if get_accurate_energy() < Energybar.max_value and Regen.is_stopped(): Regen.start() BurnoutSprite.visible = is_burnout