diff --git a/lib/include/chomper/collectible.hpp b/lib/include/chomper/collectible.hpp index a7cedb4..5059c62 100644 --- a/lib/include/chomper/collectible.hpp +++ b/lib/include/chomper/collectible.hpp @@ -1,9 +1,8 @@ #pragma once #include "chomper/world_space.hpp" -#include "glm/ext/vector_float2.hpp" -#include "le2d/drawable/sprite.hpp" -#include "le2d/renderer.hpp" -#include "le2d/resource/texture.hpp" +#include +#include +#include namespace chomper { class Collectible { @@ -19,4 +18,4 @@ class Collectible { private: le::drawable::Sprite m_sprite{}; }; -} // namespace chomper \ No newline at end of file +} // namespace chomper diff --git a/lib/include/chomper/player.hpp b/lib/include/chomper/player.hpp index b7d4122..7320a3d 100644 --- a/lib/include/chomper/player.hpp +++ b/lib/include/chomper/player.hpp @@ -2,12 +2,12 @@ #include "chomper/controller.hpp" #include "chomper/debug_inspector.hpp" #include "chomper/snake.hpp" -#include "le2d/drawable/text.hpp" -#include "le2d/render_instance.hpp" #include #include +#include #include #include +#include #include namespace chomper { diff --git a/lib/include/chomper/runtimes/game.hpp b/lib/include/chomper/runtimes/game.hpp index 7e12e03..f1b563c 100644 --- a/lib/include/chomper/runtimes/game.hpp +++ b/lib/include/chomper/runtimes/game.hpp @@ -4,12 +4,12 @@ #include "chomper/player.hpp" #include "chomper/runtime.hpp" #include "chomper/world.hpp" -#include "le2d/random.hpp" -#include "le2d/resource/texture.hpp" #include #include #include #include +#include +#include #include namespace chomper::runtime { diff --git a/lib/include/chomper/world_space.hpp b/lib/include/chomper/world_space.hpp index b845b6a..6b002f0 100644 --- a/lib/include/chomper/world_space.hpp +++ b/lib/include/chomper/world_space.hpp @@ -1,14 +1,18 @@ #pragma once #include "chomper/world_size.hpp" -#include "glm/common.hpp" +#include #include namespace chomper::worldSpace { namespace { auto const halfGridSize = glm::ceil(worldSize_v * 0.5f); -// only add half the tilesize when that axis is even -constexpr auto tileOffset = - glm::vec2{(static_cast(worldSize_v.x) % 2 == 0) ? tileSize_v.x * 0.5f : 0.0f, (static_cast(worldSize_v.y) % 2 == 0) ? tileSize_v.y * 0.5f : 0.0f}; + +[[nodiscard]] constexpr auto toTileOffset(float const worldSize, float const tileSize) -> float { + // only add half the tilesize when that axis is even + return (static_cast(worldSize) % 2 == 0) ? tileSize * 0.5f : 0.0f; +} + +constexpr auto tileOffset = glm::vec2{toTileOffset(worldSize_v.x, tileSize_v.x), toTileOffset(worldSize_v.y, tileSize_v.y)}; } // namespace constexpr auto gridToWorld(glm::vec2 gridPosition) { @@ -21,4 +25,4 @@ constexpr auto worldToGrid(glm::vec2 worldPosition) { constexpr auto isOutOfBounds(glm::vec2 gridPoint) { return gridPoint.x < 0 || gridPoint.y < 0 || gridPoint.x >= worldSize_v.x || gridPoint.y >= worldSize_v.y; } -} // namespace chomper::worldSpace \ No newline at end of file +} // namespace chomper::worldSpace diff --git a/lib/src/collectible.cpp b/lib/src/collectible.cpp index 3573d9c..ba7da42 100644 --- a/lib/src/collectible.cpp +++ b/lib/src/collectible.cpp @@ -1,6 +1,6 @@ #include "chomper/collectible.hpp" #include "chomper/world_size.hpp" -#include "le2d/renderer.hpp" +#include namespace chomper { Collectible::Collectible(le::ITexture const& texture, glm::vec2 position) { @@ -12,4 +12,4 @@ Collectible::Collectible(le::ITexture const& texture, glm::vec2 position) { void Collectible::draw(le::IRenderer& renderer) const { m_sprite.draw(renderer); } -} // namespace chomper \ No newline at end of file +} // namespace chomper diff --git a/lib/src/player_controller.cpp b/lib/src/controllers/player_controller.cpp similarity index 100% rename from lib/src/player_controller.cpp rename to lib/src/controllers/player_controller.cpp diff --git a/lib/src/player.cpp b/lib/src/player.cpp index d9f7e48..e381e74 100644 --- a/lib/src/player.cpp +++ b/lib/src/player.cpp @@ -92,7 +92,7 @@ void Player::updateScoreText() { }; m_scoreText.set_string(m_engine->getResources().getMainFont(), std::format("Score: {}", m_info.score), textParams_v); - m_scoreText.transform.position = worldSpace::gridToWorld({0, worldSize_v.y - 1}) + glm::vec2{m_scoreText.get_size().x / 2, 0}; + m_scoreText.transform.position = worldSpace::gridToWorld({0.0f, worldSize_v.y - 1.0f}) + glm::vec2{0.5f * m_scoreText.get_size().x, 0.0f}; } void Player::draw(le::IRenderer& renderer) const { diff --git a/lib/src/runtimes/game.cpp b/lib/src/runtimes/game.cpp index 16666f8..525f9dc 100644 --- a/lib/src/runtimes/game.cpp +++ b/lib/src/runtimes/game.cpp @@ -52,10 +52,10 @@ void Game::tick(kvf::Seconds const dt) { void Game::render(le::IRenderer& renderer) const { m_world->draw(renderer); - m_player->draw(renderer); for (auto const& collectible : m_collectibles) { collectible.draw(renderer); } + m_player->draw(renderer); if (m_countdown.count() > 0) { m_countdownText.draw(renderer); } diff --git a/lib/src/snake.cpp b/lib/src/snake.cpp index 5d9bdff..e1b0e9e 100644 --- a/lib/src/snake.cpp +++ b/lib/src/snake.cpp @@ -1,9 +1,9 @@ #include "chomper/snake.hpp" #include "chomper/world_size.hpp" #include "chomper/world_space.hpp" -#include "le2d/render_instance.hpp" #include #include +#include namespace chomper { namespace { @@ -14,7 +14,7 @@ constexpr auto headingToDir_v = klib::EnumArray{glm::vec2{1. Snake::Snake() { le::RenderInstance instance{}; instance.tint = snakeBodyColor_v; - instance.transform.position = worldSpace::gridToWorld({0, worldSize_v.y / 2}); + instance.transform.position = worldSpace::gridToWorld({0, 0.5f * worldSize_v.y}); m_instances.push_back(instance); while (m_instances.size() < m_baseSize) { grow({});