This repository has been archived on 2019-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
dungeon-gunner/source/generator/Generator.h

61 lines
1.5 KiB
C
Raw Normal View History

2013-04-11 18:44:00 +00:00
/*
* Generator.h
*
* Created on: 07.04.2013
* Author: Felix
*/
#ifndef DG_GENERATOR_H_
#define DG_GENERATOR_H_
#include <SFML/Graphics.hpp>
2013-04-29 14:49:16 +00:00
#include "../sprites/Tile.h"
#include "SimplexNoise.h"
2013-04-29 14:49:16 +00:00
class World;
2013-04-28 16:11:39 +00:00
class Pathfinder;
2013-04-11 18:44:00 +00:00
/**
* Procedurally generates tiles, chooses player and enemy spawn positions.
*/
2013-04-11 18:44:00 +00:00
class Generator {
public:
2013-04-29 14:49:16 +00:00
explicit Generator(World& world, Pathfinder& pathfinder);
void generateCurrentAreaIfNeeded(const sf::Vector2f& position);
2013-04-11 18:44:00 +00:00
sf::Vector2f getPlayerSpawn() const;
std::vector<sf::Vector2f> getEnemySpawns(const sf::IntRect& area);
2013-04-11 18:44:00 +00:00
private:
typedef Tile::Type type;
typedef std::map<int, std::map<int, type> > array;
2013-04-11 18:44:00 +00:00
private:
void generateAreas(const sf::IntRect& area);
void generateTiles(const sf::IntRect& area);
sf::Vector2i findClosestFloor(const sf::Vector2i& position) const;
static void fill(array& tiles, const sf::IntRect& area, type value);
void filterWalls(array& tiles, int x, int y, int longside,
int shortside, int subtract);
int countWalls(const sf::IntRect& area);
static type getTileType(float value);
private:
static const int GENERATE_AREA_SIZE;
static const float GENERATE_AREA_RANGE;
2013-05-08 09:19:21 +00:00
2013-04-29 14:49:16 +00:00
World& mWorld;
Pathfinder& mPathfinder;
/// Contains values of all tiles that have yet been generated.
array mTiles;
/// Stores where tiles have already been generated.
std::map<int, std::map<int, bool> > mGenerated;
/// Perlin noise used for tile generation.
SimplexNoise mTileNoise;
/// Perlin noise used for character placement.
SimplexNoise mCharacterNoise;
2013-04-11 18:44:00 +00:00
};
#endif /* DG_GENERATOR_H_ */