diff --git a/.clang-format b/.clang-format index 8fb3f1f..a2d71a3 100644 --- a/.clang-format +++ b/.clang-format @@ -123,8 +123,8 @@ PenaltyBreakComment: 50 PenaltyBreakFirstLessLess: 120 PenaltyBreakOpenParenthesis: 10 PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 +PenaltyBreakTemplateDeclaration: 1000 +PenaltyExcessCharacter: 10 PenaltyReturnTypeOnItsOwnLine: 100 PenaltyIndentedWhitespace: 0 PointerAlignment: Left diff --git a/project/scenes/projectiles/bullet.tscn b/project/scenes/projectiles/bullet.tscn index 2b71869..b54f1d2 100644 --- a/project/scenes/projectiles/bullet.tscn +++ b/project/scenes/projectiles/bullet.tscn @@ -1,14 +1,19 @@ -[gd_scene load_steps=3 format=3] +[gd_scene load_steps=3 format=3 uid="uid://csam3a1tugjo4"] -[ext_resource type="Texture2D" path="res://assets/art/topdown/tanks_redux/projectiles/bulletdark1_outline.png" id="1_sadn1"] +[ext_resource type="Texture2D" uid="uid://cbx5pr44nef0m" path="res://assets/art/topdown/tanks_redux/projectiles/bulletdark1_outline.png" id="1_sadn1"] -[sub_resource type="CircleShape2D" id="CircleShape2D_70ybn"] +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_i8hct"] +radius = 10.0 +height = 35.0 [node name="Projectile" type="Projectile"] - -[node name="Bullet" type="Sprite2D" parent="."] -texture = ExtResource("1_sadn1") +scale = Vector2(0.5, 0.5) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] -scale = Vector2(0.8, 0.8) -shape = SubResource("CircleShape2D_70ybn") +rotation = 0.785398 +scale = Vector2(0.75, 0.75) +shape = SubResource("CapsuleShape2D_i8hct") + +[node name="Bullet" type="Sprite2D" parent="CollisionShape2D"] +scale = Vector2(1.33333, 1.33333) +texture = ExtResource("1_sadn1") diff --git a/src/nodes/character.cpp b/src/nodes/character.cpp index e30ffcb..cbaee87 100644 --- a/src/nodes/character.cpp +++ b/src/nodes/character.cpp @@ -54,6 +54,11 @@ namespace rl::inline node }(); } + PlayerController* Character::get_controller() const + { + return m_player_controller; + } + [[signal_slot]] void Character::on_player_movement(godot::Vector2 movement_velocity, double delta_time) { diff --git a/src/nodes/character.hpp b/src/nodes/character.hpp index 5ac5017..253eeb0 100644 --- a/src/nodes/character.hpp +++ b/src/nodes/character.hpp @@ -21,6 +21,9 @@ namespace rl::inline node void _ready() override; + PlayerController* get_controller() const; + + protected: [[property]] double get_movement_speed() const; [[property]] double get_movement_friction() const; [[property]] double get_rotation_speed() const; @@ -30,8 +33,7 @@ namespace rl::inline node [[signal_slot]] void on_player_shoot(); [[signal_slot]] void on_player_rotate(double rotation_angle, double delta_time); - [[signal_slot]] void on_player_movement(godot::Vector2 movement_velocity, - double delta_time); + [[signal_slot]] void on_player_movement(godot::Vector2 movement_velocity, double delta_time); protected: static void _bind_methods(); diff --git a/src/nodes/level.cpp b/src/nodes/level.cpp index 8a7be2e..d145eaf 100644 --- a/src/nodes/level.cpp +++ b/src/nodes/level.cpp @@ -1,6 +1,7 @@ #include "nodes/level.hpp" #include "nodes/character.hpp" +#include "singletons/console.hpp" #include "util/bind.hpp" #include "util/conversions.hpp" #include "util/debug.hpp" @@ -14,6 +15,7 @@ namespace rl::inline node { Level::Level() + : m_player{ player_scene.instantiate() } { // TODO: kill magic string scene::node::set_unique_name(this, "Level1"); @@ -22,20 +24,14 @@ namespace rl::inline node void Level::_ready() { - resource::preload::scene player_scene{ path::scene::Player }; - m_player = player_scene.instantiate(); - m_projectile_spawner = memnew(rl::ProjectileSpawner); - this->add_child(m_player); this->add_child(m_projectile_spawner); - signal::connect(m_player) <=> [this]() { - return slot(this, on_character_position_changed); - }(); + signal::connect(m_player->get_controller()) <=> + slot(this, on_character_position_changed); - signal::connect(m_player) <=> [this]() { - return slot(this, on_character_spawn_projectile); - }(); + signal::connect(m_player) <=> + slot(this, on_character_spawn_projectile); } void Level::_process(double delta_time) @@ -43,9 +39,9 @@ namespace rl::inline node if (engine::editor_active()) return; - if (this->active() && input::cursor_visible()) [[unlikely]] + if (this->active() && input::cursor_visible()) [[likely]] input::hide_cursor(); - if (!this->active() && !input::cursor_visible()) [[unlikely]] + else if (!this->active() && !input::cursor_visible()) [[unlikely]] input::show_cursor(); this->queue_redraw(); @@ -91,7 +87,9 @@ namespace rl::inline node godot::Vector2 location) const { runtime_assert(node != nullptr); - log::info(node->get_class() + " location: " + location); + auto console{ Console::get() }; + console->print("{} ({},{})\n", io::green(to(node->get_class()) + " location: "), + io::orange(location.x), io::orange(location.y)); } void Level::_bind_methods() diff --git a/src/nodes/level.hpp b/src/nodes/level.hpp index 1ac641e..81ee446 100644 --- a/src/nodes/level.hpp +++ b/src/nodes/level.hpp @@ -1,7 +1,10 @@ #pragma once +#include "nodes/character.hpp" #include "nodes/projectile_spawner.hpp" #include "util/bind.hpp" +#include "util/constants.hpp" +#include "util/scene.hpp" #include #include @@ -37,7 +40,8 @@ namespace rl::inline node private: std::atomic m_active{ false }; + resource::preload::scene player_scene{ path::scene::Player }; + ProjectileSpawner* m_projectile_spawner{ memnew(rl::ProjectileSpawner) }; Character* m_player{ nullptr }; - ProjectileSpawner* m_projectile_spawner{ nullptr }; }; } diff --git a/src/nodes/player_controller.cpp b/src/nodes/player_controller.cpp index c49131f..f8b64bc 100644 --- a/src/nodes/player_controller.cpp +++ b/src/nodes/player_controller.cpp @@ -1,4 +1,5 @@ #include "nodes/player_controller.hpp" + #include "util/bind.hpp" #include "util/constants.hpp" #include "util/engine.hpp" @@ -94,7 +95,7 @@ namespace rl::inline node godot::Vector2 target_rotation{ input->get_vector("rotate_left", "rotate_right", "rotate_up", "rotate_down") }; if (!target_rotation.is_zero_approx()) - m_rotation_angle = godot::Vector2{ 0, 0 }.angle_to_point(target_rotation) + + m_rotation_angle = godot::Vector2(0, 0).angle_to_point(target_rotation) + godot::Math::deg_to_rad(90.0); } break; @@ -109,5 +110,6 @@ namespace rl::inline node signal_binding::add(); signal_binding::add(); signal_binding::add(); + signal_binding::add(); } } diff --git a/src/nodes/projectile.cpp b/src/nodes/projectile.cpp index 860a9e8..b58bac5 100644 --- a/src/nodes/projectile.cpp +++ b/src/nodes/projectile.cpp @@ -1,5 +1,7 @@ #include "nodes/projectile.hpp" +#include "util/engine.hpp" + #include namespace rl::inline node @@ -11,6 +13,9 @@ namespace rl::inline node void Projectile::_process(double delta_time) { + if (engine::editor_active()) + return; + godot::Vector2 position{ this->get_position() }; position += m_velocity * m_movement_speed * delta_time; this->set_position(position); diff --git a/src/singletons/console.hpp b/src/singletons/console.hpp index f4a84e6..3169ab0 100644 --- a/src/singletons/console.hpp +++ b/src/singletons/console.hpp @@ -30,6 +30,11 @@ namespace rl m_static_inst = nullptr; } + static inline rl::Console* get() + { + return m_static_inst; + } + void set_context(TContext* context) { m_gui_console = context; @@ -62,7 +67,7 @@ namespace rl const duration_t elapsed{ clock_t::now() - m_start_time }; m_gui_console->append_text( - fmt::format("{:5} [{:>7.2}] [b]=>[/b] [color=yellow]{}[/color]", + fmt::format("[color=gray]{:5} [{:>7.2}] [b]=>[/b] {}[/color]", m_line_num.fetch_add(1, std::memory_order_relaxed), elapsed, msg.payload) .c_str()); @@ -84,12 +89,7 @@ namespace rl template void print(fmt::format_string format_str, TArgs&&... args) { - m_logger->info(fmt::format(format_str, std::forward(args...))); - } - - static inline rl::Console* get() - { - return m_static_inst; + m_logger->info(format_str, std::forward(args)...); } protected: diff --git a/src/util/io.hpp b/src/util/io.hpp index 05ff135..7b6a1e3 100644 --- a/src/util/io.hpp +++ b/src/util/io.hpp @@ -1,33 +1,78 @@ #pragma once -#include -#include +#include "util/concepts.hpp" + +#include +#include +#include +#include #include -#include #include -#include -#include #include #include #include +#include #include +#include namespace rl::inline utils { namespace io { - // inline constexpr auto to_lowercase(std::string_view str) noexcept - //{ - // std::span sp{ str.begin(), str.end() }; - // std::transform(sp.begin(), sp.end(), sp.begin(), [](char c) -> char { - // if (c >= 'A' && c <= 'Z') - // return c - 32; - // return c; - // }); - // return str.data(); - // } - - // constexpr const char* test{ std::move(to_lowercase("ASDF")) }; + static inline auto white(auto&& val) + { + return fmt::format(FMT_COMPILE("[color=white]{}[/color]"), + std::forward(val)); + } + + static inline auto gray(auto&& val) + { + return fmt::format(FMT_COMPILE("[color=gray]{}[/color]"), + std::forward(val)); + } + + static inline auto black(auto&& val) + { + return fmt::format(FMT_COMPILE("[color=black]{}[/color]"), + std::forward(val)); + } + + static inline auto red(auto&& val) + { + return fmt::format(FMT_COMPILE("[color=red]{}[/color]"), + std::forward(val)); + } + + static inline auto orange(auto&& val) + { + return fmt::format(FMT_COMPILE("[color=orange]{}[/color]"), + std::forward(val)); + } + + static inline auto yellow(auto&& val) + { + return fmt::format(FMT_COMPILE("[color=yellow]{}[/color]"), + std::forward(val)); + } + + static inline auto green(auto&& val) + { + return fmt::format(FMT_COMPILE("[color=green]{}[/color]"), + std::forward(val)); + } + + static inline auto blue(auto&& val) + { + return fmt::format(FMT_COMPILE("[color=blue]{}[/color]"), + std::forward(val)); + } + + static inline auto purple(auto&& val) + { + return fmt::format(FMT_COMPILE("[color=purple]{}[/color]"), + std::forward(val)); + } + } struct log