From dce110a9b3c5c9f033a009133c0f7e509d3c7b3b Mon Sep 17 00:00:00 2001 From: Victor Turgeon Date: Tue, 11 Oct 2022 13:48:59 -0400 Subject: [PATCH] Switch HUD into player scene --- HUD.tscn | 134 ++++++++++++++++++++++++++++++++++++++++++++++++ Player.gd | 3 +- Player.tscn | 5 +- Test_Scene.tscn | 126 +-------------------------------------------- 4 files changed, 141 insertions(+), 127 deletions(-) create mode 100644 HUD.tscn diff --git a/HUD.tscn b/HUD.tscn new file mode 100644 index 0000000..64a0b8d --- /dev/null +++ b/HUD.tscn @@ -0,0 +1,134 @@ +[gd_scene load_steps=11 format=2] + +[ext_resource path="res://SlapGauge.gd" type="Script" id=1] +[ext_resource path="res://Title Timer.gd" type="Script" id=2] +[ext_resource path="res://fonts/TorontoSubwayRegular.ttf" type="DynamicFontData" id=3] + +[sub_resource type="DynamicFont" id=7] +size = 88 +outline_size = 5 +outline_color = Color( 0, 0, 0, 1 ) +use_filter = true +font_data = ExtResource( 3 ) + +[sub_resource type="DynamicFont" id=4] +size = 19 +outline_size = 2 +outline_color = Color( 0, 0, 0, 1 ) +use_mipmaps = true +use_filter = true +font_data = ExtResource( 3 ) + +[sub_resource type="Theme" id=8] +default_font = SubResource( 4 ) + +[sub_resource type="DynamicFont" id=9] +size = 19 +outline_size = 2 +outline_color = Color( 0, 0, 0, 1 ) +use_mipmaps = true +use_filter = true +font_data = ExtResource( 3 ) + +[sub_resource type="Theme" id=10] +default_font = SubResource( 9 ) + +[sub_resource type="Shader" id=6] +code = "shader_type canvas_item; +render_mode unshaded; + +uniform float fill; +uniform float kill; +uniform vec4 bkgcol = vec4(0.0, 0.0, 0.0, 0.3); +uniform vec4 kilcol = vec4(0.5, 0.0, 0.0, 0.3); + +void fragment() { + bool is = false; + if (fill >= UV.x) { + COLOR = vec4(UV.x,-UV.x + .5,-UV.x + 1.0,1.0); + COLOR.rgb *= vec3(cos(UV.y * 2.0) / 1.5,cos(UV.y * 2.0) / 1.5,cos(UV.y * 2.0) / 1.5); + is = true; + + if (kill >= UV.x) + COLOR.rgb += vec3(0.1,0.1,0.1); + + } + else if (UV.x > kill + 0.001) + COLOR = kilcol; + else COLOR = bkgcol; + + if ((UV.y < .2 || UV.y > 0.8) && (UV.x > kill + 0.001 || UV.x < kill - 0.001) && !is) + COLOR.a = 0.05; + +}" + +[sub_resource type="ShaderMaterial" id=11] +shader = SubResource( 6 ) +shader_param/fill = 0.0 +shader_param/kill = null +shader_param/bkgcol = Plane( 0, 0, 0, 0.3 ) +shader_param/kilcol = Plane( 0.5, 0, 0, 0.3 ) + +[node name="HUD" type="CanvasLayer"] + +[node name="Start" type="Control" parent="."] +visible = false +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="Title" type="Label" parent="Start"] +anchor_left = 12.9 +anchor_top = 7.625 +anchor_right = 12.9 +anchor_bottom = 7.625 +margin_left = -439.0 +margin_top = -54.0 +margin_right = 443.0 +margin_bottom = 48.0 +custom_fonts/font = SubResource( 7 ) +text = "FIRST PERSON SLAPPER" + +[node name="Title Timer" type="Timer" parent="Start"] +one_shot = true +script = ExtResource( 2 ) + +[node name="New Game" type="Button" parent="Start"] +anchor_left = 12.85 +anchor_top = 10.525 +anchor_right = 12.85 +anchor_bottom = 10.525 +margin_left = -67.0 +margin_top = -20.0 +margin_right = 70.0 +margin_bottom = 16.0 +theme = SubResource( 8 ) +text = "New Game" + +[node name="ActualHUD" type="Control" parent="."] +margin_right = 40.0 +margin_bottom = 40.0 +theme = SubResource( 10 ) + +[node name="SlapGauge" type="ColorRect" parent="ActualHUD"] +material = SubResource( 11 ) +anchor_left = 12.875 +anchor_top = 7.625 +anchor_right = 12.875 +anchor_bottom = 7.625 +margin_left = -451.0 +margin_top = 218.0 +margin_right = -161.0 +margin_bottom = 241.0 +script = ExtResource( 1 ) + +[node name="SlapLabel" type="Label" parent="ActualHUD"] +modulate = Color( 1, 1, 1, 0.611765 ) +anchor_left = 12.662 +anchor_top = 7.324 +anchor_right = 12.662 +anchor_bottom = 7.324 +margin_left = -436.48 +margin_top = 229.04 +margin_right = -325.48 +margin_bottom = 261.04 +text = "Slap" diff --git a/Player.gd b/Player.gd index 5f9f66a..e711e88 100644 --- a/Player.gd +++ b/Player.gd @@ -23,6 +23,7 @@ var gravity_vec = Vector3() onready var head = $Head onready var ground_check = $GroundCheck +onready var SlapGauge = $HUD/ActualHUD/SlapGauge func _ready(): Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) @@ -81,7 +82,7 @@ func _physics_process(delta): else: slap -= delta * 8.0; slap = clamp(slap, 0.0, 1.0) - get_node("/root/Spatial/HUD/ActualHUD/SlapGauge").fill = slap; + SlapGauge.fill = slap; direction = direction.normalized() diff --git a/Player.tscn b/Player.tscn index 9ba039b..e717002 100644 --- a/Player.tscn +++ b/Player.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://Player.gd" type="Script" id=1] [ext_resource path="res://BlenderStuff/Hand/protohand.obj" type="ArrayMesh" id=2] [ext_resource path="res://Textures/kenney_prototype_textures/purple/texture_01.png" type="Texture" id=3] +[ext_resource path="res://HUD.tscn" type="PackedScene" id=4] [sub_resource type="CapsuleShape" id=2] height = 3.0 @@ -41,3 +42,5 @@ material/0 = SubResource( 4 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0 ) enabled = true cast_to = Vector3( 0, -1.5, 0 ) + +[node name="HUD" parent="." instance=ExtResource( 4 )] diff --git a/Test_Scene.tscn b/Test_Scene.tscn index 7b8d312..17ba975 100644 --- a/Test_Scene.tscn +++ b/Test_Scene.tscn @@ -1,12 +1,9 @@ -[gd_scene load_steps=15 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://Materials/Dark_ProtoMat.tres" type="Material" id=1] [ext_resource path="res://Player.tscn" type="PackedScene" id=2] [ext_resource path="res://Materials/Orange_ProtoMat.tres" type="Material" id=3] [ext_resource path="res://AllSkyFree_Skyboxes/Epic_BlueSunset_EquiRect_flat.png" type="Texture" id=4] -[ext_resource path="res://Title Timer.gd" type="Script" id=5] -[ext_resource path="res://fonts/TorontoSubwayRegular.ttf" type="DynamicFontData" id=6] -[ext_resource path="res://SlapGauge.gd" type="Script" id=7] [sub_resource type="PanoramaSky" id=1] panorama = ExtResource( 4 ) @@ -41,60 +38,6 @@ glow_bloom = 0.02 glow_hdr_threshold = 0.44 glow_bicubic_upscale = true -[sub_resource type="DynamicFont" id=3] -size = 88 -outline_size = 5 -outline_color = Color( 0, 0, 0, 1 ) -use_filter = true -font_data = ExtResource( 6 ) - -[sub_resource type="DynamicFont" id=4] -size = 19 -outline_size = 2 -outline_color = Color( 0, 0, 0, 1 ) -use_mipmaps = true -use_filter = true -font_data = ExtResource( 6 ) - -[sub_resource type="Theme" id=5] -default_font = SubResource( 4 ) - -[sub_resource type="Shader" id=6] -code = "shader_type canvas_item; -render_mode unshaded; - -uniform float fill; -uniform float kill; -uniform vec4 bkgcol = vec4(0.0, 0.0, 0.0, 0.3); -uniform vec4 kilcol = vec4(0.5, 0.0, 0.0, 0.3); - -void fragment() { - bool is = false; - if (fill >= UV.x) { - COLOR = vec4(UV.x,-UV.x + .5,-UV.x + 1.0,1.0); - COLOR.rgb *= vec3(cos(UV.y * 2.0) / 1.5,cos(UV.y * 2.0) / 1.5,cos(UV.y * 2.0) / 1.5); - is = true; - - if (kill >= UV.x) - COLOR.rgb += vec3(0.1,0.1,0.1); - - } - else if (UV.x > kill + 0.001) - COLOR = kilcol; - else COLOR = bkgcol; - - if ((UV.y < .2 || UV.y > 0.8) && (UV.x > kill + 0.001 || UV.x < kill - 0.001) && !is) - COLOR.a = 0.05; - -}" - -[sub_resource type="ShaderMaterial" id=7] -shader = SubResource( 6 ) -shader_param/fill = 0.0 -shader_param/kill = null -shader_param/bkgcol = Plane( 0, 0, 0, 0.3 ) -shader_param/kilcol = Plane( 0.5, 0, 0, 0.3 ) - [node name="Spatial" type="Spatial"] [node name="CSGCombiner" type="CSGCombiner" parent="."] @@ -122,70 +65,3 @@ transform = Transform( 1, 0, 0, 0, 0.849579, 0.527461, 0, -0.527461, 0.849579, 0 light_color = Color( 1, 0.924276, 0.869018, 1 ) light_specular = 1.0 shadow_enabled = true - -[node name="HUD" type="CanvasLayer" parent="."] -__meta__ = { -"_editor_description_": "Heads Up Display" -} - -[node name="Start" type="Control" parent="HUD"] -visible = false -margin_right = 40.0 -margin_bottom = 40.0 - -[node name="Title" type="Label" parent="HUD/Start"] -anchor_left = 12.9 -anchor_top = 7.625 -anchor_right = 12.9 -anchor_bottom = 7.625 -margin_left = -439.0 -margin_top = -54.0 -margin_right = 443.0 -margin_bottom = 48.0 -custom_fonts/font = SubResource( 3 ) -text = "FIRST PERSON SLAPPER" - -[node name="Title Timer" type="Timer" parent="HUD/Start"] -one_shot = true -script = ExtResource( 5 ) - -[node name="New Game" type="Button" parent="HUD/Start"] -anchor_left = 12.85 -anchor_top = 10.525 -anchor_right = 12.85 -anchor_bottom = 10.525 -margin_left = -67.0 -margin_top = -20.0 -margin_right = 70.0 -margin_bottom = 16.0 -theme = SubResource( 5 ) -text = "New Game" - -[node name="ActualHUD" type="Control" parent="HUD"] -margin_right = 40.0 -margin_bottom = 40.0 -theme = SubResource( 5 ) - -[node name="SlapGauge" type="ColorRect" parent="HUD/ActualHUD"] -material = SubResource( 7 ) -anchor_left = 12.875 -anchor_top = 7.625 -anchor_right = 12.875 -anchor_bottom = 7.625 -margin_left = -451.0 -margin_top = 218.0 -margin_right = -161.0 -margin_bottom = 241.0 -script = ExtResource( 7 ) - -[node name="SlapLabel" type="Label" parent="HUD/ActualHUD"] -modulate = Color( 1, 1, 1, 0.611765 ) -anchor_left = 12.662 -anchor_top = 7.324 -anchor_right = 12.662 -anchor_bottom = 7.324 -margin_left = -436.48 -margin_top = 229.04 -margin_right = -325.48 -margin_bottom = 261.04 -text = "Slap"