Compare commits

...

3 Commits

9 changed files with 188 additions and 28 deletions

View File

@@ -49,17 +49,75 @@ grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
[node name="Top" type="Line2D" parent="UserInterface/Crosshair"] [node name="Top" type="Line2D" parent="UserInterface/Crosshair"]
points = PackedVector2Array(0, -5, 0, -15) points = PackedVector2Array(20, 15, 20, 5)
width = 2.0 width = 2.0
[node name="Right" type="Line2D" parent="UserInterface/Crosshair"] [node name="Right" type="Line2D" parent="UserInterface/Crosshair"]
points = PackedVector2Array(5, 0, 15, 0) points = PackedVector2Array(25, 20, 35, 20)
width = 2.0 width = 2.0
[node name="Bottom" type="Line2D" parent="UserInterface/Crosshair"] [node name="Bottom" type="Line2D" parent="UserInterface/Crosshair"]
points = PackedVector2Array(0, 5, 0, 15) points = PackedVector2Array(20, 25, 20, 35)
width = 2.0 width = 2.0
[node name="Left" type="Line2D" parent="UserInterface/Crosshair"] [node name="Left" type="Line2D" parent="UserInterface/Crosshair"]
points = PackedVector2Array(-5, 0, -15, 0) points = PackedVector2Array(15, 20, 5, 20)
width = 2.0 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)

View File

