From ec63e57c628f3e429cf03ff88b5b403336014bac Mon Sep 17 00:00:00 2001 From: derek Date: Thu, 31 Oct 2024 15:20:49 -0500 Subject: [PATCH] hide hud on pause and dead camera --- assets/blockout_2.tscn | 33 ++++++++++++----------- assets/player.tscn | 39 ++++++++++++++++++++++++--- pause_menu.gdshader | 60 ++++++++++++++++++++--------------------- pause_menu.tscn | 2 +- project.godot | 1 + scripts/LevelManager.gd | 10 ++++--- scripts/player.gd | 13 +++++++-- scripts/rocket.gd | 1 + 8 files changed, 104 insertions(+), 55 deletions(-) diff --git a/assets/blockout_2.tscn b/assets/blockout_2.tscn index e466211..d54777c 100644 --- a/assets/blockout_2.tscn +++ b/assets/blockout_2.tscn @@ -645,21 +645,6 @@ size = Vector3(11.605, 4.25, 0.61) [sub_resource type="BoxShape3D" id="BoxShape3D_uer68"] size = Vector3(9.26855, 4.28711, 0.640869) -[sub_resource type="Animation" id="Animation_d2bci"] -resource_name = "open" -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:position") -tracks/0/interp = 2 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0, 1), -"transitions": PackedFloat32Array(1, 1), -"update": 0, -"values": [Vector3(0, 28.5934, 14.0814), Vector3(0, 32.6882, 14.0814)] -} - [sub_resource type="Animation" id="Animation_0aerp"] length = 0.001 tracks/0/type = "value" @@ -690,6 +675,21 @@ tracks/0/keys = { "values": [Vector3(0, 32.6882, 14.0814), Vector3(0, 28.5934, 14.0814)] } +[sub_resource type="Animation" id="Animation_d2bci"] +resource_name = "open" +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath(".:position") +tracks/0/interp = 2 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 1), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [Vector3(0, 28.5934, 14.0814), Vector3(0, 32.6882, 14.0814)] +} + [sub_resource type="AnimationLibrary" id="AnimationLibrary_m24x1"] _data = { "RESET": SubResource("Animation_0aerp"), @@ -1745,4 +1745,7 @@ libraries = { } autoplay = "movingswitch" +[node name="rocketlauncher1_pickup2" parent="." instance=ExtResource("11_6de2k")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 29.7453, -2.8486, 37.7796) + [connection signal="switch_hit" from="Switch 1/switch/StaticBody3D" to="Switch 1/switch" method="_on_static_body_3d_switch_hit"] diff --git a/assets/player.tscn b/assets/player.tscn index 27d1d39..5fea1f5 100644 --- a/assets/player.tscn +++ b/assets/player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=25 format=3 uid="uid://drwae3loscbw7"] +[gd_scene load_steps=27 format=3 uid="uid://drwae3loscbw7"] [ext_resource type="Script" path="res://scripts/player.gd" id="1_x7wms"] [ext_resource type="PackedScene" uid="uid://dcmno6wafk5hg" path="res://assets/dead_player.tscn" id="2_4hoys"] @@ -17,6 +17,7 @@ [ext_resource type="AudioStream" uid="uid://cwre1dq8gsvbg" path="res://assets/Audio/Foley Sports/Boxing/Gloves Block Intense.wav" id="12_qhd01"] [ext_resource type="PackedScene" uid="uid://cfbwx2fsdp0b3" path="res://pause_menu.tscn" id="13_xrfwr"] [ext_resource type="AudioStream" uid="uid://t50i483xmj3a" path="res://assets/Audio/Weapons/toy-click-spin-SBA-300071143.wav" id="14_pnsbm"] +[ext_resource type="Shader" path="res://assets/crtTest.gdshader" id="14_v5svg"] [ext_resource type="AudioStream" uid="uid://c1e6vr2hndho7" path="res://assets/Audio/Weapons/Misc (Ammo Boxes, Holsters, Etc)/Kydex Unholster 002.wav" id="17_1fyjm"] [sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_l5ga0"] @@ -34,6 +35,30 @@ font_size = 115 shadow_size = 16 shadow_color = Color(0, 0, 0, 1) +[sub_resource type="ShaderMaterial" id="ShaderMaterial_ubnx7"] +shader = ExtResource("14_v5svg") +shader_parameter/overlay = true +shader_parameter/scanlines_opacity = 0.025 +shader_parameter/scanlines_width = 0.315 +shader_parameter/grille_opacity = 0.1 +shader_parameter/resolution = Vector2(640, 480) +shader_parameter/pixelate = false +shader_parameter/roll = false +shader_parameter/roll_speed = 1.165 +shader_parameter/roll_size = 38.883 +shader_parameter/roll_variation = 1.8 +shader_parameter/distort_intensity = 0.0 +shader_parameter/noise_opacity = 0.0 +shader_parameter/noise_speed = 5.0 +shader_parameter/static_noise_intensity = 0.035 +shader_parameter/aberration = 0.00500005 +shader_parameter/brightness = 1.4 +shader_parameter/discolor = true +shader_parameter/warp_amount = 0.0 +shader_parameter/clip_warp = true +shader_parameter/vignette_intensity = 0.4 +shader_parameter/vignette_opacity = 0.235 + [sub_resource type="BoxShape3D" id="BoxShape3D_nfpjw"] size = Vector3(3, 3.58057, 3) @@ -95,7 +120,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.437954, -1) stream = ExtResource("14_pnsbm") volume_db = 2.0 -[node name="AmmoCounter" type="Label" parent="Head/Recoil/Camera3D"] +[node name="AmmoCounter" type="Label" parent="Head/Recoil/Camera3D" groups=["hud"]] offset_right = 3840.0 offset_bottom = 2160.0 size_flags_horizontal = 3 @@ -107,7 +132,7 @@ vertical_alignment = 2 script = ExtResource("4_8cy44") padding_amount = 0.025 -[node name="StaminaCounter" type="Label" parent="Head/Recoil/Camera3D"] +[node name="StaminaCounter" type="Label" parent="Head/Recoil/Camera3D" groups=["hud"]] offset_right = 3440.0 offset_bottom = 1440.0 size_flags_horizontal = 3 @@ -126,7 +151,7 @@ hit_back_faces = false [node name="AudioListener3D" type="AudioListener3D" parent="Head/Recoil/Camera3D"] transform = Transform3D(1, 0, 0, 0, 0.992332, 0.123601, 0, -0.123601, 0.992332, 0, -0.921646, -0.000722691) -[node name="Crosshair" type="TextureRect" parent="Head/Recoil/Camera3D"] +[node name="Crosshair" type="TextureRect" parent="Head/Recoil/Camera3D" groups=["hud"]] offset_right = 40.0 offset_bottom = 40.0 texture = ExtResource("6_5m60e") @@ -162,6 +187,12 @@ visible = false offset_right = 0.0 offset_bottom = 0.0 +[node name="crtFilter" type="ColorRect" parent="Head/Recoil/Camera3D"] +visible = false +material = SubResource("ShaderMaterial_ubnx7") +offset_right = 3840.0 +offset_bottom = 2160.0 + [node name="pick_up_detection" type="Area3D" parent="."] collision_layer = 0 collision_mask = 16 diff --git a/pause_menu.gdshader b/pause_menu.gdshader index 45f6d14..7f2c377 100644 --- a/pause_menu.gdshader +++ b/pause_menu.gdshader @@ -2,14 +2,14 @@ Shader from Godot Shaders - the free shader library. godotshaders.com/shader/VHS-and-CRT-monitor-effect -This shader is under CC0 license. Feel free to use, improve and -change this shader according to your needs and consider sharing +This shader is under CC0 license. Feel free to use, improve and +change this shader according to your needs and consider sharing the modified result to godotshaders.com. */ shader_type canvas_item; -//*** IMPORTANT! ***/ +//*** IMPORTANT! ***/ // - If you are using this shader to affect the node it is applied to set 'overlay' to false (unchecked in the instepctor). // - If you are using this shader as an overlay, and want the shader to affect the nodes below in the Scene hierarchy, // set 'overlay' to true (checked in the inspector). @@ -72,7 +72,7 @@ vec2 warp(vec2 uv){ float delta2 = dot(delta.xy, delta.xy); float delta4 = delta2 * delta2; float delta_offset = delta4 * warp_amount; - + return uv + delta * delta_offset; } @@ -99,14 +99,14 @@ void fragment() vec2 text_uv = uv; vec2 roll_uv = vec2(0.0); float time = roll ? TIME : 0.0; - + // Pixelate the texture based on the given resolution. if (pixelate) { text_uv = ceil(uv * resolution) / resolution; } - + // Create the rolling effect. We need roll_line a bit later to make the noise effect. // That is why this runs if roll is true OR noise_opacity is over 0. float roll_line = 0.0; @@ -119,11 +119,11 @@ void fragment() // Distort the UV where where the lines are roll_uv = vec2(( roll_line * distort_intensity * (1.-UV.x)), 0.0); } - + vec4 text; if (roll) { - // If roll is true distort the texture with roll_uv. The texture is split up into RGB to + // If roll is true distort the texture with roll_uv. The texture is split up into RGB to // make some chromatic aberration. We apply the aberration to the red and green channels accorging to the aberration parameter // and intensify it a bit in the roll distortion. text.r = texture(SCREEN_TEXTURE, text_uv + roll_uv * 0.8 + vec2(aberration, 0.0) * .1).r; @@ -133,43 +133,43 @@ void fragment() } else { - // If roll is false only apply the aberration without any distorion. The aberration values are very small so the .1 is only + // If roll is false only apply the aberration without any distorion. The aberration values are very small so the .1 is only // to make the slider in the Inspector less sensitive. text.r = texture(SCREEN_TEXTURE, text_uv + vec2(aberration, 0.0) * .1).r; text.g = texture(SCREEN_TEXTURE, text_uv - vec2(aberration, 0.0) * .1).g; text.b = texture(SCREEN_TEXTURE, text_uv).b; text.a = 1.0; } - + float r = text.r; float g = text.g; float b = text.b; - + uv = warp(UV); - - // CRT monitors don't have pixels but groups of red, green and blue dots or lines, called grille. We isolate the texture's color channels + + // CRT monitors don't have pixels but groups of red, green and blue dots or lines, called grille. We isolate the texture's color channels // and divide it up in 3 offsetted lines to show the red, green and blue colors next to each other, with a small black gap between. if (grille_opacity > 0.0){ - + float g_r = smoothstep(0.85, 0.95, abs(sin(uv.x * (resolution.x * 3.14159265)))); r = mix(r, r * g_r, grille_opacity); - + float g_g = smoothstep(0.85, 0.95, abs(sin(1.05 + uv.x * (resolution.x * 3.14159265)))); g = mix(g, g * g_g, grille_opacity); - + float b_b = smoothstep(0.85, 0.95, abs(sin(2.1 + uv.x * (resolution.x * 3.14159265)))); b = mix(b, b * b_b, grille_opacity); - + } - + // Apply the grille to the texture's color channels and apply Brightness. Since the grille and the scanlines (below) make the image very dark you // can compensate by increasing the brightness. text.r = clamp(r * brightness, 0.0, 1.0); text.g = clamp(g * brightness, 0.0, 1.0); text.b = clamp(b * brightness, 0.0, 1.0); - - // Scanlines are the horizontal lines that make up the image on a CRT monitor. - // Here we are actual setting the black gap between each line, which I guess is not the right definition of the word, but you get the idea + + // Scanlines are the horizontal lines that make up the image on a CRT monitor. + // Here we are actual setting the black gap between each line, which I guess is not the right definition of the word, but you get the idea float scanlines = 0.5; if (scanlines_opacity > 0.0) { @@ -177,29 +177,29 @@ void fragment() scanlines = smoothstep(scanlines_width, scanlines_width + 0.5, abs(sin(uv.y * (resolution.y * 3.14159265)))); text.rgb = mix(text.rgb, text.rgb * vec3(scanlines), scanlines_opacity); } - + // Apply the banded noise. if (noise_opacity > 0.0) { // Generate a noise pattern that is very stretched horizontally, and animate it with noise_speed float noise = smoothstep(0.4, 0.5, noise(uv * vec2(2.0, 200.0) + vec2(10.0, (TIME * (noise_speed))) ) ); - + // We use roll_line (set above) to define how big the noise should be vertically (multiplying cuts off all black parts). - // We also add in some basic noise with random() to break up the noise pattern above. The noise is sized according to - // the resolution value set in the inspector. If you don't like this look you can + // We also add in some basic noise with random() to break up the noise pattern above. The noise is sized according to + // the resolution value set in the inspector. If you don't like this look you can // change "ceil(uv * resolution) / resolution" to only "uv" to make it less pixelated. Or multiply resolution with som value // greater than 1.0 to make them smaller. roll_line *= noise * scanlines * clamp(random((ceil(uv * resolution) / resolution) + vec2(TIME * 0.8, 0.0)).x + 0.8, 0.0, 1.0); // Add it to the texture based on noise_opacity text.rgb = clamp(mix(text.rgb, text.rgb + roll_line, noise_opacity), vec3(0.0), vec3(1.0)); } - + // Apply static noise by generating it over the whole screen in the same way as above if (static_noise_intensity > 0.0) { text.rgb += clamp(random((ceil(uv * resolution) / resolution) + fract(TIME)).x, 0.0, 1.0) * static_noise_intensity; } - + // Apply a black border to hide imperfections caused by the warping. // Also apply the vignette text.rgb *= border(uv); @@ -209,7 +209,7 @@ void fragment() { text.a = border(uv); } - + // Apply discoloration to get a VHS look (lower saturation and higher contrast) // You can play with the values below or expose them in the Inspector. float saturation = 0.5; @@ -219,11 +219,11 @@ void fragment() // Saturation vec3 greyscale = vec3(text.r + text.g + text.b) / 3.; text.rgb = mix(text.rgb, greyscale, saturation); - + // Contrast float midpoint = pow(0.5, 2.2); text.rgb = (text.rgb - vec3(midpoint)) * contrast + midpoint; } - + COLOR = text; } \ No newline at end of file diff --git a/pause_menu.tscn b/pause_menu.tscn index 369e533..38fbb9d 100644 --- a/pause_menu.tscn +++ b/pause_menu.tscn @@ -45,7 +45,7 @@ shader_parameter/noise_opacity = 0.4 shader_parameter/noise_speed = 5.0 shader_parameter/static_noise_intensity = 0.06 shader_parameter/aberration = 0.03 -shader_parameter/brightness = 1.4 +shader_parameter/brightness = 0.7 shader_parameter/discolor = true shader_parameter/warp_amount = 0.0 shader_parameter/clip_warp = true diff --git a/project.godot b/project.godot index 57b2a0d..37bc749 100644 --- a/project.godot +++ b/project.godot @@ -41,6 +41,7 @@ scene_rigidbody="" weight="" switch_override="" magnet="" +hud="" [input] diff --git a/scripts/LevelManager.gd b/scripts/LevelManager.gd index 701f166..665014d 100644 --- a/scripts/LevelManager.gd +++ b/scripts/LevelManager.gd @@ -37,6 +37,7 @@ var last_hit : Node var respawn_position var respawn_cam_rotation var respawn_rot +var engine_time_scale_cache : float = 1.0 # Called when the node enters the scene tree for the first time. func _ready(): @@ -144,6 +145,8 @@ func die(): get_tree().get_root().add_child(instance_dead) instance_dead.camera.current = true player.dead = true + player.crt_filter.visible = true + player.toggle_hud() player.gun.visible = false player.crosshair.visible = false @@ -157,14 +160,15 @@ func pickup_spawn(): func pause_menu(): if paused: - Engine.time_scale = 1 + Engine.time_scale = engine_time_scale_cache Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) - player.crosshair.visible = true + player.toggle_hud() player.pause_menu.hide() else: + engine_time_scale_cache = Engine.time_scale Engine.time_scale = 0 Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) - player.crosshair.visible = false + player.toggle_hud() player.pause_menu.show() paused = !paused diff --git a/scripts/player.gd b/scripts/player.gd index eb61e68..d945a14 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -73,6 +73,7 @@ var gun_fire_pitch_starting var current_weapon_index var recoiling = false var dead = false +var hud_visible : bool = true # Slow Down Variables var remaining_stamina = MAX_STAMINA @@ -103,6 +104,7 @@ var pickupmsg @onready var flashlight_audio: AudioStreamPlayer3D = $Head/Recoil/Camera3D/WeaponHolder/FlashlightButton @onready var kick_audio: AudioStreamPlayer3D = $Head/Recoil/Camera3D/Audio/Kick @onready var weapon_pickup_audio: AudioStreamPlayer = $Audio/WeaponPickup +@onready var crt_filter: ColorRect = $Head/Recoil/Camera3D/crtFilter func _ready(): @@ -134,8 +136,8 @@ func _input(event) -> void: mouse_input = event.relative else: if event is InputEventMouseMotion: - self.rotate_y(-event.relative.x * .00001) - head.rotate_x(-event.relative.y * .00001) + self.rotate_y(event.relative.x * .00001) + head.rotate_x(event.relative.y * .00001) head.rotation.x = clamp(head.rotation.x, deg_to_rad(-90), deg_to_rad(85)) mouse_input = event.relative @@ -398,3 +400,10 @@ func enemy_hit(): hitmarker.visible = true await get_tree().create_timer(.1).timeout hitmarker.visible = false + +func toggle_hud(): + crosshair.visible = !hud_visible + ammo_counter.visible = !hud_visible + stamina_counter.visible = !hud_visible + + hud_visible = !hud_visible diff --git a/scripts/rocket.gd b/scripts/rocket.gd index c1bce62..e9e6556 100644 --- a/scripts/rocket.gd +++ b/scripts/rocket.gd @@ -55,6 +55,7 @@ func explode(): body.linear_velocity += blast_velocity if body.is_in_group("player"): body.velocity += clamp(blast_velocity,Vector3(-7,-7,-7),Vector3(7,7,7)) + body.recoil.add_recoil(Vector3(1,.1,.1),10,10) if body.is_in_group("enemy"): body.knocked = true body.stunned = true