1 Commits
weapon ... caca

Author SHA1 Message Date
Morph01
4fd60e7874 bug animation ??? 2024-08-16 14:19:29 +02:00
21 changed files with 116 additions and 1763 deletions

View File

@@ -24,100 +24,3 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1, 0)
[node name="Steampunk Rifle" parent="Head/Camera" instance=ExtResource("1_i6keg")] [node name="Steampunk Rifle" parent="Head/Camera" instance=ExtResource("1_i6keg")]
transform = Transform3D(1, 0, 0, 0, 0.998135, -0.0610485, 0, 0.0610485, 0.998135, 0.19, -0.18, -0.55) transform = Transform3D(1, 0, 0, 0, 0.998135, -0.0610485, 0, 0.0610485, 0.998135, 0.19, -0.18, -0.55)
[node name="UserInterface" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 1
[node name="Crosshair" type="Crosshair" 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="Top" type="Line2D" parent="UserInterface/Crosshair"]
points = PackedVector2Array(20, 15, 20, 5)
width = 2.0
[node name="Right" type="Line2D" parent="UserInterface/Crosshair"]
points = PackedVector2Array(25, 20, 35, 20)
width = 2.0
[node name="Bottom" type="Line2D" parent="UserInterface/Crosshair"]
points = PackedVector2Array(20, 25, 20, 35)
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)

View File

@@ -3771,6 +3771,6 @@ callback_mode_process = 0
tree_root = SubResource("AnimationNodeBlendTree_dptuf") tree_root = SubResource("AnimationNodeBlendTree_dptuf")
anim_player = NodePath("../AnimationPlayer") anim_player = NodePath("../AnimationPlayer")
parameters/ground_air_transition/current_state = "air" parameters/ground_air_transition/current_state = "air"
parameters/ground_air_transition/transition_request = "air" parameters/ground_air_transition/transition_request = ""
parameters/ground_air_transition/current_index = 1 parameters/ground_air_transition/current_index = 1
parameters/iwr_blend/blend_amount = -1.0 parameters/iwr_blend/blend_amount = -1.0

File diff suppressed because one or more lines are too long

View File

