Skip to content

Commit

Permalink
Add tracking gamemode feedback
Browse files Browse the repository at this point in the history
Health slider animation and hit sound to tell players when they are hitting the target
  • Loading branch information
antimundo committed Apr 14, 2024
1 parent cf28cfe commit ee0a6f3
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 9 deletions.
9 changes: 8 additions & 1 deletion scenes/enemies/health_slider.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
extends MeshInstance3D
## Slider that shows the health of the enemy targets

var enabled: bool = true
var enabled: bool = false

func _process(_delta: float) -> void:
visible = enabled
if enabled:
var health = $"..".health
var max_health = $"..".max_health
Expand All @@ -13,3 +14,9 @@ func enable() -> void:
visible = true
enabled = true
position.y = ($"../CollisionShape3D/MeshInstance3D".mesh.height / 2) + 0.4

func _on_target_hitted():
$AudioStreamPlayer.play()
$AudioStreamPlayer.pitch_scale = randf_range(0.97, 1.03)
$AnimationPlayer.play("RESET")
$AnimationPlayer.play("shot")
Binary file added scenes/enemies/hit.ogg
Binary file not shown.
19 changes: 19 additions & 0 deletions scenes/enemies/hit.ogg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[remap]

importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://kf70w8cqg0y"
path="res://.godot/imported/hit.ogg-270303119ed9432215d93f22754ac306.oggvorbisstr"

[deps]

source_file="res://scenes/enemies/hit.ogg"
dest_files=["res://.godot/imported/hit.ogg-270303119ed9432215d93f22754ac306.oggvorbisstr"]

[params]

loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4
14 changes: 8 additions & 6 deletions scenes/enemies/target.gd
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
extends CharacterBody3D

signal destroyed
signal destroyed ## When player destroys the target
signal hitted ## When player when player hits the target

@onready var _mesh_instance := $CollisionShape3D/MeshInstance3D

var _current_velocity: Vector3 = Vector3.ZERO
var max_health: float
var health: float = 0.0:
set(value):
if value < health:
hitted.emit()
health = value
if health < 0.0:
emit_signal("destroyed")
queue_free()

func _ready() -> void:
_set_health()
_set_health_slider()
_set_target_material()

func _physics_process(delta: float) -> void:
if _current_velocity != Vector3.ZERO:
var collision_info = move_and_collide(_current_velocity * delta)
Expand All @@ -33,6 +31,10 @@ func init(size = {"radius": .5, "height": 1}, movement = {"x": 0, "y": 0}) -> vo
_mesh_instance.mesh.height = size.height
_current_velocity = Vector3(randf_range(-movement.x, movement.x),\
randf_range(-movement.y, movement.y), 0)

_set_health()
_set_health_slider()
_set_target_material()

func _set_health() -> void:
max_health = Global.current_gamemode.health
Expand Down
53 changes: 51 additions & 2 deletions scenes/enemies/target.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=8 format=3 uid="uid://baj568pnwc4ph"]
[gd_scene load_steps=12 format=3 uid="uid://baj568pnwc4ph"]

[ext_resource type="Script" path="res://scenes/enemies/target.gd" id="1_nte11"]
[ext_resource type="Script" path="res://scenes/enemies/health_slider.gd" id="2_usxmj"]
[ext_resource type="AudioStream" uid="uid://kf70w8cqg0y" path="res://scenes/enemies/hit.ogg" id="3_o7ev4"]

[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_do5mn"]
height = 1.0
Expand All @@ -25,6 +26,43 @@ emission = Color(1, 1, 1, 1)
material = SubResource("StandardMaterial3D_18ew3")
size = Vector2(3, 0.3)

[sub_resource type="Animation" id="Animation_7m7wm"]
resource_name = "shot"
length = 0.3
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:mesh:material:emission")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.3),
"transitions": PackedFloat32Array(-2, -2, -2),
"update": 0,
"values": [Color(1, 0.294118, 0.360784, 1), Color(1, 0.294118, 0.360784, 1), Color(1, 1, 1, 1)]
}

[sub_resource type="Animation" id="Animation_adj6b"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:mesh:material:emission")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 1)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_nqfqo"]
_data = {
"RESET": SubResource("Animation_adj6b"),
"shot": SubResource("Animation_7m7wm")
}

[node name="Target" type="CharacterBody3D" groups=["Enemy"]]
collision_mask = 2
motion_mode = 1
Expand All @@ -39,6 +77,17 @@ skeleton = NodePath("../..")

[node name="HealthSlider" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.7, 0)
visible = false
mesh = SubResource("PlaneMesh_4njml")
script = ExtResource("2_usxmj")

[node name="AnimationPlayer" type="AnimationPlayer" parent="HealthSlider"]
libraries = {
"": SubResource("AnimationLibrary_nqfqo")
}
autoplay = "RESET"

[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="HealthSlider"]
stream = ExtResource("3_o7ev4")
volume_db = -10.0

[connection signal="hitted" from="." to="HealthSlider" method="_on_target_hitted"]

0 comments on commit ee0a6f3

Please sign in to comment.