#pragma once #include #include #include #include #include #include #include "amt/matrix.hpp" #include #include #include "dbc.hpp" #include using Matrix = amt::Matrix; struct Sprite { double x; double y; int texture; // ZED: this should be a separate transform parameter double elevation=0; int uDiv=1; int vDiv=1; }; using RGBA = uint32_t; struct TexturePack { int NUM_SPRITES=1; int NUM_TEXTURES=11; int TEXTURE_WIDTH=256; // must be power of two int TEXTURE_HEIGHT=256; // must be power of two std::vector> images; std::vector SPRITE{{4.0, 3.55, 8}}; const int floor = 3; const int ceiling = 6; void load_textures(); std::vector load_image(const char *filename); Sprite &get_sprite(size_t sprite_num); std::vector& get(size_t num); }; struct Raycaster { int PITCH=0; 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; //ZED: USE smart pointer for this std::unique_ptr pixels = nullptr; int $width; int $height; sf::RenderWindow& $window; Matrix& $map; std::vector spriteOrder; std::vector spriteDistance; std::vector ZBuffer; // width Raycaster(sf::RenderWindow& window, Matrix &map, int width, int height); void draw_pixel_buffer(); void clear(); void cast_rays(); void draw_ceiling_floor(); void sprite_casting(); void sort_sprites(std::vector& order, std::vector& dist, int amount); void render(); bool empty_space(int new_x, int new_y); void run(double speed, int dir); void rotate(double speed, int dir); 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); } };