@@ -1,9 +1,10 @@
[gd_scene load_steps=19 format=3 uid="uid://coue2qehpn4fr"] [gd_scene load_steps=20 format=3 uid="uid://coue2qehpn4fr"]
[ext_resource type="Texture2D" uid="uid://dujfl12rge3p4" path="res://Assets/Textures/Sky.png" id="1_mnexj"] [ext_resource type="Texture2D" uid="uid://dujfl12rge3p4" path="res://Assets/Textures/Sky.png" id="1_mnexj"]
[ext_resource type="Texture2D" uid="uid://b8n5rff2a8h2u" path="res://Assets/Textures/Black.png" id="2_fkwcn"] [ext_resource type="Texture2D" uid="uid://b8n5rff2a8h2u" path="res://Assets/Textures/Black.png" id="2_fkwcn"]
[ext_resource type="Texture2D" uid="uid://lpbttkw7gpxj" path="res://Assets/Textures/Orange.png" id="3_ux02w"] [ext_resource type="Texture2D" uid="uid://lpbttkw7gpxj" path="res://Assets/Textures/Orange.png" id="3_ux02w"]
[ext_resource type="Texture2D" uid="uid://di3uyny341483" path="res://Assets/Textures/Green.png" id="4_wp15n"] [ext_resource type="Texture2D" uid="uid://di3uyny341483" path="res://Assets/Textures/Green.png" id="4_wp15n"]
[ext_resource type="PackedScene" uid="uid://bcawyy7lmwphr" path="res://Scenes/Characters/zombie.tscn" id="5_4vmh3"]
[ext_resource type="PackedScene" uid="uid://d38w4ae3qj0k4" path="res://Scenes/Characters/first_person_player.tscn" id="5_8ctht"] [ext_resource type="PackedScene" uid="uid://d38w4ae3qj0k4" path="res://Scenes/Characters/first_person_player.tscn" id="5_8ctht"]
[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_6c4vd"] [sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_6c4vd"]
@@ -57,7 +58,7 @@ uv1_triplanar = true
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_rit6o"] [sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_rit6o"]
data = PackedVector3Array(-12.5, 2.5, 2.5, 2.5, -2.5, 2.5, -2.5, -2.5, 2.5, -12.5, 2.5, -2.5, -2.5, -2.5, -2.5, 2.5, -2.5, -2.5, -12.5, 2.5, 2.5, -12.5, 2.5, -2.5, 2.5, -2.5, 2.5, -12.5, 2.5, -2.5, 2.5, -2.5, -2.5, 2.5, -2.5, 2.5, -12.5, 2.5, -2.5, -12.5, 2.5, 2.5, -2.5, -2.5, -2.5, -12.5, 2.5, 2.5, -2.5, -2.5, 2.5, -2.5, -2.5, -2.5, -2.5, -2.5, 2.5, 2.5, -2.5, 2.5, -2.5, -2.5, -2.5, 2.5, -2.5, 2.5, 2.5, -2.5, -2.5, -2.5, -2.5, -2.5) data = PackedVector3Array(-12.5, 2.5, 2.5, 2.5, -2.5, 2.5, -2.5, -2.5, 2.5, -12.5, 2.5, -2.5, -2.5, -2.5, -2.5, 2.5, -2.5, -2.5, -12.5, 2.5, 2.5, -12.5, 2.5, -2.5, 2.5, -2.5, 2.5, -12.5, 2.5, -2.5, 2.5, -2.5, -2.5, 2.5, -2.5, 2.5, -12.5, 2.5, -2.5, -12.5, 2.5, 2.5, -2.5, -2.5, -2.5, -12.5, 2.5, 2.5, -2.5, -2.5, 2.5, -2.5, -2.5, -2.5, -2.5, -2.5, 2.5, 2.5, -2.5, 2.5, -2.5, -2.5, -2.5, 2.5, -2.5, 2.5, 2.5, -2.5, -2.5, -2.5, -2.5, -2.5)
[node name="World" type="World"] [node name="World" type="Node3D"]
[node name="Map" type="Node3D" parent="."] [node name="Map" type="Node3D" parent="."]
@@ -76,8 +77,6 @@ mesh = SubResource("PlaneMesh_mmup0")
skeleton = NodePath("../../..") skeleton = NodePath("../../..")
[node name="StaticBody3D" type="StaticBody3D" parent="Map/NavigationRegion3D/Floor"] [node name="StaticBody3D" type="StaticBody3D" parent="Map/NavigationRegion3D/Floor"]
collision_layer = 3
collision_mask = 3
[node name="CollisionShape3D" type="CollisionShape3D" parent="Map/NavigationRegion3D/Floor/StaticBody3D"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Map/NavigationRegion3D/Floor/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_26ptr") shape = SubResource("ConcavePolygonShape3D_26ptr")
@@ -88,8 +87,6 @@ mesh = SubResource("BoxMesh_plpqy")
skeleton = NodePath("../../..") skeleton = NodePath("../../..")
[node name="StaticBody3D" type="StaticBody3D" parent="Map/NavigationRegion3D/Wall"] [node name="StaticBody3D" type="StaticBody3D" parent="Map/NavigationRegion3D/Wall"]
collision_layer = 3
collision_mask = 3
[node name="CollisionShape3D" type="CollisionShape3D" parent="Map/NavigationRegion3D/Wall/StaticBody3D"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Map/NavigationRegion3D/Wall/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_v7prx") shape = SubResource("ConcavePolygonShape3D_v7prx")
@@ -101,55 +98,12 @@ skeleton = NodePath("../../..")
surface_material_override/0 = SubResource("StandardMaterial3D_pfpgv") surface_material_override/0 = SubResource("StandardMaterial3D_pfpgv")
[node name="StaticBody3D" type="StaticBody3D" parent="Map/NavigationRegion3D/Slope"] [node name="StaticBody3D" type="StaticBody3D" parent="Map/NavigationRegion3D/Slope"]
collision_layer = 3
collision_mask = 3
[node name="CollisionShape3D" type="CollisionShape3D" parent="Map/NavigationRegion3D/Slope/StaticBody3D"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Map/NavigationRegion3D/Slope/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_rit6o") shape = SubResource("ConcavePolygonShape3D_rit6o")
[node name="Spawns" type="Node3D" parent="Map"] [node name="zombie" parent="Map" instance=ExtResource("5_4vmh3")]
m_PlayerPath = NodePath("../../FirstPersonPlayer")
[node name="Spawn1" type="Node3D" parent="Map/Spawns"] transform = Transform3D(-0.98774, 0, -0.156107, 0, 1, 0, 0.156107, 0, -0.98774, 0, 0, 7.38477)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 18.6089)
[node name="Spawn2" type="Node3D" parent="Map/Spawns"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 18.8451, 0, 18.6089)
[node name="Spawn3" type="Node3D" parent="Map/Spawns"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 18.8451, 0, 0.0245247)
[node name="Spawn4" type="Node3D" parent="Map/Spawns"]
transform = Transform3D(-0.269021, -0.963134, 0, 0.963134, -0.269021, 0, 0, 0, 1, 19.0777, 0, -20.2546)
[node name="Spawn5" type="Node3D" parent="Map/Spawns"]
transform = Transform3D(-0.269021, -0.963134, 0, 0.963134, -0.269021, 0, 0, 0, 1, 1.64303, 0, -20.2546)
[node name="Spawn6" type="Node3D" parent="Map/Spawns"]
transform = Transform3D(-0.269021, -0.963134, 0, 0.963134, -0.269021, 0, 0, 0, 1, -19.0255, 0, -20.2546)
[node name="Spawn7" type="Node3D" parent="Map/Spawns"]
transform = Transform3D(-0.269021, -0.963134, 0, 0.963134, -0.269021, 0, 0, 0, 1, -19.0255, 0, 0.256641)
[node name="Spawn8" type="Node3D" parent="Map/Spawns"]
transform = Transform3D(-0.269021, -0.963134, 0, 0.963134, -0.269021, 0, 0, 0, 1, -19.0255, 0, 16.4132)
[node name="FirstPersonPlayer" parent="." instance=ExtResource("5_8ctht")] [node name="FirstPersonPlayer" parent="." instance=ExtResource("5_8ctht")]
[node name="UI" type="Control" parent="."]
layout_mode = 3
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
[node name="HitRect" type="ColorRect" parent="UI"]
visible = false
layout_mode = 0
offset_left = -177.0
offset_top = -96.0
offset_right = 1365.0
offset_bottom = 780.0
color = Color(1, 0, 0, 0.34902)
[node name="ZombieSpawnTimer" type="Timer" parent="."]
wait_time = 5.0
autostart = true

View File

@@ -25,17 +25,14 @@ material = SubResource("StandardMaterial3D_gn2fy")
size = Vector3(0.04, 0.04, 0.04) size = Vector3(0.04, 0.04, 0.04)
[node name="Bullet" type="Bullet"] [node name="Bullet" type="Bullet"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -56304.6) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -52730.2)
[node name="MeshInstance3D" type="MeshInstance3D" parent="."] [node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.6)
mesh = SubResource("BoxMesh_ibwn0") mesh = SubResource("BoxMesh_ibwn0")
surface_material_override/0 = SubResource("StandardMaterial3D_2qdhl") surface_material_override/0 = SubResource("StandardMaterial3D_2qdhl")
[node name="RayCast3D" type="RayCast3D" parent="."] [node name="RayCast3D" type="RayCast3D" parent="."]
target_position = Vector3(0, 0, -0.6) target_position = Vector3(0, 0, -0.6)
collision_mask = 2
collide_with_areas = true
[node name="GPUParticles3D" type="GPUParticles3D" parent="."] [node name="GPUParticles3D" type="GPUParticles3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.7) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.7)

View File

@@ -32,5 +32,5 @@ libraries = {
} }
[node name="RayCast3D" type="RayCast3D" parent="." index="2"] [node name="RayCast3D" type="RayCast3D" parent="." index="2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.6) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.10108)
target_position = Vector3(0, 0, -1) target_position = Vector3(0, 0, -1)

View File

@@ -1,72 +0,0 @@
#include "BoneCollisionShape.h"
#include <godot_cpp/classes/engine.hpp>
using namespace godot;
namespace blitz {
void BoneCollisionShape::_bind_methods() {
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);
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("set_body_damage", "m_BodyDamage"), &BoneCollisionShape::set_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_ZombieBodyShotHit", PropertyInfo(Variant::INT, "dam")));
ClassDB::bind_method(D_METHOD("headshot_hit"), &BoneCollisionShape::headshot_hit);
ClassDB::bind_method(D_METHOD("bodyshot_hit"), &BoneCollisionShape::bodyshot_hit);
}
BoneCollisionShape::BoneCollisionShape() {}
BoneCollisionShape::~BoneCollisionShape() {}
void BoneCollisionShape::_ready() {
#if DEBUG_ENABLED
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) {
m_HeadDamage = a_D;
}
int BoneCollisionShape::get_head_damage() const {
return m_HeadDamage;
}
void BoneCollisionShape::set_body_damage(int a_D) {
m_BodyDamage = a_D;
}
int BoneCollisionShape::get_body_damage() const {
return m_BodyDamage;
}
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_HitMarkers->visible(true);
emit_signal("a_ZombieBodyShotHit", m_BodyDamage);
}
} // namespace blitz

