Exploring raycasters and possibly make a little "doom like" game based on it.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
raycaster/raycaster.hpp

60 lines
1.3 KiB

#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/System/Clock.hpp>
#include "texture.hpp"
#include "animator.hpp"
#include "spatialmap.hpp"
#include "levelmanager.hpp"
using matrix::Matrix;
using RGBA = uint32_t;
struct Raycaster {
int $pitch=0;
sf::Clock $clock;
TexturePack &$textures;
double $posX = 0;
double $posY = 0;
// initial direction vector
double $dirX = -1;
double $dirY = 0;
// the 2d raycaster version of camera plane
double $planeX = 0;
double $planeY = 0.66;
sf::Texture $view_texture;
sf::Sprite $view_sprite;
std::unique_ptr<RGBA[]> $pixels = nullptr;
int $width;
int $height;
GameLevel $level;
Matrix $map;
std::unordered_map<DinkyECS::Entity, SpriteTexture> $sprites;
std::vector<double> ZBuffer; // width
Animator $anim;
Raycaster(TexturePack &textures, int width, int height);
void cast_rays();
void draw_ceiling_floor();
void draw_pixel_buffer();
void sprite_casting(sf::RenderTarget& target);
void draw(sf::RenderTarget& target);
void sort_sprites(std::vector<int>& order, std::vector<double>& dist, int amount);
void position_camera(float player_x, float player_y);
void set_position(int x, int y);
inline size_t pixcoord(int x, int y) {
return ((y) * $width) + (x);
}
void set_level(GameLevel level);
};