generated from Persson-dev/Godot-Xmake
Compare commits
2 Commits
1f52eb2c52
...
5c6f82c5d7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c6f82c5d7 | ||
|
|
faf6a9116d |
File diff suppressed because one or more lines are too long
@@ -1,10 +1,9 @@
|
||||
[gd_scene load_steps=20 format=3 uid="uid://coue2qehpn4fr"]
|
||||
[gd_scene load_steps=19 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://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://di3uyny341483" path="res://Assets/Textures/Green.png" id="4_wp15n"]
|
||||
[ext_resource type="PackedScene" uid="uid://bjuf33f7oteit" 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"]
|
||||
|
||||
[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_6c4vd"]
|
||||
@@ -108,9 +107,31 @@ collision_mask = 3
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Map/NavigationRegion3D/Slope/StaticBody3D"]
|
||||
shape = SubResource("ConcavePolygonShape3D_rit6o")
|
||||
|
||||
[node name="zombie" parent="Map" instance=ExtResource("5_4vmh3")]
|
||||
m_PlayerPath = NodePath("../../FirstPersonPlayer")
|
||||
transform = Transform3D(-0.98774, 0, -0.156107, 0, 1, 0, 0.156107, 0, -0.98774, 14.3905, 0, -18.3684)
|
||||
[node name="Spawns" type="Node3D" parent="Map"]
|
||||
|
||||
[node name="Spawn1" type="Node3D" parent="Map/Spawns"]
|
||||
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")]
|
||||
|
||||
@@ -128,3 +149,7 @@ 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
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include "World.h"
|
||||
#include "FirstPersonPlayer.h"
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/classes/resource_loader.hpp>
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
@@ -10,6 +11,7 @@ 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() {}
|
||||
@@ -27,6 +29,20 @@ void World::_ready() {
|
||||
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() {
|
||||
@@ -45,4 +61,27 @@ 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
|
||||
15
src/World.h
15
src/World.h
@@ -1,7 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <godot_cpp/classes/node3d.hpp>
|
||||
#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 {
|
||||
@@ -21,7 +25,16 @@ class World : public godot::Node3D {
|
||||
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
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "Zombie.h"
|
||||
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/classes/scene_tree.hpp>
|
||||
#include <godot_cpp/classes/window.hpp>
|
||||
#include <godot_cpp/core/math.hpp>
|
||||
|
||||
using namespace godot;
|
||||
@@ -16,6 +18,7 @@ void Zombie::_bind_methods() {
|
||||
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");
|
||||
}
|
||||
@@ -31,8 +34,13 @@ void Zombie::_ready() {
|
||||
}
|
||||
#endif
|
||||
|
||||
m_Player = Object::cast_to<FirstPersonPlayer>(get_parent()->get_parent()->find_child("FirstPersonPlayer"));
|
||||
DEV_ASSERT(m_Player);
|
||||
godot::Node* scene_root = Object::cast_to<godot::Node>(get_tree()->get_root()->get_child(0));
|
||||
if (scene_root) {
|
||||
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"));
|
||||
DEV_ASSERT(m_NavigationAgent);
|
||||
m_AnimationTree = Object::cast_to<AnimationTree>(find_child("AnimationTree"));
|
||||
@@ -44,6 +52,9 @@ void Zombie::_ready() {
|
||||
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) {
|
||||
@@ -92,7 +103,10 @@ void Zombie::hit_finished() {
|
||||
void Zombie::apply_damage(int dam) {
|
||||
m_Health -= dam;
|
||||
if (m_Health <= 0) {
|
||||
queue_free();
|
||||
m_AnimationTree->set("parameters/conditions/die", true);
|
||||
this->set_velocity(Vector3(0, 0, 0));
|
||||
m_Timer->set_wait_time(4.0);
|
||||
m_Timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,4 +127,8 @@ void Zombie::connect_collision_shapes(const std::vector<StringName>& body_parts)
|
||||
}
|
||||
}
|
||||
|
||||
void Zombie::_on_timer_timeout() {
|
||||
queue_free();
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <godot_cpp/classes/navigation_agent3d.hpp>
|
||||
#include <godot_cpp/variant/node_path.hpp>
|
||||
#include <godot_cpp/variant/string_name.hpp>
|
||||
#include <godot_cpp/classes/timer.hpp>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
@@ -37,12 +38,14 @@ class Zombie : public godot::CharacterBody3D {
|
||||
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);
|
||||
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
|
||||
Reference in New Issue
Block a user