View File

@@ -1,34 +0,0 @@
#pragma once
#include "Crosshair.h"
#include "HitMarkers.h"
#include <godot_cpp/classes/area3d.hpp>
namespace blitz {
class BoneCollisionShape : public godot::Area3D {
GDCLASS(BoneCollisionShape, godot::Area3D)
protected:
static void _bind_methods();
public:
BoneCollisionShape();
~BoneCollisionShape();
void _ready();
void headshot_hit();
void bodyshot_hit();
private:
int m_HeadDamage = 2;
int m_BodyDamage = 1;
void set_head_damage(int d);
int get_head_damage() const;
void set_body_damage(int d);
int get_body_damage() const;
Crosshair* m_Crosshair;
HitMarkers* m_HitMarkers;
};
} // namespace blitz

View File

@@ -1,7 +1,4 @@
#include "Bullet.h" #include "Bullet.h"
#include "BoneCollisionShape.h"
#include <godot_cpp/classes/engine.hpp>
using namespace godot; using namespace godot;
@@ -24,18 +21,9 @@ void Bullet::_ready() {
DEV_ASSERT(m_Ray); DEV_ASSERT(m_Ray);
m_Mesh = Object::cast_to<MeshInstance3D>(find_child("MeshInstance3D")); m_Mesh = Object::cast_to<MeshInstance3D>(find_child("MeshInstance3D"));
DEV_ASSERT(m_Mesh); DEV_ASSERT(m_Mesh);
m_Timer = memnew(Timer); m_Timer = memnew(godot::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"));
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) {
@@ -45,28 +33,12 @@ void Bullet::_physics_process(float a_Delta) {
if (m_Ray->is_colliding()) { if (m_Ray->is_colliding()) {
m_Mesh->set_visible(false); m_Mesh->set_visible(false);
m_Particles->set_emitting(true); m_Particles->set_emitting(true);
m_Ray->set_enabled(false);
Object* collider = m_Ray->get_collider();
if (!collider)
return;
auto* area_collider = Object::cast_to<BoneCollisionShape>(collider);
if (!(area_collider && area_collider->is_in_group("enemy")))
return;
const StringName& area_name = area_collider->get_name();
area_collider->call(area_name.match("HeadArea3D") ? "headshot_hit" : "bodyshot_hit");
m_Timer->set_wait_time(1.0); m_Timer->set_wait_time(1.0);
m_Timer->start(); m_Timer->start();
} }
} }
void Bullet::_on_timer_timeout() { void Bullet::_on_timer_timeout() {
m_Crosshair->set_dot_color(Color(1, 1, 1, 1));
m_HitMarkers->visible();
m_HitMarkers->hsvisible();
queue_free(); queue_free();
} }

View File

@@ -1,7 +1,5 @@
#pragma once #pragma once
#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,8 +24,6 @@ class Bullet : public godot::Node3D {
godot::RayCast3D* m_Ray; godot::RayCast3D* m_Ray;
godot::MeshInstance3D* m_Mesh; godot::MeshInstance3D* m_Mesh;
godot::Timer* m_Timer; godot::Timer* m_Timer;
Crosshair* m_Crosshair;
HitMarkers* m_HitMarkers;
void _on_timer_timeout(); void _on_timer_timeout();
}; };

