From 4d11fe8fc791f187386f7b8e59b9129a19348d10 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Tue, 11 Oct 2022 12:48:08 -0400 Subject: [PATCH] Slap Gauge --- Player.gd | 19 ++++++++ SlapGauge.gd | 14 ++++++ Test_Scene.tscn | 116 +++++++++++++++++++++++++++++++++++++++++++++++- Title Timer.gd | 17 +++++++ project.godot | 5 +++ 5 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 SlapGauge.gd create mode 100644 Title Timer.gd diff --git a/Player.gd b/Player.gd index 9a3465f..9db4d45 100644 --- a/Player.gd +++ b/Player.gd @@ -7,6 +7,8 @@ export var air_acceleration = 1 export var normal_acceleration = 6 export var gravity = 100 export var jump = 30 +var slap = 0.0 +var isSlap = false export var mouse_sensitivity = 0.03 @@ -65,7 +67,24 @@ func _physics_process(delta): elif Input.is_action_pressed("move_right"): direction += transform.basis.x + if Input.is_action_just_released("slap"): + isSlap = false; + elif Input.is_action_just_pressed("slap"): + isSlap = true; + + if (isSlap): + slap += delta; + else: + slap -= delta * 4.0; + + slap = clamp(slap, 0.0, 1.1) + + if (slap > 1.0 && isSlap): + isSlap = false + slap = 0.0; + + get_node("/root/Spatial/HUD/ActualHUD/SlapGauge").fill = slap; direction = direction.normalized() h_velocity = h_velocity.linear_interpolate(direction * speed, h_acceleration * delta) movement.z = h_velocity.z + gravity_vec.z diff --git a/SlapGauge.gd b/SlapGauge.gd new file mode 100644 index 0000000..f94e833 --- /dev/null +++ b/SlapGauge.gd @@ -0,0 +1,14 @@ +extends ColorRect + +var Mat; +var fill = 0.0; +var kill = 0.66; + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass + +func _process(delta): + material.set_shader_param("fill",clamp(fill, 0.0, 1.0)) + material.set_shader_param("kill",clamp(kill, 0.0, 1.0)) + diff --git a/Test_Scene.tscn b/Test_Scene.tscn index 17ba975..fca0bfd 100644 --- a/Test_Scene.tscn +++ b/Test_Scene.tscn @@ -1,9 +1,12 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=15 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 ) @@ -38,6 +41,50 @@ 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() { + 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); + } + else if (UV.x >= kill) + COLOR = kilcol; + else COLOR = bkgcol; +}" + +[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="."] @@ -65,3 +112,70 @@ 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" diff --git a/Title Timer.gd b/Title Timer.gd new file mode 100644 index 0000000..d757478 --- /dev/null +++ b/Title Timer.gd @@ -0,0 +1,17 @@ +extends Timer + + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + diff --git a/project.godot b/project.godot index a636b1e..2005ec9 100644 --- a/project.godot +++ b/project.godot @@ -55,6 +55,11 @@ sprint={ "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":16777237,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } +slap={ +"deadzone": 0.5, +"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null) + ] +} [physics]