Now About Social Code
summaryrefslogtreecommitdiff
path: root/addons/fpc/reticles
diff options
context:
space:
mode:
authorLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-09-17 22:02:33 +0100
committerLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-09-17 22:02:33 +0100
commit0abec8156bd944aa883d544850ee1187219ba943 (patch)
tree55e222da361d176b0ba79611704b56e2d942a831 /addons/fpc/reticles
Initial commit
Diffstat (limited to 'addons/fpc/reticles')
-rw-r--r--addons/fpc/reticles/reticle_0.tscn37
-rw-r--r--addons/fpc/reticles/reticle_1.tscn104
2 files changed, 141 insertions, 0 deletions
diff --git a/addons/fpc/reticles/reticle_0.tscn b/addons/fpc/reticles/reticle_0.tscn
new file mode 100644
index 0000000..2828124
--- /dev/null
+++ b/addons/fpc/reticles/reticle_0.tscn
@@ -0,0 +1,37 @@
+[gd_scene load_steps=2 format=3 uid="uid://coqpusufa8a6k"]
+
+[sub_resource type="GDScript" id="GDScript_10f85"]
+script/source = "extends CenterContainer
+
+
+@export_category(\"Reticle\")
+@export_group(\"Nodes\")
+@export var character : CharacterBody3D
+
+@export_group(\"Settings\")
+@export var dot_size : int = 1
+@export var dot_color : Color = Color.WHITE
+
+
+func _process(_delta):
+ if visible: # If the reticle is disabled (not visible), don't bother updating it
+ update_reticle_settings()
+
+func update_reticle_settings():
+ $dot.scale.x = dot_size
+ $dot.scale.y = dot_size
+ $dot.color = dot_color
+"
+
+[node name="Reticle" type="CenterContainer"]
+anchors_preset = 8
+anchor_left = 0.5
+anchor_top = 0.5
+anchor_right = 0.5
+anchor_bottom = 0.5
+grow_horizontal = 2
+grow_vertical = 2
+script = SubResource("GDScript_10f85")
+
+[node name="dot" type="Polygon2D" parent="."]
+polygon = PackedVector2Array(-1, -1, 1, -1, 1, 1, -1, 1)
diff --git a/addons/fpc/reticles/reticle_1.tscn b/addons/fpc/reticles/reticle_1.tscn
new file mode 100644
index 0000000..bb83b83
--- /dev/null
+++ b/addons/fpc/reticles/reticle_1.tscn
@@ -0,0 +1,104 @@
+[gd_scene load_steps=2 format=3 uid="uid://3mij3cjhkwsm"]
+
+[sub_resource type="GDScript" id="GDScript_a8kpl"]
+script/source = "extends CenterContainer
+
+
+@export_category(\"Reticle\")
+@export_group(\"Nodes\")
+@export var reticle_lines : Array[Line2D]
+@export var character : CharacterBody3D
+
+@export_group(\"Animate\")
+@export var animated_reticle : bool = true
+@export var reticle_speed : float = 0.5
+@export var reticle_spread : float = 4.0
+
+@export_group(\"Dot Settings\")
+@export var dot_size : int = 1
+@export var dot_color : Color = Color.WHITE
+
+@export_group(\"Line Settings\")
+@export var line_color : Color = Color.WHITE
+@export var line_width : int = 2
+@export var line_length : int = 10
+@export var line_distance : int = 5
+@export_enum(\"None\", \"Round\") var cap_mode : int = 0
+
+
+func _process(_delta):
+ if visible: # If the reticle is disabled (not visible), don't bother updating it
+ update_reticle_settings()
+ if animated_reticle:
+ animate_reticle_lines()
+
+
+func animate_reticle_lines():
+ var vel = character.get_real_velocity()
+ var origin = Vector3(0,0,0)
+ var pos = Vector2(0,0)
+ var speed = origin.distance_to(vel)
+
+ reticle_lines[0].position = lerp(reticle_lines[0].position, pos + Vector2(0, -speed * reticle_spread), reticle_speed)
+ reticle_lines[1].position = lerp(reticle_lines[1].position, pos + Vector2(-speed * reticle_spread, 0), reticle_speed)
+ reticle_lines[2].position = lerp(reticle_lines[2].position, pos + Vector2(speed * reticle_spread, 0), reticle_speed)
+ reticle_lines[3].position = lerp(reticle_lines[3].position, pos + Vector2(0, speed * reticle_spread), reticle_speed)
+
+
+func update_reticle_settings():
+ # Dot
+ $dot.scale.x = dot_size
+ $dot.scale.y = dot_size
+ $dot.color = dot_color
+
+ # Lines
+ for line in reticle_lines:
+ line.default_color = line_color
+ line.width = line_width
+ if cap_mode == 0:
+ line.begin_cap_mode = Line2D.LINE_CAP_NONE
+ line.end_cap_mode = Line2D.LINE_CAP_NONE
+ elif cap_mode == 1:
+ line.begin_cap_mode = Line2D.LINE_CAP_ROUND
+ line.end_cap_mode = Line2D.LINE_CAP_ROUND
+
+ # Please someone find a better way to do this
+ reticle_lines[0].points[0].y = -line_distance
+ reticle_lines[0].points[1].y = -line_length - line_distance
+ reticle_lines[1].points[0].x = -line_distance
+ reticle_lines[1].points[1].x = -line_length - line_distance
+ reticle_lines[2].points[0].x = line_distance
+ reticle_lines[2].points[1].x = line_length + line_distance
+ reticle_lines[3].points[0].y = line_distance
+ reticle_lines[3].points[1].y = line_length + line_distance
+"
+
+[node name="Reticle" type="CenterContainer" node_paths=PackedStringArray("reticle_lines")]
+anchors_preset = 8
+anchor_left = 0.5
+anchor_top = 0.5
+anchor_right = 0.5
+anchor_bottom = 0.5
+grow_horizontal = 2
+grow_vertical = 2
+script = SubResource("GDScript_a8kpl")
+reticle_lines = [NodePath("top"), NodePath("left"), NodePath("right"), NodePath("bottom")]
+
+[node name="dot" type="Polygon2D" parent="."]
+polygon = PackedVector2Array(-1, -1, 1, -1, 1, 1, -1, 1)
+
+[node name="top" type="Line2D" parent="."]
+points = PackedVector2Array(0, -5, 0, -15)
+width = 2.0
+
+[node name="left" type="Line2D" parent="."]
+points = PackedVector2Array(-5, 0, -15, 0)
+width = 2.0
+
+[node name="right" type="Line2D" parent="."]
+points = PackedVector2Array(5, 0, 15, 0)
+width = 2.0
+
+[node name="bottom" type="Line2D" parent="."]
+points = PackedVector2Array(0, 5, 0, 15)
+width = 2.0