View File

@@ -1,70 +0,0 @@
#include "Crosshair.h"
using namespace godot;
namespace blitz {
void Crosshair::_bind_methods() {}
Crosshair::Crosshair() :
m_DotRadius(1.0f),
m_DotColor(Color(1, 1, 1, 1)),
m_CrosshairSpeed(0.25f),
m_CrosshairDistance(2.0f),
m_Origin(Vector3(0, 0, 0)),
m_Pos(Vector2(0, 0)) {}
Crosshair::~Crosshair() {}
void Crosshair::_ready() {
// Catch the parent node directly without SubViewport problem in the editor thx to "recursivity" (if we go up the tree one more
// 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")),
Object::cast_to<Line2D>(find_child("Bottom")), Object::cast_to<Line2D>(find_child("Left"))};
for (size_t i = 0; i < m_CrosshairLines.size(); i++) {
DEV_ASSERT(m_CrosshairLines[i]);
}
queue_redraw();
}
void Crosshair::_process(float a_Delta) {
adjust_crosshair_lines();
}
void Crosshair::_draw() {
draw_circle(Vector2(20, 20), m_DotRadius, m_DotColor);
}
void Crosshair::adjust_crosshair_lines() {
Vector3 vel = m_Player->get_real_velocity();
float speed = m_Origin.distance_to(vel);
m_CrosshairLines[0]->set_position(
m_CrosshairLines[0]->get_position().lerp(m_Pos + Vector2(0, -speed * m_CrosshairDistance), m_CrosshairSpeed));
m_CrosshairLines[1]->set_position(
m_CrosshairLines[1]->get_position().lerp(m_Pos + Vector2(speed * m_CrosshairDistance, 0), m_CrosshairSpeed));
m_CrosshairLines[2]->set_position(
m_CrosshairLines[2]->get_position().lerp(m_Pos + Vector2(0, speed * m_CrosshairDistance), m_CrosshairSpeed));
m_CrosshairLines[3]->set_position(
m_CrosshairLines[3]->get_position().lerp(m_Pos + Vector2(-speed * m_CrosshairDistance, 0), m_CrosshairSpeed));
}
void Crosshair::set_dot_color(Color a_Color) {
m_DotColor = a_Color;
queue_redraw();
}
} // namespace blitz

View File

