Teo-CD
ddb01d0509
World has a lot of type conversion warnings. Take care of most of them, for a slight performance hit ( :( ). Re-order constructor parameters to match declaration. Move FillColumn to a more appropriate place. GetBlock gets called a lot : use direct memory access of the vector rather than going through bounds checks with .at(). Introduce an integer overload to remove warnings.
67 lines
1.7 KiB
C++
67 lines
1.7 KiB
C++
//
|
|
// Created by trotfunky on 27/05/19.
|
|
//
|
|
|
|
#ifndef RAYCASTING_WORLD_H
|
|
#define RAYCASTING_WORLD_H
|
|
|
|
#include <vector>
|
|
#include <ostream>
|
|
#include <SFML/Graphics.hpp>
|
|
#include <iostream>
|
|
|
|
#include "Player.h"
|
|
|
|
enum class BlockType {
|
|
AIR,
|
|
WALL,
|
|
DOOR,
|
|
WINDOW,
|
|
};
|
|
|
|
class World {
|
|
public:
|
|
Player player;
|
|
|
|
World(int w, int h,
|
|
sf::Color groundColor = sf::Color{67, 137, 39},
|
|
sf::Color ceilingColor = sf::Color{39, 69, 137},
|
|
std::vector<BlockType> worldMap = {});
|
|
int getW() const;
|
|
int getH() const;
|
|
|
|
inline BlockType getBlock(int x, int y) const;
|
|
inline BlockType getBlock(float x, float y) const;
|
|
void setBlock(BlockType block, int x, int y, int width = 1, int height = 1);
|
|
|
|
void render(sf::RenderWindow&) const;
|
|
|
|
/**
|
|
* Move the world one step forward.
|
|
* @param stepTime delta time since last step, in seconds
|
|
*/
|
|
void step(const float& stepTime);
|
|
|
|
friend std::ostream& operator<<(std::ostream& ostream, World const & world);
|
|
private:
|
|
int w;
|
|
int h;
|
|
std::vector<BlockType> map;
|
|
|
|
sf::Color groundColor;
|
|
sf::Color ceilingColor;
|
|
|
|
void fillColumn(sf::RenderWindow&, unsigned int column, float scale,
|
|
sf::Color wallColor = sf::Color(84,56,34)) const;
|
|
/**
|
|
* Cast a ray from a given position and return the on-screen scale.
|
|
* @param originX Ray X origin, strictly positive
|
|
* @param originY Ray Y origin, strictly positive
|
|
* @param orientation Angle to cast to, in degrees between 0 and 360
|
|
* @return Scale on the screen of the hit wall.
|
|
*/
|
|
float castRay(float originX, float originY, float orientation) const;
|
|
};
|
|
|
|
|
|
#endif //RAYCASTING_WORLD_H
|