Basic skymap prototype

This commit is contained in:
Maximilian Giller 2023-06-18 17:20:35 +02:00
parent 66cc4fcb5f
commit 06a6b1b029
6 changed files with 72 additions and 7 deletions

View file

@ -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)

View file

@ -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> levelRenderer = std::make_shared<LevelRenderer>();
game->addGameObject(levelRenderer);
levelRenderer->addChild(std::make_shared<Skymap>());
levelRenderer->addChild(SpriteFactory::createTileMap(levelConfig.tileMapConfig));
if (DB_WORLD_GRID_RENDER)
{
game->addGameObject(std::make_shared<GridDebugLayer>(0, 50, 0, 50));
levelRenderer->addChild(std::make_shared<GridDebugLayer>(0, 50, 0, 50));
}
game->addGameObject(std::make_shared<TrackingView>());
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<TrackingView>());
LOG(INFO) << "Finished loading level '" << levelConfig.name << "'.";
}

View file

@ -0,0 +1 @@
#include "level_renderer.hpp"

View file

@ -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

View file

@ -0,0 +1,28 @@
#include <SFML/Graphics/VertexArray.hpp>
#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);
}

View file

@ -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