@@ -1,35 +0,0 @@
#pragma once
#include "FirstPersonPlayer.h"
#include <godot_cpp/classes/center_container.hpp>
#include <godot_cpp/classes/line2d.hpp>
namespace blitz {
class Crosshair : public godot::CenterContainer {
GDCLASS(Crosshair, godot::CenterContainer)
protected:
static void _bind_methods();
public:
Crosshair();
~Crosshair();
void _ready();
void _process(float delta);
void _draw();
void set_dot_color(godot::Color col);
private:
godot::Color m_DotColor;
float m_DotRadius;
std::array<godot::Line2D*, 4> m_CrosshairLines;
FirstPersonPlayer* m_Player;
float m_CrosshairSpeed;
float m_CrosshairDistance;
godot::Vector3 m_Origin;
godot::Vector2 m_Pos;
void adjust_crosshair_lines();
};
} // namespace blitz

View File

@@ -6,7 +6,6 @@
#include <godot_cpp/classes/input_map.hpp> #include <godot_cpp/classes/input_map.hpp>
#include <godot_cpp/classes/resource_loader.hpp> #include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/core/math.hpp> #include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/signal.hpp>
using namespace godot; using namespace godot;
@@ -21,8 +20,6 @@ static constexpr float GRAVITY = 9.81f;
static constexpr float SENSITIVITY = 0.003f; static constexpr float SENSITIVITY = 0.003f;
static constexpr float HIT_STAGGER = 8.0f;
static constexpr float BOB_FREQ = 2.0f; static constexpr float BOB_FREQ = 2.0f;
static constexpr float BOB_AMP = 0.08f; static constexpr float BOB_AMP = 0.08f;
@@ -37,9 +34,7 @@ static constexpr float MIN_FOV_VELOCITY = 0.5;
static constexpr float MAX_FOV_VELOCITY = SPRINT_SPEED * 2.0f; static constexpr float MAX_FOV_VELOCITY = SPRINT_SPEED * 2.0f;
void FirstPersonPlayer::_bind_methods() { void FirstPersonPlayer::_bind_methods() {}
ADD_SIGNAL(MethodInfo("a_PlayerHit"));
}
FirstPersonPlayer::FirstPersonPlayer() : m_BobTime(0) {} FirstPersonPlayer::FirstPersonPlayer() : m_BobTime(0) {}
@@ -161,9 +156,4 @@ void FirstPersonPlayer::UpdateFOV(float a_Delta) {
m_Camera->set_fov(Math::lerp(m_Camera->get_fov(), targetFOV, a_Delta * FOV_TRANSITION)); m_Camera->set_fov(Math::lerp(m_Camera->get_fov(), targetFOV, a_Delta * FOV_TRANSITION));
} }
void FirstPersonPlayer::hit(Vector3 a_Dir) {
emit_signal("a_PlayerHit");
this->set_velocity(a_Dir * HIT_STAGGER);
}
} // namespace blitz } // namespace blitz

View File

@@ -24,7 +24,6 @@ class FirstPersonPlayer : public godot::CharacterBody3D {
void _unhandled_input(const godot::Ref<godot::InputEvent>&); void _unhandled_input(const godot::Ref<godot::InputEvent>&);
void _physics_process(float delta); void _physics_process(float delta);
void _ready(); void _ready();
void hit(godot::Vector3 dir);
private: private:
godot::Camera3D* m_Camera; godot::Camera3D* m_Camera;
@@ -40,7 +39,6 @@ class FirstPersonPlayer : public godot::CharacterBody3D {
void UpdateFOV(float delta); void UpdateFOV(float delta);
void UpdateCamera(const godot::InputEventMouseMotion&); void UpdateCamera(const godot::InputEventMouseMotion&);
void UpdatePosition(float delta); void UpdatePosition(float delta);
}; };
} // namespace blitz } // namespace blitz

View File

@@ -1,37 +0,0 @@
#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

View File

@@ -1,25 +0,0 @@
#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

