generated from Persson-dev/Godot-Xmake
Add Hitmarkers
This commit is contained in:
@@ -35,7 +35,6 @@ grow_vertical = 2
|
|||||||
mouse_filter = 1
|
mouse_filter = 1
|
||||||
|
|
||||||
[node name="Crosshair" type="Crosshair" parent="UserInterface"]
|
[node name="Crosshair" type="Crosshair" parent="UserInterface"]
|
||||||
layout_direction = 1
|
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 8
|
anchors_preset = 8
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
@@ -64,3 +63,61 @@ width = 2.0
|
|||||||
[node name="Left" type="Line2D" parent="UserInterface/Crosshair"]
|
[node name="Left" type="Line2D" parent="UserInterface/Crosshair"]
|
||||||
points = PackedVector2Array(15, 20, 5, 20)
|
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)
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ void BoneCollisionShape::_ready() {
|
|||||||
m_Crosshair = Object::cast_to<Crosshair>(
|
m_Crosshair = Object::cast_to<Crosshair>(
|
||||||
get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->find_child("Crosshair"));
|
get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->get_parent()->find_child("Crosshair"));
|
||||||
DEV_ASSERT(m_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) {
|
||||||
@@ -56,12 +59,13 @@ int BoneCollisionShape::get_body_damage() const {
|
|||||||
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));
|
||||||
|
m_HitMarkers->hsvisible(true);
|
||||||
emit_signal("a_ZombieHeadShotHit", m_HeadDamage);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -34,6 +34,8 @@ void Bullet::_ready() {
|
|||||||
#endif
|
#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) {
|
||||||
@@ -63,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
};
|
};
|
||||||
|
|||||||
37
src/HitMarkers.cpp
Normal file
37
src/HitMarkers.cpp
Normal 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
25
src/HitMarkers.h
Normal 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
|
||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user