generated from Persson-dev/Godot-Xmake
Compare commits
5 Commits
caca
...
4d02e8afbf
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d02e8afbf | |||
| 72d8d46017 | |||
| 960ce2a546 | |||
| eb8e3b0888 | |||
| d0028dd0f8 |
File diff suppressed because one or more lines are too long
41
godot/Scenes/Menus/mainmenu.tscn
Normal file
41
godot/Scenes/Menus/mainmenu.tscn
Normal file
@@ -0,0 +1,41 @@
|
||||
[gd_scene format=3 uid="uid://bqfqg7xwwlxd8"]
|
||||
|
||||
[node name="Main Menu" type="MainMenu"]
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
|
||||
[node name="Container" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -228.512
|
||||
offset_top = -89.5
|
||||
offset_right = 228.512
|
||||
offset_bottom = 89.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="JoinButton" type="Button" parent="Container"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 35
|
||||
text = "Join Game"
|
||||
|
||||
[node name="CreateButton" type="Button" parent="Container"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 35
|
||||
text = "Create Game"
|
||||
|
||||
[node name="QuitButton" type="Button" parent="Container"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 35
|
||||
text = "Quit"
|
||||
@@ -15,6 +15,11 @@ run/main_scene="res://Scenes/Levels/world.tscn"
|
||||
config/features=PackedStringArray("4.2", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=1920
|
||||
window/size/viewport_height=1080
|
||||
|
||||
[input]
|
||||
|
||||
move_left={
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <godot_cpp/classes/input_event_mouse_motion.hpp>
|
||||
#include <godot_cpp/classes/input_map.hpp>
|
||||
#include <godot_cpp/core/math.hpp>
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
@@ -32,6 +33,9 @@ static constexpr float FOV_TRANSITION = 8.0f;
|
||||
static constexpr float MIN_FOV_VELOCITY = 0.5;
|
||||
static constexpr float MAX_FOV_VELOCITY = SPRINT_SPEED * 2.0f;
|
||||
|
||||
static const float LerpValue = 0.10;
|
||||
static const float AnimationBlend = 7.0;
|
||||
|
||||
void FirstPersonPlayer::_bind_methods() {}
|
||||
|
||||
FirstPersonPlayer::FirstPersonPlayer() : m_BobTime(0) {}
|
||||
@@ -44,9 +48,9 @@ void FirstPersonPlayer::_ready() {
|
||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
|
||||
}
|
||||
m_Head = Object::cast_to<Node3D>(find_child("Head"));
|
||||
DEV_ASSERT(m_Head);
|
||||
m_Camera = Object::cast_to<Camera3D>(m_Head->find_child("Camera"));
|
||||
DEV_ASSERT(m_Camera);
|
||||
m_AnimationTree = Object::cast_to<AnimationTree>(find_child("AnimationTree"));
|
||||
m_Mesh = Object::cast_to<Node3D>(find_child("Mesh"));
|
||||
}
|
||||
|
||||
void FirstPersonPlayer::_unhandled_input(const godot::Ref<godot::InputEvent>& a_Event) {
|
||||
@@ -84,6 +88,8 @@ void FirstPersonPlayer::_physics_process(float a_Delta) {
|
||||
UpdateFOV(a_Delta);
|
||||
UpdateBobbing(a_Delta);
|
||||
|
||||
UpdateAnimation(a_Delta);
|
||||
|
||||
move_and_slide();
|
||||
}
|
||||
|
||||
@@ -98,10 +104,11 @@ void FirstPersonPlayer::UpdateBobbing(float a_Delta) {
|
||||
|
||||
void FirstPersonPlayer::UpdateCamera(const InputEventMouseMotion& a_Event) {
|
||||
m_Head->rotate_y(-a_Event.get_relative().x * SENSITIVITY);
|
||||
m_Mesh->rotate_y(-a_Event.get_relative().x * 0.005);
|
||||
m_Camera->rotate_x(-a_Event.get_relative().y * SENSITIVITY);
|
||||
|
||||
float rotationX = m_Camera->get_rotation().x;
|
||||
CLAMP(rotationX, Math::deg_to_rad(-40.0), Math::deg_to_rad(60.0));
|
||||
rotationX = CLAMP(rotationX, Math::deg_to_rad(-80.0), Math::deg_to_rad(80.0));
|
||||
m_Camera->set_rotation({rotationX, get_rotation().y, get_rotation().z});
|
||||
}
|
||||
|
||||
@@ -128,6 +135,14 @@ void FirstPersonPlayer::UpdatePosition(float delta) {
|
||||
Math::lerp(static_cast<float>(get_velocity().z), static_cast<float>(direction.z * m_Speed),
|
||||
static_cast<float>(delta * AIR_MOVEMENT))});
|
||||
}
|
||||
|
||||
|
||||
if (!direction.is_zero_approx()) {
|
||||
godot::Vector3 newRotation = m_Mesh->get_rotation();
|
||||
newRotation.y = godot::UtilityFunctions::lerp_angle(
|
||||
newRotation.y, godot::UtilityFunctions::atan2(get_velocity().x, get_velocity().z), LerpValue);
|
||||
m_Mesh->set_rotation(newRotation);
|
||||
}
|
||||
}
|
||||
|
||||
void FirstPersonPlayer::UpdateFOV(float a_Delta) {
|
||||
@@ -136,4 +151,25 @@ void FirstPersonPlayer::UpdateFOV(float a_Delta) {
|
||||
m_Camera->set_fov(Math::lerp(m_Camera->get_fov(), targetFOV, a_Delta * FOV_TRANSITION));
|
||||
}
|
||||
|
||||
void FirstPersonPlayer::UpdateAnimation(float delta) {
|
||||
if (is_on_floor()) {
|
||||
m_AnimationTree->set("parameters/ground_air_transition/transition_request", "grounded");
|
||||
|
||||
if (get_velocity().length() > 0.2f) {
|
||||
if (m_Speed == SPRINT_SPEED) {
|
||||
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
|
||||
UtilityFunctions::lerp(m_AnimationTree->get("parameters/iwr_blend/blend_amount"), 1.0, delta * AnimationBlend));
|
||||
} else {
|
||||
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
|
||||
UtilityFunctions::lerp(m_AnimationTree->get("parameters/iwr_blend/blend_amount"), 0.0, delta * AnimationBlend));
|
||||
}
|
||||
} else {
|
||||
m_AnimationTree->set("parameters/iwr_blend/blend_amount",
|
||||
UtilityFunctions::lerp(m_AnimationTree->get("parameters/iwr_blend/blend_amount"), -1.0, delta * AnimationBlend));
|
||||
}
|
||||
} else {
|
||||
m_AnimationTree->set("parameters/ground_air_transition/transition_request", "air");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <godot_cpp/classes/animation_tree.hpp>
|
||||
#include <godot_cpp/classes/camera3d.hpp>
|
||||
#include <godot_cpp/classes/character_body3d.hpp>
|
||||
#include <godot_cpp/classes/input_event_mouse_motion.hpp>
|
||||
@@ -22,8 +23,10 @@ class FirstPersonPlayer : public godot::CharacterBody3D {
|
||||
void _ready();
|
||||
|
||||
private:
|
||||
godot::AnimationTree* m_AnimationTree;
|
||||
godot::Camera3D* m_Camera;
|
||||
godot::Node3D* m_Head;
|
||||
godot::Node3D* m_Mesh;
|
||||
float m_BobTime;
|
||||
float m_Speed;
|
||||
|
||||
@@ -31,6 +34,8 @@ class FirstPersonPlayer : public godot::CharacterBody3D {
|
||||
void UpdateFOV(float delta);
|
||||
void UpdateCamera(const godot::InputEventMouseMotion&);
|
||||
void UpdatePosition(float delta);
|
||||
|
||||
void UpdateAnimation(float delta);
|
||||
};
|
||||
|
||||
} // namespace blitz
|
||||
47
src/MainMenu.cpp
Normal file
47
src/MainMenu.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "MainMenu.h"
|
||||
|
||||
#include <godot_cpp/classes/resource_loader.hpp>
|
||||
#include <godot_cpp/classes/scene_tree.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
static constexpr char MainScenePath[] = "res://Scenes/Levels/world.tscn";
|
||||
|
||||
namespace blitz {
|
||||
|
||||
void MainMenu::_bind_methods() {}
|
||||
|
||||
MainMenu::MainMenu() {}
|
||||
|
||||
MainMenu::~MainMenu() {}
|
||||
|
||||
void MainMenu::_ready() {
|
||||
Node* container = find_child("Container");
|
||||
DEV_ASSERT(container);
|
||||
|
||||
m_JoinButton = Object::cast_to<Button>(container->find_child("JoinButton"));
|
||||
m_CreateButton = Object::cast_to<Button>(container->find_child("CreateButton"));
|
||||
m_QuitButton = Object::cast_to<Button>(container->find_child("QuitButton"));
|
||||
|
||||
DEV_ASSERT(m_JoinButton);
|
||||
DEV_ASSERT(m_CreateButton);
|
||||
DEV_ASSERT(m_QuitButton);
|
||||
|
||||
m_JoinButton->connect("pressed", callable_mp(this, &MainMenu::OnJoinPressed));
|
||||
m_CreateButton->connect("pressed", callable_mp(this, &MainMenu::OnCreatePressed));
|
||||
m_QuitButton->connect("pressed", callable_mp(this, &MainMenu::OnQuitPressed));
|
||||
}
|
||||
|
||||
void MainMenu::OnJoinPressed() {
|
||||
get_tree()->change_scene_to_file(MainScenePath);
|
||||
}
|
||||
|
||||
void MainMenu::OnCreatePressed() {
|
||||
get_tree()->change_scene_to_file(MainScenePath);
|
||||
}
|
||||
|
||||
void MainMenu::OnQuitPressed() {
|
||||
get_tree()->quit();
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
30
src/MainMenu.h
Normal file
30
src/MainMenu.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <godot_cpp/classes/button.hpp>
|
||||
#include <godot_cpp/classes/control.hpp>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
class MainMenu : public godot::Control {
|
||||
GDCLASS(MainMenu, godot::Control)
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
MainMenu();
|
||||
~MainMenu();
|
||||
|
||||
// Godot overrides
|
||||
void _ready() override;
|
||||
|
||||
private:
|
||||
godot::Button* m_JoinButton;
|
||||
godot::Button* m_CreateButton;
|
||||
godot::Button* m_QuitButton;
|
||||
|
||||
void OnJoinPressed();
|
||||
void OnCreatePressed();
|
||||
void OnQuitPressed();
|
||||
};
|
||||
|
||||
} // namespace blitz
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "FirstPersonPlayer.h"
|
||||
#include "Player.h"
|
||||
#include "SpringArmPivot.h"
|
||||
#include "MainMenu.h"
|
||||
|
||||
#include <gdextension_interface.h>
|
||||
#include <godot_cpp/core/defs.hpp>
|
||||
@@ -10,14 +11,19 @@
|
||||
|
||||
using namespace godot;
|
||||
|
||||
static void RegisterClasses() {
|
||||
ClassDB::register_class<blitz::Player>();
|
||||
ClassDB::register_class<blitz::SpringArmPivot>();
|
||||
ClassDB::register_class<blitz::FirstPersonPlayer>();
|
||||
ClassDB::register_class<blitz::MainMenu>();
|
||||
}
|
||||
|
||||
void initialize_example_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
|
||||
ClassDB::register_class<blitz::Player>();
|
||||
ClassDB::register_class<blitz::SpringArmPivot>();
|
||||
ClassDB::register_class<blitz::FirstPersonPlayer>();
|
||||
RegisterClasses();
|
||||
}
|
||||
|
||||
void uninitialize_example_module(ModuleInitializationLevel p_level) {
|
||||
|
||||
Reference in New Issue
Block a user