@@ -1,87 +0,0 @@
#include "World.h"
#include "FirstPersonPlayer.h"
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
using namespace godot;
namespace blitz {
void World::_bind_methods() {
ClassDB::bind_method(D_METHOD("_on_first_person_player_hit"), &World::_on_first_person_player_hit);
ClassDB::bind_method(D_METHOD("_on_timer_timeout"), &World::_on_timer_timeout);
ClassDB::bind_method(D_METHOD("_on_zombie_spawn_timer_timeout"), &World::_on_zombie_spawn_timer_timeout);
}
World::World() {}
World::~World() {}
void World::_ready() {
FirstPersonPlayer* player = Object::cast_to<FirstPersonPlayer>(find_child("FirstPersonPlayer"));
DEV_ASSERT(player);
if (player) {
player->connect("a_PlayerHit", callable_mp(this, &World::_on_first_person_player_hit));
}
m_RedRect = Object::cast_to<ColorRect>(find_child("HitRect"));
DEV_ASSERT(m_RedRect);
m_Timer = memnew(Timer);
add_child(m_Timer);
m_Timer->connect("timeout", callable_mp(this, &World::_on_timer_timeout));
m_ZombieSpawnTimer = memnew(Timer);
add_child(m_ZombieSpawnTimer);
m_ZombieSpawnTimer->connect("timeout", callable_mp(this, &World::_on_zombie_spawn_timer_timeout));
m_Spawns = Object::cast_to<Node3D>(find_child("Spawns"));
DEV_ASSERT(m_Spawns);
m_NavigationRegion = Object::cast_to<NavigationRegion3D>(find_child("NavigationRegion3D"));
DEV_ASSERT(m_NavigationRegion);
m_ZombieScene = ResourceLoader::get_singleton()->load("res://Scenes/Characters/zombie.tscn");
if (!m_ZombieScene.is_valid()) {
ERR_PRINT("Failed to load zombie scene.");
}
m_RandomId.instantiate();
m_RandomId->randomize();
m_ZombieSpawnTimer->start();
}
void World::_on_first_person_player_hit() {
#if DEBUG_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
#endif
UtilityFunctions::print("Player hit detected in World.");
m_RedRect->set_visible(true);
m_Timer->set_wait_time(0.2);
m_Timer->start();
}
void World::_on_timer_timeout() {
m_RedRect->set_visible(false);
}
Node* World::get_random_child(Node* a_ParentNode) {
m_ZombieSpawnTimer->set_wait_time(4.0);
if (!a_ParentNode || a_ParentNode->get_child_count() == 0) {
return nullptr;
}
int32_t id = m_RandomId->randi() % a_ParentNode->get_child_count();
return a_ParentNode->get_child(id);
}
void World::_on_zombie_spawn_timer_timeout() {
#if DEBUG_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
#endif
auto spawns = Object::cast_to<Node3D>(World::get_random_child(m_Spawns));
auto spawn_points = spawns->get_global_position();
m_ZombieInstance = Object::cast_to<Zombie>(m_ZombieScene->instantiate());
DEV_ASSERT(m_ZombieInstance);
m_ZombieInstance->set_position(spawn_points);
m_NavigationRegion->add_child(m_ZombieInstance);
}
} // namespace blitz

View File

@@ -1,40 +0,0 @@
#pragma once
#include "Zombie.h"
#include <godot_cpp/classes/color_rect.hpp>
#include <godot_cpp/classes/navigation_region3d.hpp>
#include <godot_cpp/classes/packed_scene.hpp>
#include <godot_cpp/classes/random_number_generator.hpp>
#include <godot_cpp/classes/ref.hpp>
#include <godot_cpp/classes/timer.hpp>
namespace blitz {
class World : public godot::Node3D {
GDCLASS(World, godot::Node3D);
protected:
static void _bind_methods();
public:
World();
~World();
void _ready();
private:
godot::ColorRect* m_RedRect;
godot::Timer* m_Timer;
godot::Timer* m_ZombieSpawnTimer;
godot::Node3D* m_Spawns;
godot::NavigationRegion3D* m_NavigationRegion;
Zombie* m_ZombieInstance;
godot::Ref<godot::PackedScene> m_ZombieScene;
godot::Ref<godot::RandomNumberGenerator> m_RandomId;
void _on_timer_timeout();
void _on_zombie_spawn_timer_timeout();
void _on_first_person_player_hit();
Node* get_random_child(Node* parent_node);
};
} // namespace blitz

View File

