diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b4de56..5c9a883 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,7 +98,7 @@ set(SOURCES src/levels.hpp src/sprites/tiling/tilemap.cpp src/sprites/tiling/tilemap.hpp - src/sprites/tiling/tilemap_config.hpp src/sprites/tiling/tileset_config.hpp src/sprites/tiling/tileset.cpp src/sprites/tiling/tileset.hpp src/game/frame_counter.cpp src/game/frame_counter.hpp) + src/sprites/tiling/tilemap_config.hpp src/sprites/tiling/tileset_config.hpp src/sprites/tiling/tileset.cpp src/sprites/tiling/tileset.hpp src/game/frame_counter.cpp src/game/frame_counter.hpp src/game/level/level_renderer.cpp src/game/level/level_renderer.hpp src/sprites/skymap/skymap.cpp src/sprites/skymap/skymap.hpp) set(PHYSICS_00_SOURCES src/prototypes/physics_00.cpp) diff --git a/src/game/level/level_loader.cpp b/src/game/level/level_loader.cpp index c74df78..37ab24d 100644 --- a/src/game/level/level_loader.cpp +++ b/src/game/level/level_loader.cpp @@ -7,6 +7,8 @@ #include "../collectables/collectable_factory.hpp" #include "../player/player_collection.hpp" #include "../physics/hole/hole_depth_simulation.hpp" +#include "level_renderer.hpp" +#include "../../sprites/skymap/skymap.hpp" void LevelLoader::loadLevel(const LevelConfig &levelConfig) { @@ -19,23 +21,26 @@ void LevelLoader::loadLevel(const LevelConfig &levelConfig) MapSimulation::getInstance()->resetMap(levelConfig.worldMapSize); PlayerCollection::getInstance()->clear(); - // Add basic game objects - game->addGameObject(SpriteFactory::createTileMap(levelConfig.tileMapConfig)); + // Add rendered level objects + std::shared_ptr levelRenderer = std::make_shared(); + game->addGameObject(levelRenderer); + + levelRenderer->addChild(std::make_shared()); + levelRenderer->addChild(SpriteFactory::createTileMap(levelConfig.tileMapConfig)); if (DB_WORLD_GRID_RENDER) { - game->addGameObject(std::make_shared(0, 50, 0, 50)); + levelRenderer->addChild(std::make_shared(0, 50, 0, 50)); } - game->addGameObject(std::make_shared()); - game->addGameObject(PlayerCollection::getInstance()); + levelRenderer->addChild(PlayerCollection::getInstance()); PlayerCollection::getInstance()->setSpawnPoints(levelConfig.playerSpawnPoints); // Prepare collectables framework auto maxDepth = (int) levelConfig.worldMapSize.x * 2; auto collectablesCollection = CollectablesCollection::getInstance(); collectablesCollection->createEmpty(maxDepth); - game->addGameObject(collectablesCollection); + levelRenderer->addChild(collectablesCollection); // Spawn collectibles for (auto const &collectableInfo: levelConfig.collectables) @@ -43,9 +48,14 @@ void LevelLoader::loadLevel(const LevelConfig &levelConfig) spawnCollectable(collectableInfo); } + + // Add physics simulations game->addGameObject(MapSimulation::getInstance()); + // Add views + game->addGameObject(std::make_shared()); + LOG(INFO) << "Finished loading level '" << levelConfig.name << "'."; } diff --git a/src/game/level/level_renderer.cpp b/src/game/level/level_renderer.cpp new file mode 100644 index 0000000..7c22f14 --- /dev/null +++ b/src/game/level/level_renderer.cpp @@ -0,0 +1 @@ +#include "level_renderer.hpp" diff --git a/src/game/level/level_renderer.hpp b/src/game/level/level_renderer.hpp new file mode 100644 index 0000000..96e4c7a --- /dev/null +++ b/src/game/level/level_renderer.hpp @@ -0,0 +1,12 @@ +#ifndef HOLESOME_LEVEL_RENDERER_HPP +#define HOLESOME_LEVEL_RENDERER_HPP + + +#include "../game_object.h" + +class LevelRenderer : public GameObject +{ +}; + + +#endif //HOLESOME_LEVEL_RENDERER_HPP diff --git a/src/sprites/skymap/skymap.cpp b/src/sprites/skymap/skymap.cpp new file mode 100644 index 0000000..566d739 --- /dev/null +++ b/src/sprites/skymap/skymap.cpp @@ -0,0 +1,28 @@ +#include +#include "skymap.hpp" + +void Skymap::draw(sf::RenderWindow *window) +{ + float mapHeight = 1000; + + sf::VertexArray backgroundGradient(sf::Quads, 4); + + // Defining the coordinates clockwise + // Top Left + backgroundGradient[0].position = sf::Vector2f(-2 * mapHeight, -2 * mapHeight); + backgroundGradient[0].color = sf::Color(150, 200, 255); + + // Top Right + backgroundGradient[1].position = sf::Vector2f(2 * mapHeight, -2 * mapHeight); + backgroundGradient[1].color = sf::Color(150, 200, 255); + + // Bottom Right + backgroundGradient[2].position = sf::Vector2f(2 * mapHeight, mapHeight); + backgroundGradient[2].color = sf::Color::White; + + // Bottom Left + backgroundGradient[3].position = sf::Vector2f(-2 * mapHeight, mapHeight); + backgroundGradient[3].color = sf::Color::White; + + window->draw(backgroundGradient); +} diff --git a/src/sprites/skymap/skymap.hpp b/src/sprites/skymap/skymap.hpp new file mode 100644 index 0000000..db5099a --- /dev/null +++ b/src/sprites/skymap/skymap.hpp @@ -0,0 +1,14 @@ +#ifndef HOLESOME_SKYMAP_HPP +#define HOLESOME_SKYMAP_HPP + + +#include "../../game/game_object.h" + +class Skymap : public GameObject +{ +public: + void draw(sf::RenderWindow *window) override; +}; + + +#endif //HOLESOME_SKYMAP_HPP