diff --git a/godot/Scenes/Characters/first_person_player.tscn b/godot/Scenes/Characters/first_person_player.tscn index 266fe50..3633df3 100644 --- a/godot/Scenes/Characters/first_person_player.tscn +++ b/godot/Scenes/Characters/first_person_player.tscn @@ -35,7 +35,6 @@ grow_vertical = 2 mouse_filter = 1 [node name="Crosshair" type="Crosshair" parent="UserInterface"] -layout_direction = 1 layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 @@ -64,3 +63,61 @@ width = 2.0 [node name="Left" type="Line2D" parent="UserInterface/Crosshair"] points = PackedVector2Array(15, 20, 5, 20) width = 2.0 + +[node name="HitMarkers" type="HitMarkers" parent="UserInterface"] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -20.0 +offset_top = -20.0 +offset_right = 20.0 +offset_bottom = 20.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="TopRight" type="Line2D" parent="UserInterface/HitMarkers"] +visible = false +points = PackedVector2Array(22.5, 17.5, 35, 5) +width = 2.0 + +[node name="BottomRight" type="Line2D" parent="UserInterface/HitMarkers"] +visible = false +points = PackedVector2Array(22.5, 22.5, 35, 35) +width = 2.0 + +[node name="BottomLeft" type="Line2D" parent="UserInterface/HitMarkers"] +visible = false +points = PackedVector2Array(17.5, 22.5, 5, 35) +width = 2.0 + +[node name="TopLeft" type="Line2D" parent="UserInterface/HitMarkers"] +visible = false +points = PackedVector2Array(17.5, 17.5, 5, 5) +width = 2.0 + +[node name="TopRightHS" type="Line2D" parent="UserInterface/HitMarkers"] +visible = false +points = PackedVector2Array(22.5, 17.5, 35, 5) +width = 2.0 +default_color = Color(1, 0, 0, 1) + +[node name="BottomRightHS" type="Line2D" parent="UserInterface/HitMarkers"] +visible = false +points = PackedVector2Array(22.5, 22.5, 35, 35) +width = 2.0 +default_color = Color(1, 0, 0, 1) + +[node name="BottomLeftHS" type="Line2D" parent="UserInterface/HitMarkers"] +visible = false +points = PackedVector2Array(17.5, 22.5, 5, 35) +width = 2.0 +default_color = Color(1, 0, 0, 1) + +[node name="TopLeftHS" type="Line2D" parent="UserInterface/HitMarkers"] +visible = false +points = PackedVector2Array(17.5, 17.5, 5, 5) +width = 2.0 +default_color = Color(1, 0, 0, 1) diff --git a/src/BoneCollisionShape.cpp b/src/BoneCollisionShape.cpp index 97bba9d..d3d75c3 100644 --- a/src/BoneCollisionShape.cpp +++ b/src/BoneCollisionShape.cpp @@ -35,6 +35,9 @@ void BoneCollisionShape::_ready() { m_Crosshair = Object::cast_to( get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->find_child("Crosshair")); DEV_ASSERT(m_Crosshair); + m_HitMarkers = Object::cast_to( + get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->find_child("HitMarkers")); + DEV_ASSERT(m_HitMarkers); } void BoneCollisionShape::set_head_damage(int a_D) { @@ -56,12 +59,13 @@ int BoneCollisionShape::get_body_damage() const { void BoneCollisionShape::headshot_hit() { ERR_PRINT("zombie headshot hit"); m_Crosshair->set_dot_color(Color(1, 0, 0, 1)); + m_HitMarkers->hsvisible(true); emit_signal("a_ZombieHeadShotHit", m_HeadDamage); } void BoneCollisionShape::bodyshot_hit() { ERR_PRINT("zombie body hit"); - m_Crosshair->set_dot_color(Color(0, 0, 1, 1)); + m_HitMarkers->visible(true); emit_signal("a_ZombieBodyShotHit", m_BodyDamage); } diff --git a/src/BoneCollisionShape.h b/src/BoneCollisionShape.h index 56fe1fa..9ade443 100644 --- a/src/BoneCollisionShape.h +++ b/src/BoneCollisionShape.h @@ -1,6 +1,7 @@ #pragma once #include "Crosshair.h" +#include "HitMarkers.h" #include namespace blitz { @@ -27,6 +28,7 @@ class BoneCollisionShape : public godot::Area3D { void set_body_damage(int d); int get_body_damage() const; Crosshair* m_Crosshair; + HitMarkers* m_HitMarkers; }; } // namespace blitz \ No newline at end of file diff --git a/src/Bullet.cpp b/src/Bullet.cpp index 65734ed..23293d2 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -34,6 +34,8 @@ void Bullet::_ready() { #endif m_Crosshair = Object::cast_to(get_parent()->find_child("Crosshair")); DEV_ASSERT(m_Crosshair); + m_HitMarkers = Object::cast_to(get_parent()->find_child("HitMarkers")); + DEV_ASSERT(m_HitMarkers); } void Bullet::_physics_process(float a_Delta) { @@ -63,6 +65,8 @@ void Bullet::_physics_process(float a_Delta) { void Bullet::_on_timer_timeout() { m_Crosshair->set_dot_color(Color(1, 1, 1, 1)); + m_HitMarkers->visible(); + m_HitMarkers->hsvisible(); queue_free(); } diff --git a/src/Bullet.h b/src/Bullet.h index 56412fd..097dadd 100644 --- a/src/Bullet.h +++ b/src/Bullet.h @@ -1,6 +1,7 @@ #pragma once #include "Crosshair.h" +#include "HitMarkers.h" #include #include #include @@ -26,6 +27,7 @@ class Bullet : public godot::Node3D { godot::MeshInstance3D* m_Mesh; godot::Timer* m_Timer; Crosshair* m_Crosshair; + HitMarkers* m_HitMarkers; void _on_timer_timeout(); }; diff --git a/src/HitMarkers.cpp b/src/HitMarkers.cpp new file mode 100644 index 0000000..bf13619 --- /dev/null +++ b/src/HitMarkers.cpp @@ -0,0 +1,37 @@ +#include "HitMarkers.h" + +using namespace godot; + +namespace blitz { +void HitMarkers::_bind_methods() {} + +HitMarkers::HitMarkers() {} +HitMarkers::~HitMarkers() {} + +void HitMarkers::_ready() { + m_HitMarkerLines = {Object::cast_to(find_child("TopRight")), Object::cast_to(find_child("BottomRight")), + Object::cast_to(find_child("BottomLeft")), Object::cast_to(find_child("TopLeft"))}; + for (size_t i = 0; i < m_HitMarkerLines.size(); i++) { + DEV_ASSERT(m_HitMarkerLines[i]); + } + m_HitMarkerHSLines = {Object::cast_to(find_child("TopRightHS")), Object::cast_to(find_child("BottomRightHS")), + Object::cast_to(find_child("BottomLeftHS")), Object::cast_to(find_child("TopLeftHS"))}; + for (size_t i = 0; i < m_HitMarkerHSLines.size(); i++) { + DEV_ASSERT(m_HitMarkerHSLines[i]); + } + this->visible(); +} + +void HitMarkers::visible(bool a_Bool) { + for (size_t i = 0; i < m_HitMarkerLines.size(); i++) { + m_HitMarkerLines[i]->set_visible(a_Bool); + } +} + +void HitMarkers::hsvisible(bool a_Bool) { + for (size_t i = 0; i < m_HitMarkerHSLines.size(); i++) { + m_HitMarkerHSLines[i]->set_visible(a_Bool); + } +} + +} // namespace blitz \ No newline at end of file diff --git a/src/HitMarkers.h b/src/HitMarkers.h new file mode 100644 index 0000000..b4c0e35 --- /dev/null +++ b/src/HitMarkers.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include + +namespace blitz { +class HitMarkers : public godot::CenterContainer { + GDCLASS(HitMarkers, godot::CenterContainer) + protected: + static void _bind_methods(); + + public: + HitMarkers(); + ~HitMarkers(); + + void _ready(); + void visible(bool visiblity = false); + void hsvisible(bool visiblity = false); + + private: + std::array m_HitMarkerLines; + std::array m_HitMarkerHSLines; +}; + +} // namespace blitz \ No newline at end of file diff --git a/src/register_types.cpp b/src/register_types.cpp index d6711be..15cd658 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -2,12 +2,13 @@ #include "BoneCollisionShape.h" #include "Bullet.h" +#include "Crosshair.h" #include "FirstPersonPlayer.h" +#include "HitMarkers.h" #include "Player.h" #include "SpringArmPivot.h" #include "World.h" #include "Zombie.h" -#include "Crosshair.h" #include #include @@ -28,6 +29,7 @@ void initialize_example_module(ModuleInitializationLevel p_level) { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); } void uninitialize_example_module(ModuleInitializationLevel p_level) {