@@ -1,24 +1,18 @@
#include "Zombie.h" #include "Zombie.h"
#include <godot_cpp/classes/engine.hpp> #include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/scene_tree.hpp> #include <godot_cpp/variant/utility_functions.hpp>
#include <godot_cpp/classes/window.hpp>
#include <godot_cpp/core/math.hpp>
using namespace godot; using namespace godot;
namespace blitz { namespace blitz {
static constexpr float SPEED = 2.0f; static constexpr float SPEED = 2.0f;
static constexpr float ATTACK_RANGE = 2.0f;
void Zombie::_bind_methods() { void Zombie::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_m_PlayerPath", "m_PlayerPath"), &Zombie::set_m_PlayerPath); ClassDB::bind_method(D_METHOD("set_m_PlayerPath", "m_PlayerPath"), &Zombie::set_m_PlayerPath);
ClassDB::bind_method(D_METHOD("get_m_PlayerPath"), &Zombie::get_m_PlayerPath); ClassDB::bind_method(D_METHOD("get_m_PlayerPath"), &Zombie::get_m_PlayerPath);
ClassDB::bind_method(D_METHOD("hit_finished"), &Zombie::hit_finished);
ClassDB::bind_method(D_METHOD("_on_area_3d_a_zombie_head_shot_hit", "m_Health"), &Zombie::_on_area_3d_a_zombie_head_shot_hit);
ClassDB::bind_method(D_METHOD("_on_area_3d_a_zombie_body_shot_hit", "m_Health"), &Zombie::_on_area_3d_a_zombie_body_shot_hit);
ClassDB::bind_method(D_METHOD("_on_timer_timeout"), &Zombie::_on_timer_timeout);
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "m_PlayerPath"), "set_m_PlayerPath", "get_m_PlayerPath"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "m_PlayerPath"), "set_m_PlayerPath", "get_m_PlayerPath");
} }
@@ -34,27 +28,11 @@ void Zombie::_ready() {
} }
#endif #endif
godot::Node* scene_root = Object::cast_to<godot::Node>(get_tree()->get_root()->get_child(0)); m_Player = Object::cast_to<FirstPersonPlayer>(get_parent()->get_parent()->find_child("FirstPersonPlayer"));
if (scene_root) { DEV_ASSERT(m_Player);
m_Player = Object::cast_to<FirstPersonPlayer>(scene_root->find_child("FirstPersonPlayer", true));
DEV_ASSERT(m_Player);
} else {
ERR_PRINT("Scene root not found or invalid.");
}
m_NavigationAgent = Object::cast_to<NavigationAgent3D>(find_child("NavigationAgent3D")); m_NavigationAgent = Object::cast_to<NavigationAgent3D>(find_child("NavigationAgent3D"));
DEV_ASSERT(m_NavigationAgent); DEV_ASSERT(m_NavigationAgent);
m_AnimationTree = Object::cast_to<AnimationTree>(find_child("AnimationTree")); m_Velocity = Vector3(0, 0, 0);
DEV_ASSERT(m_AnimationTree);
m_StateMachine = Object::cast_to<AnimationNodeStateMachinePlayback>(m_AnimationTree->get("parameters/playback"));
DEV_ASSERT(m_StateMachine);
this->set_velocity(Vector3(0, 0, 0));
m_HeadCollision = Object::cast_to<BoneCollisionShape>(find_child("HeadArea3D"));
DEV_ASSERT(m_HeadCollision);
m_HeadCollision->connect("a_ZombieHeadShotHit", Callable(this, "_on_area_3d_a_zombie_head_shot_hit"));
connect_collision_shapes(m_BodyPartsCollision);
m_Timer = memnew(Timer);
add_child(m_Timer);
m_Timer->connect("timeout", callable_mp(this, &Zombie::_on_timer_timeout));
} }
void Zombie::_process(float a_Delta) { void Zombie::_process(float a_Delta) {
@@ -63,28 +41,15 @@ void Zombie::_process(float a_Delta) {
return; return;
} }
#endif #endif
if (m_StateMachine->get_current_node().match("Run")) { this->set_velocity(m_Velocity);
m_NavigationAgent->set_target_position(m_Player->get_global_position()); m_NavigationAgent->set_target_position(m_Player->get_global_position());
m_Velocity = (m_NavigationAgent->get_next_path_position() - this->get_global_position()).normalized() * SPEED; Vector3 next_nav_point = m_NavigationAgent->get_next_path_position();
this->set_velocity(m_Velocity); m_Velocity = (next_nav_point - get_global_position()).normalized() * SPEED;
look_at(Vector3(this->get_global_position().x + this->get_velocity().x, this->get_global_position().y, this->set_velocity(m_Velocity);
this->get_global_position().z + this->get_velocity().z)); look_at(Vector3(m_Player->get_global_position().x, get_global_position().y, m_Player->get_global_position().z), Vector3(0, 1, 0));
} else if (m_StateMachine->get_current_node().match("Attack")) {
this->set_velocity(Vector3(0, 0, 0));
look_at(Vector3(m_Player->get_global_position().x + this->get_velocity().x, this->get_global_position().y,
m_Player->get_global_position().z + this->get_velocity().z));
}
m_AnimationTree->set("parameters/conditions/run", !_target_in_range());
m_AnimationTree->set("parameters/conditions/attack", _target_in_range());
move_and_slide(); move_and_slide();
} }
bool Zombie::_target_in_range() {
return this->get_global_position().distance_to(m_Player->get_global_position()) < ATTACK_RANGE;
}
void Zombie::set_m_PlayerPath(const NodePath& path) { void Zombie::set_m_PlayerPath(const NodePath& path) {
m_PlayerPath = path; m_PlayerPath = path;
} }
@@ -92,43 +57,4 @@ void Zombie::set_m_PlayerPath(const NodePath& path) {
NodePath Zombie::get_m_PlayerPath() const { NodePath Zombie::get_m_PlayerPath() const {
return m_PlayerPath; return m_PlayerPath;
} }
void Zombie::hit_finished() {
if (this->get_global_position().distance_to(m_Player->get_global_position()) < (ATTACK_RANGE + 1.0)) {
Vector3 dir = this->get_global_position().direction_to(m_Player->get_global_position());
m_Player->hit(dir);
}
}
void Zombie::apply_damage(int dam) {
m_Health -= dam;
if (m_Health <= 0) {
m_AnimationTree->set("parameters/conditions/die", true);
this->set_velocity(Vector3(0, 0, 0));
m_Timer->set_wait_time(4.0);
m_Timer->start();
}
}
void Zombie::_on_area_3d_a_zombie_head_shot_hit(int dam) {
apply_damage(dam);
}
void Zombie::_on_area_3d_a_zombie_body_shot_hit(int dam) {
apply_damage(dam);
}
void Zombie::connect_collision_shapes(const std::vector<StringName>& body_parts) {
for (const StringName& part : body_parts) {
StringName area_name = String(part) + "Area3D";
BoneCollisionShape* collision_shape = Object::cast_to<BoneCollisionShape>(find_child(area_name));
DEV_ASSERT(collision_shape);
collision_shape->connect("a_ZombieBodyShotHit", Callable(this, "_on_area_3d_a_zombie_body_shot_hit"));
}
}
void Zombie::_on_timer_timeout() {
queue_free();
}
} // namespace blitz } // namespace blitz