@@ -1,23 +1,25 @@
#include "BoneCollisionShape.h" #include "BoneCollisionShape.h"
#include <godot_cpp/classes/engine.hpp>
using namespace godot; using namespace godot;
namespace blitz { namespace blitz {
void BoneCollisionShape::_bind_methods() { void BoneCollisionShape::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_head_damage"), &BoneCollisionShape::get_head_damage); ClassDB::bind_method(D_METHOD("get_head_damage"), &BoneCollisionShape::get_head_damage);
ClassDB::bind_method(D_METHOD("set_head_damage", "m_HeadDamage"), &BoneCollisionShape::set_head_damage); ClassDB::bind_method(D_METHOD("set_head_damage", "m_HeadDamage"), &BoneCollisionShape::set_head_damage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "m_HeadDamage"), "set_head_damage", "get_head_damage"); ADD_PROPERTY(PropertyInfo(Variant::INT, "m_HeadDamage"), "set_head_damage", "get_head_damage");
ClassDB::bind_method(D_METHOD("get_body_damage"), &BoneCollisionShape::get_body_damage); ClassDB::bind_method(D_METHOD("get_body_damage"), &BoneCollisionShape::get_body_damage);
ClassDB::bind_method(D_METHOD("set_body_damage", "m_BodyDamage"), &BoneCollisionShape::set_body_damage); ClassDB::bind_method(D_METHOD("set_body_damage", "m_BodyDamage"), &BoneCollisionShape::set_body_damage);
ADD_PROPERTY(PropertyInfo(Variant::INT, "m_BodyDamage"), "set_head_damage", "get_body_damage"); ADD_PROPERTY(PropertyInfo(Variant::INT, "m_BodyDamage"), "set_head_damage", "get_body_damage");
ADD_SIGNAL(MethodInfo("a_ZombieHeadShotHit", PropertyInfo(Variant::INT, "dam"))); ADD_SIGNAL(MethodInfo("a_ZombieHeadShotHit", PropertyInfo(Variant::INT, "dam")));
ADD_SIGNAL(MethodInfo("a_ZombieBodyShotHit", PropertyInfo(Variant::INT, "dam"))); ADD_SIGNAL(MethodInfo("a_ZombieBodyShotHit", PropertyInfo(Variant::INT, "dam")));
ClassDB::bind_method(D_METHOD("headshot_hit"), &BoneCollisionShape::headshot_hit); ClassDB::bind_method(D_METHOD("headshot_hit"), &BoneCollisionShape::headshot_hit);
ClassDB::bind_method(D_METHOD("bodyshot_hit"), &BoneCollisionShape::bodyshot_hit); ClassDB::bind_method(D_METHOD("bodyshot_hit"), &BoneCollisionShape::bodyshot_hit);
} }
BoneCollisionShape::BoneCollisionShape() {} BoneCollisionShape::BoneCollisionShape() {}
@@ -25,36 +27,46 @@ BoneCollisionShape::BoneCollisionShape() {}
BoneCollisionShape::~BoneCollisionShape() {} BoneCollisionShape::~BoneCollisionShape() {}
void BoneCollisionShape::_ready() { void BoneCollisionShape::_ready() {
m_Crosshair = Object::cast_to<Crosshair>(get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->find_child("Crosshair")); #if DEBUG_ENABLED
DEV_ASSERT(m_Crosshair); if (Engine::get_singleton()->is_editor_hint()) {
return;
}
#endif
m_Crosshair = Object::cast_to<Crosshair>(
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<HitMarkers>(
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) { void BoneCollisionShape::set_head_damage(int a_D) {
m_HeadDamage = a_D; m_HeadDamage = a_D;
} }
int BoneCollisionShape::get_head_damage() const { int BoneCollisionShape::get_head_damage() const {
return m_HeadDamage; return m_HeadDamage;
} }
void BoneCollisionShape::set_body_damage(int a_D) { void BoneCollisionShape::set_body_damage(int a_D) {
m_BodyDamage = a_D; m_BodyDamage = a_D;
} }
int BoneCollisionShape::get_body_damage() const { int BoneCollisionShape::get_body_damage() const {
return m_BodyDamage; return m_BodyDamage;
} }
void BoneCollisionShape::headshot_hit() { void BoneCollisionShape::headshot_hit() {
ERR_PRINT("zombie headshot hit"); ERR_PRINT("zombie headshot hit");
m_Crosshair->set_dot_color(Color(1,0,0,1)); m_Crosshair->set_dot_color(Color(1, 0, 0, 1));
emit_signal("a_ZombieHeadShotHit", m_HeadDamage); m_HitMarkers->hsvisible(true);
emit_signal("a_ZombieHeadShotHit", m_HeadDamage);
} }
void BoneCollisionShape::bodyshot_hit() { void BoneCollisionShape::bodyshot_hit() {
ERR_PRINT("zombie body 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); emit_signal("a_ZombieBodyShotHit", m_BodyDamage);
} }
} // namespace blitz } // namespace blitz

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "Crosshair.h" #include "Crosshair.h"
#include "HitMarkers.h"
#include <godot_cpp/classes/area3d.hpp> #include <godot_cpp/classes/area3d.hpp>
namespace blitz { namespace blitz {
@@ -27,6 +28,7 @@ class BoneCollisionShape : public godot::Area3D {
void set_body_damage(int d); void set_body_damage(int d);
int get_body_damage() const; int get_body_damage() const;
Crosshair* m_Crosshair; Crosshair* m_Crosshair;
HitMarkers* m_HitMarkers;
}; };
} // namespace blitz } // namespace blitz

View File

@@ -1,6 +1,8 @@
#include "Bullet.h" #include "Bullet.h"
#include "BoneCollisionShape.h" #include "BoneCollisionShape.h"
#include <godot_cpp/classes/engine.hpp>
using namespace godot; using namespace godot;
namespace blitz { namespace blitz {
@@ -25,8 +27,15 @@ void Bullet::_ready() {
m_Timer = memnew(Timer); m_Timer = memnew(Timer);
add_child(m_Timer); add_child(m_Timer);
m_Timer->connect("timeout", callable_mp(this, &Bullet::_on_timer_timeout)); m_Timer->connect("timeout", callable_mp(this, &Bullet::_on_timer_timeout));
#if DEBUG_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
#endif
m_Crosshair = Object::cast_to<Crosshair>(get_parent()->find_child("Crosshair")); m_Crosshair = Object::cast_to<Crosshair>(get_parent()->find_child("Crosshair"));
DEV_ASSERT(m_Crosshair); DEV_ASSERT(m_Crosshair);
m_HitMarkers = Object::cast_to<HitMarkers>(get_parent()->find_child("HitMarkers"));
DEV_ASSERT(m_HitMarkers);
} }
void Bullet::_physics_process(float a_Delta) { void Bullet::_physics_process(float a_Delta) {
@@ -56,6 +65,8 @@ void Bullet::_physics_process(float a_Delta) {
void Bullet::_on_timer_timeout() { void Bullet::_on_timer_timeout() {
m_Crosshair->set_dot_color(Color(1, 1, 1, 1)); m_Crosshair->set_dot_color(Color(1, 1, 1, 1));
m_HitMarkers->visible();
m_HitMarkers->hsvisible();
queue_free(); queue_free();
} }

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "Crosshair.h" #include "Crosshair.h"
#include "HitMarkers.h"
#include <godot_cpp/classes/gpu_particles3d.hpp> #include <godot_cpp/classes/gpu_particles3d.hpp>
#include <godot_cpp/classes/mesh_instance3d.hpp> #include <godot_cpp/classes/mesh_instance3d.hpp>
#include <godot_cpp/classes/node3d.hpp> #include <godot_cpp/classes/node3d.hpp>
@@ -26,6 +27,7 @@ class Bullet : public godot::Node3D {
godot::MeshInstance3D* m_Mesh; godot::MeshInstance3D* m_Mesh;
godot::Timer* m_Timer; godot::Timer* m_Timer;
Crosshair* m_Crosshair; Crosshair* m_Crosshair;
HitMarkers* m_HitMarkers;
void _on_timer_timeout(); void _on_timer_timeout();
}; };

View File

@@ -15,8 +15,19 @@ Crosshair::Crosshair() :
Crosshair::~Crosshair() {} Crosshair::~Crosshair() {}
void Crosshair::_ready() { void Crosshair::_ready() {
m_Player = Object::cast_to<FirstPersonPlayer>(get_parent()->get_parent()->get_parent()->find_child("FirstPersonPlayer")); // Catch the parent node directly without SubViewport problem in the editor thx to "recursivity" (if we go up the tree one more
DEV_ASSERT(m_Player); // notch its bugging)
Node* root_node = get_parent();
while (root_node != nullptr && !root_node->is_class("FirstPersonPlayer")) {
root_node = root_node->get_parent();
}
if (root_node != nullptr && root_node->is_class("FirstPersonPlayer")) {
m_Player = Object::cast_to<FirstPersonPlayer>(root_node);
DEV_ASSERT(m_Player);
} else {
ERR_PRINT("FirstPersonPlayer not found in parent hierarchy.");
}
m_CrosshairLines = {Object::cast_to<Line2D>(find_child("Top")), Object::cast_to<Line2D>(find_child("Right")), m_CrosshairLines = {Object::cast_to<Line2D>(find_child("Top")), Object::cast_to<Line2D>(find_child("Right")),
Object::cast_to<Line2D>(find_child("Bottom")), Object::cast_to<Line2D>(find_child("Left"))}; Object::cast_to<Line2D>(find_child("Bottom")), Object::cast_to<Line2D>(find_child("Left"))};
for (size_t i = 0; i < m_CrosshairLines.size(); i++) { for (size_t i = 0; i < m_CrosshairLines.size(); i++) {
@@ -30,7 +41,7 @@ void Crosshair::_process(float a_Delta) {
} }
void Crosshair::_draw() { void Crosshair::_draw() {
draw_circle(Vector2(0, 0), m_DotRadius, m_DotColor); draw_circle(Vector2(20, 20), m_DotRadius, m_DotColor);
} }
void Crosshair::adjust_crosshair_lines() { void Crosshair::adjust_crosshair_lines() {

37
src/HitMarkers.cpp Normal file
View File

@@ -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<Line2D>(find_child("TopRight")), Object::cast_to<Line2D>(find_child("BottomRight")),
Object::cast_to<Line2D>(find_child("BottomLeft")), Object::cast_to<Line2D>(find_child("TopLeft"))};
for (size_t i = 0; i < m_HitMarkerLines.size(); i++) {
DEV_ASSERT(m_HitMarkerLines[i]);
}
m_HitMarkerHSLines = {Object::cast_to<Line2D>(find_child("TopRightHS")), Object::cast_to<Line2D>(find_child("BottomRightHS")),
Object::cast_to<Line2D>(find_child("BottomLeftHS")), Object::cast_to<Line2D>(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

25
src/HitMarkers.h Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <godot_cpp/classes/center_container.hpp>
#include <godot_cpp/classes/line2d.hpp>
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<godot::Line2D*, 4> m_HitMarkerLines;
std::array<godot::Line2D*, 4> m_HitMarkerHSLines;
};
} // namespace blitz

View File

@@ -2,12 +2,13 @@
#include "BoneCollisionShape.h" #include "BoneCollisionShape.h"
#include "Bullet.h" #include "Bullet.h"
#include "Crosshair.h"
#include "FirstPersonPlayer.h" #include "FirstPersonPlayer.h"
#include "HitMarkers.h"
#include "Player.h" #include "Player.h"
#include "SpringArmPivot.h" #include "SpringArmPivot.h"
#include "World.h" #include "World.h"
#include "Zombie.h" #include "Zombie.h"
#include "Crosshair.h"
#include <gdextension_interface.h> #include <gdextension_interface.h>
#include <godot_cpp/core/defs.hpp> #include <godot_cpp/core/defs.hpp>
@@ -28,6 +29,7 @@ void initialize_example_module(ModuleInitializationLevel p_level) {
ClassDB::register_class<blitz::BoneCollisionShape>(); ClassDB::register_class<blitz::BoneCollisionShape>();
ClassDB::register_class<blitz::World>(); ClassDB::register_class<blitz::World>();
ClassDB::register_class<blitz::Crosshair>(); ClassDB::register_class<blitz::Crosshair>();
ClassDB::register_class<blitz::HitMarkers>();
} }
void uninitialize_example_module(ModuleInitializationLevel p_level) { void uninitialize_example_module(ModuleInitializationLevel p_level) {