Add wall hit sound and animation

This commit is contained in:
2025-03-10 11:58:45 -07:00
parent d8c5bc8f78
commit 23049b3231
11 changed files with 189 additions and 47 deletions

View File

@@ -8,7 +8,6 @@ using Godot.Collections;
using SimpleInjector;
using System;
using System.Linq;
using Zennysoft.Game.Abstractions;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;
@@ -88,6 +87,8 @@ public partial class Player : CharacterBody3D, IPlayer
[Node] private Area3D CollisionDetector { get; set; } = default!;
[Node] private Timer HealthTimer { get; set; } = default!;
[Node] private RigidBody3D WallCheck { get; set; } = default!;
#endregion
@@ -211,10 +212,18 @@ public partial class Player : CharacterBody3D, IPlayer
PlayerBinding
.Handle((in PlayerLogic.Output.Animations.Attack output) =>
{
var attackSpeed = EquippedWeapon.Value.AttackSpeed;
AnimationPlayer.SetSpeedScale((float)attackSpeed);
AnimationPlayer.Play("attack");
if (PlayerIsHittingGeometry())
{
AnimationPlayer.Play("hit_wall");
_gameRepo.OnPlayerAttackedWall();
}
else
{
var attackSpeed = EquippedWeapon.Value.AttackSpeed;
AnimationPlayer.SetSpeedScale((float)attackSpeed);
AnimationPlayer.Play("attack");
_gameRepo.OnPlayerAttack();
}
})
.Handle((in PlayerLogic.Output.ThrowItem output) =>
{
@@ -230,32 +239,6 @@ public partial class Player : CharacterBody3D, IPlayer
this.Provide();
}
private void CollisionDetector_AreaEntered(Area3D area)
{
if (area.GetParent() is InventoryItem inventoryItem)
{
var isAdded = Inventory.TryAdd(inventoryItem);
if (isAdded)
{
_gameRepo.AnnounceMessageOnMainScreen($"{inventoryItem.ItemName} picked up.");
inventoryItem.QueueFree();
}
else
_gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {inventoryItem.ItemName}.");
}
if (area.GetParent() is DroppedItem droppedItem)
{
var isAdded = Inventory.TryAdd(droppedItem.Item);
if (isAdded)
{
_gameRepo.AnnounceMessageOnMainScreen($"{droppedItem.Item.ItemName} picked up.");
droppedItem.QueueFree();
}
else
_gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {droppedItem.Item.ItemName}.");
}
}
public void OnReady()
{
SetPhysicsProcess(true);
@@ -502,7 +485,6 @@ public partial class Player : CharacterBody3D, IPlayer
private void OnAnimationFinished(StringName animation)
{
GD.Print("Attack finished");
PlayerLogic.Input(new PlayerLogic.Input.AttackAnimationFinished());
}
@@ -594,4 +576,43 @@ public partial class Player : CharacterBody3D, IPlayer
if (EquippedWeapon.Value.WeaponTag == WeaponTag.Knockback)
enemy.Knockback(0.3f, -CurrentBasis.Z.Normalized());
}
private void CollisionDetector_AreaEntered(Area3D area)
{
if (area.GetParent() is InventoryItem inventoryItem)
{
var isAdded = Inventory.TryAdd(inventoryItem);
if (isAdded)
{
_gameRepo.AnnounceMessageOnMainScreen($"{inventoryItem.ItemName} picked up.");
inventoryItem.QueueFree();
}
else
_gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {inventoryItem.ItemName}.");
}
if (area.GetParent() is DroppedItem droppedItem)
{
var isAdded = Inventory.TryAdd(droppedItem.Item);
if (isAdded)
{
_gameRepo.AnnounceMessageOnMainScreen($"{droppedItem.Item.ItemName} picked up.");
droppedItem.QueueFree();
}
else
_gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {droppedItem.Item.ItemName}.");
}
}
private bool PlayerIsHittingGeometry()
{
var collisions = WallCheck.GetCollidingBodies();
return collisions.Count > 0;
}
private void WallCheck_BodyEntered(Node body)
{
PlayerLogic.Input(new PlayerLogic.Input.AttackAnimationFinished());
GD.Print("Hit wall");
AnimationPlayer.Stop();
}
}

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=60 format=4 uid="uid://cfecvvav8kkp6"]
[gd_scene load_steps=61 format=4 uid="uid://cfecvvav8kkp6"]
[ext_resource type="Script" uid="uid://yxmiqy7i0t7r" path="res://src/player/Player.cs" id="1_xcol5"]
[ext_resource type="Script" uid="uid://6edayafleq8y" path="res://src/hitbox/Hitbox.cs" id="2_lb3qc"]
@@ -96,16 +96,28 @@ tracks/1/keys = {
"values": [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
}
[sub_resource type="Animation" id="Animation_uxo8q"]
resource_name = "explosion"
length = 3.66668
[sub_resource type="Animation" id="Animation_es4xk"]
resource_name = "hit_wall"
length = 0.3
step = 0.0833333
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("SwordSlashAnimation:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.0833333, 0.166667),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 1,
"values": [10, 1, 11]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_w8l8m"]
_data = {
&"RESET": SubResource("Animation_hcjph"),
&"attack": SubResource("Animation_0jjwv"),
&"explosion": SubResource("Animation_uxo8q")
&"hit_wall": SubResource("Animation_es4xk")
}
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_d4v1j"]
@@ -465,6 +477,9 @@ animations = [{
"speed": 12.0
}]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_es4xk"]
height = 1.6909
[node name="Player" type="CharacterBody3D"]
collision_layer = 806
collision_mask = 775
@@ -564,3 +579,19 @@ spot_attenuation = 0.22
[node name="OmniLight3D2" type="OmniLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5.65529, 0.471719)
[node name="WallCheck" type="RigidBody3D" parent="."]
unique_name_in_owner = true
collision_layer = 0
axis_lock_linear_x = true
axis_lock_linear_y = true
axis_lock_linear_z = true
axis_lock_angular_x = true
axis_lock_angular_y = true
axis_lock_angular_z = true
contact_monitor = true
max_contacts_reported = 100
[node name="CollisionShape3D" type="CollisionShape3D" parent="WallCheck"]
transform = Transform3D(1.91069e-15, 4.37114e-08, 1, 1, -4.37114e-08, 0, 4.37114e-08, 1, -4.37114e-08, 0.293308, 1.35803, -0.602638)
shape = SubResource("CapsuleShape3D_es4xk")