diff --git a/README.md b/README.md new file mode 100644 index 0000000..71d3c95 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Varicle Framework diff --git a/src/include/components.hpp b/src/include/components.hpp index cfb4bd1..cc5e14c 100644 --- a/src/include/components.hpp +++ b/src/include/components.hpp @@ -12,6 +12,9 @@ struct Velocity{ }; struct Player{}; +struct PlayerBody{ + unsigned int part_idx; +}; struct Fruit{}; diff --git a/src/include/player.hpp b/src/include/player.hpp index 57a1db0..807de39 100644 --- a/src/include/player.hpp +++ b/src/include/player.hpp @@ -1,6 +1,24 @@ #pragma once +#include + + #include #include void create_player(entt::registry& registry,Texture* texture); +void create_player_body(entt::registry& registry,Texture* texture,unsigned int idx); void update_player_system(entt::registry& registry,float dt); + +class BodyManager{ + private: + std::vector parts_position_stack = {}; + public: + Texture* body_texture; + BodyManager(Texture* texture) : body_texture(texture){} + + void add_body(entt::registry& registry); + void pop_body(); + void update_body_positions(Position player_head_position); + Position get_body_position(unsigned int part_idx); +}; + diff --git a/src/include/scene.hpp b/src/include/scene.hpp index 30c4760..6a59fc9 100644 --- a/src/include/scene.hpp +++ b/src/include/scene.hpp @@ -3,6 +3,7 @@ #include #include +#include enum class SceneType{ MENU, @@ -51,7 +52,7 @@ class MenuScene : public Scene{ class SceneManager{ private: - Scene* current_scene = nullptr; + std::unique_ptr current_scene = nullptr; SceneType next_scene_type; bool pending_switch = false; bool should_quit = false; @@ -68,4 +69,5 @@ class SceneManager{ bool should_game_close(); void request_switch(SceneType type); void quit(); + Scene& get_current_scene(); }; diff --git a/src/player.cpp b/src/player.cpp index 51173ea..d74e36e 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -10,6 +10,8 @@ entt::entity player; const float SPEED = 300.0f; +class BodyManager; + void create_player(entt::registry& registry,Texture* texture){ const auto entity = registry.create(); @@ -17,6 +19,8 @@ void create_player(entt::registry& registry,Texture* texture){ registry.emplace(entity,SPEED,0.0f); registry.emplace(entity); registry.emplace(entity,texture,0.0f,0.0f,70.0f,70.0f,false,false,0.0f); + + } void update_player_system(entt::registry& registry,float dt){ @@ -57,5 +61,44 @@ void update_player_system(entt::registry& registry,float dt){ } } + auto body_view = registry.view(); + for (entt::entity entity : body_view){ + const PlayerBody& body = body_view.get(entity); + Position& pos = body_view.get(entity); + + } + + + +} + +void create_player_body(entt::registry& registry,Texture* texture,unsigned int idx){ + const auto entity = registry.create(); + registry.emplace(entity,100.0f,0.0f); + registry.emplace(entity,SPEED,0.0f); + registry.emplace(entity,idx); + registry.emplace(entity,texture,0.0f,0.0f,70.0f,70.0f,false,false,0.0f); +} + +void BodyManager::add_body(entt::registry& registry) +{ + create_player_body(registry,body_texture,parts_position_stack.size()); + parts_position_stack.push_back( Position{}); +} + +void BodyManager::pop_body(){ + + parts_position_stack.pop_back(); +} + +void BodyManager::update_body_positions(Position player_head_position){ + for ( auto i = parts_position_stack.size()-1; i > 0 ;i--){ + parts_position_stack[i] = parts_position_stack[i-1]; + } + parts_position_stack[0] = player_head_position; +} + +Position BodyManager::get_body_position(unsigned int part_idx){ + return parts_position_stack[part_idx]; } diff --git a/src/scenes/scene.cpp b/src/scenes/scene.cpp index 9c71d83..78d858c 100644 --- a/src/scenes/scene.cpp +++ b/src/scenes/scene.cpp @@ -2,11 +2,15 @@ #include SceneManager::SceneManager(){ - current_scene = new MenuScene(); + current_scene = std::make_unique(); } SceneManager::~SceneManager(){ - delete current_scene; + // delete current_scene; +} + +Scene& SceneManager::get_current_scene(){ + return *current_scene; } void SceneManager::process_scene_switch(){ @@ -14,15 +18,15 @@ void SceneManager::process_scene_switch(){ if (!pending_switch) return; if (current_scene){ - delete current_scene; + current_scene.reset(); } switch(next_scene_type){ case SceneType::MENU: - current_scene = new MenuScene(); + current_scene = std::make_unique(); break; case SceneType::GAMEPLAY: - current_scene = new GamePlayScene(); + current_scene = std::make_unique(); break; } pending_switch = false;