View File

@@ -1,17 +1,12 @@
#pragma once #pragma once
#include "BoneCollisionShape.h"
#include "FirstPersonPlayer.h"
#include <godot_cpp/classes/animation_node_state_machine_playback.hpp>
#include <godot_cpp/classes/animation_tree.hpp>
#include <godot_cpp/classes/character_body3d.hpp> #include <godot_cpp/classes/character_body3d.hpp>
#include <godot_cpp/classes/navigation_agent3d.hpp> #include <godot_cpp/classes/navigation_agent3d.hpp>
#include <godot_cpp/variant/node_path.hpp> #include <godot_cpp/variant/node_path.hpp>
#include <godot_cpp/variant/string_name.hpp> #include "FirstPersonPlayer.h"
#include <godot_cpp/classes/timer.hpp>
namespace blitz { namespace blitz {
class Zombie : public godot::CharacterBody3D { class Zombie : public godot::CharacterBody3D {
GDCLASS(Zombie, godot::CharacterBody3D) GDCLASS(Zombie, godot::CharacterBody3D)
protected: protected:
@@ -23,29 +18,16 @@ class Zombie : public godot::CharacterBody3D {
void _ready(); void _ready();
void _process(float delta); void _process(float delta);
bool _target_in_range();
void _on_area_3d_a_zombie_head_shot_hit(int dam);
void _on_area_3d_a_zombie_body_shot_hit(int dam);
private: private:
godot::NavigationAgent3D* m_NavigationAgent; godot::NavigationAgent3D* m_NavigationAgent;
FirstPersonPlayer* m_Player; FirstPersonPlayer* m_Player;
godot::NodePath m_PlayerPath; godot::NodePath m_PlayerPath;
godot::Vector3 m_Velocity; godot::Vector3 m_Velocity;
godot::AnimationTree* m_AnimationTree;
godot::AnimationNodeStateMachinePlayback* m_StateMachine;
BoneCollisionShape* m_HeadCollision;
std::vector<godot::StringName> m_BodyPartsCollision = {"Neck", "Spine", "Hips", "LeftArm", "LeftForearm", "LeftHand", "RightArm",
"RightForearm", "RightHand", "LeftUpLeg", "RightUpLeg", "LeftLeg", "RightLeg", "LeftFoot", "RightFoot"};
int m_Health = 6;
godot::Timer* m_Timer;
void set_m_PlayerPath(const godot::NodePath& path); void set_m_PlayerPath(const godot::NodePath& path);
godot::NodePath get_m_PlayerPath() const; godot::NodePath get_m_PlayerPath() const;
void hit_finished();
void apply_damage(int dam);
void connect_collision_shapes(const std::vector<godot::StringName>& body_parts);
void _on_timer_timeout();
}; };
} // namespace blitz } // namespace blitz

View File

@@ -1,13 +1,9 @@
#include "register_types.h" #include "register_types.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 "Zombie.h" #include "Zombie.h"
#include <gdextension_interface.h> #include <gdextension_interface.h>
@@ -26,10 +22,6 @@ void initialize_example_module(ModuleInitializationLevel p_level) {
ClassDB::register_class<blitz::FirstPersonPlayer>(); ClassDB::register_class<blitz::FirstPersonPlayer>();
ClassDB::register_class<blitz::Bullet>(); ClassDB::register_class<blitz::Bullet>();
ClassDB::register_class<blitz::Zombie>(); ClassDB::register_class<blitz::Zombie>();
ClassDB::register_class<blitz::BoneCollisionShape>();
ClassDB::register_class<blitz::World>();
ClassDB::register_class<blitz::Crosshair>();
ClassDB::register_class<blitz::HitMarkers>();
} }
void uninitialize_example_module(ModuleInitializationLevel p_level) { void uninitialize_example_module(ModuleInitializationLevel p_level) {