2019-05-27 13:50:49 +02:00
|
|
|
//
|
|
|
|
// Created by trotfunky on 27/05/19.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef RAYCASTING_WORLD_H
|
|
|
|
#define RAYCASTING_WORLD_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <ostream>
|
2019-06-01 06:42:29 +02:00
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "Player.h"
|
2019-05-27 13:50:49 +02:00
|
|
|
|
|
|
|
enum class BlockType {
|
|
|
|
AIR,
|
|
|
|
WALL,
|
|
|
|
DOOR,
|
|
|
|
WINDOW,
|
|
|
|
};
|
|
|
|
|
|
|
|
class World {
|
|
|
|
public:
|
2019-06-01 06:42:29 +02:00
|
|
|
Player player;
|
2019-05-27 13:50:49 +02:00
|
|
|
|
2019-06-01 06:42:29 +02:00
|
|
|
World(int w, int h, sf::Color groundColor = sf::Color::Green, sf::Color ceilingColor = sf::Color::Blue,
|
|
|
|
std::vector<BlockType> worldMap = {});
|
2019-05-27 13:50:49 +02:00
|
|
|
int getW() const;
|
|
|
|
int getH() const;
|
|
|
|
|
|
|
|
BlockType getBlock(float x, float y) const;
|
|
|
|
void setBlock(BlockType block, int x, int y, int width = 1, int height = 1);
|
|
|
|
|
2019-06-01 06:42:29 +02:00
|
|
|
void render(sf::RenderWindow&) const;
|
|
|
|
|
2019-05-27 13:50:49 +02:00
|
|
|
friend std::ostream& operator<<(std::ostream& ostream, World const & world);
|
|
|
|
private:
|
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
std::vector<BlockType> map;
|
2019-06-01 06:42:29 +02:00
|
|
|
|
|
|
|
sf::Color groundColor;
|
|
|
|
sf::Color ceilingColor;
|
|
|
|
|
|
|
|
void fillColumn(sf::RenderWindow&, int column, float scale, sf::Color wallColor = sf::Color(127,127,127)) const;
|
2023-12-30 14:50:35 +01:00
|
|
|
/**
|
|
|
|
* Cast a ray from a given position and return the on-screen scale.
|
|
|
|
* @param originX Ray X origin
|
|
|
|
* @param originY Ray Y origin
|
|
|
|
* @param orientation Angle to cast to, in degrees
|
|
|
|
* @return Scale on the screen of the hit wall.
|
|
|
|
*/
|
2019-06-01 06:42:29 +02:00
|
|
|
float castRay(float originX, float originY, float orientation);
|
2019-05-27 13:50:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //RAYCASTING_WORLD_H
|