Right before bringing in the code to render sprites, but after I restructured to have the sprite data.
This commit is contained in:
parent
0828fb584e
commit
93b7faa369
2 changed files with 88 additions and 59 deletions
|
@ -11,6 +11,27 @@
|
|||
using matrix::Matrix;
|
||||
using namespace fmt;
|
||||
|
||||
#define texWidth 64 // must be power of two
|
||||
#define texHeight 64 // must be power of two
|
||||
|
||||
|
||||
#define numSprites 1
|
||||
#define numTextures 11
|
||||
|
||||
struct Sprite {
|
||||
double x;
|
||||
double y;
|
||||
int texture;
|
||||
};
|
||||
|
||||
const int RAY_VIEW_WIDTH=1280;
|
||||
const int RAY_VIEW_HEIGHT=720;
|
||||
const int RAY_VIEW_X=0;
|
||||
const int RAY_VIEW_Y=0;
|
||||
|
||||
const int SCREEN_HEIGHT=RAY_VIEW_HEIGHT;
|
||||
const int SCREEN_WIDTH=1280;
|
||||
|
||||
Matrix MAP{
|
||||
{8,8,8,8,8,8,8,8,8},
|
||||
{8,0,2,0,0,0,0,0,8},
|
||||
|
@ -23,14 +44,6 @@ Matrix MAP{
|
|||
{8,8,8,8,8,8,8,8,8}
|
||||
};
|
||||
|
||||
const int RAY_VIEW_WIDTH=1920;
|
||||
const int RAY_VIEW_HEIGHT=1080;
|
||||
const int RAY_VIEW_X=0;
|
||||
const int RAY_VIEW_Y=0;
|
||||
|
||||
const int SCREEN_HEIGHT=RAY_VIEW_HEIGHT;
|
||||
const int SCREEN_WIDTH=1920;
|
||||
|
||||
const int MAP_SIZE=matrix::width(MAP);
|
||||
const int TILE_SIZE=RAY_VIEW_HEIGHT / MAP_SIZE;
|
||||
int PITCH=0;
|
||||
|
@ -56,17 +69,24 @@ double planeY = 0.66;
|
|||
#define rgba_color(r,g,b,a) (r<<(0*8))|(g<<(1*8))|(b<<(2*8))|(a<<(3*8))
|
||||
#define gray_color(c) rgba_color(c, c, c, 255)
|
||||
|
||||
std::vector<uint32_t> texture[8];
|
||||
#define texWidth 256 // must be power of two
|
||||
#define texHeight 256 // must be power of two
|
||||
Sprite sprites[numSprites] = {
|
||||
{20.5, 11.5, 8}
|
||||
};
|
||||
|
||||
double ZBuffer[RAY_VIEW_WIDTH];
|
||||
int spriteOrder[numSprites];
|
||||
double spriteDistance[numSprites];
|
||||
|
||||
std::vector<uint32_t> texture[numTextures];
|
||||
|
||||
#define pixcoord(X, Y) ((Y) * RAY_VIEW_WIDTH) + (X)
|
||||
|
||||
uint32_t pixels[RAY_VIEW_WIDTH * RAY_VIEW_HEIGHT] = {0};
|
||||
|
||||
sf::Texture view_texture;
|
||||
sf::Sprite view_sprite;
|
||||
|
||||
void sortSprites(int *order, double *dist, int amount);
|
||||
|
||||
void loadImage(std::vector<uint32_t>& texture, const char *filename) {
|
||||
sf::Image img;
|
||||
bool good = img.loadFromFile(filename);
|
||||
|
@ -76,18 +96,22 @@ void loadImage(std::vector<uint32_t>& texture, const char *filename) {
|
|||
}
|
||||
|
||||
void load_textures() {
|
||||
for(int i = 0; i < 8; i++) {
|
||||
for(int i = 0; i < numTextures; i++) {
|
||||
texture[i].resize(texWidth * texHeight);
|
||||
}
|
||||
|
||||
loadImage(texture[0], "pics/tile16.png");
|
||||
loadImage(texture[1], "pics/tile02.png");
|
||||
loadImage(texture[2], "pics/tile03.png");
|
||||
loadImage(texture[3], "pics/tile32.png");
|
||||
loadImage(texture[4], "pics/tile05.png");
|
||||
loadImage(texture[5], "pics/tile17.png");
|
||||
loadImage(texture[6], "pics/tile10.png");
|
||||
loadImage(texture[7], "pics/tile01.png");
|
||||
loadImage(texture[0], "pics/eagle.png");
|
||||
loadImage(texture[1], "pics/redbrick.png");
|
||||
loadImage(texture[2], "pics/purplestone.png");
|
||||
loadImage(texture[3], "pics/greystone.png");
|
||||
loadImage(texture[4], "pics/bluestone.png");
|
||||
loadImage(texture[5], "pics/mossy.png");
|
||||
loadImage(texture[6], "pics/wood.png");
|
||||
loadImage(texture[7], "pics/colorstone.png");
|
||||
|
||||
loadImage(texture[8], "pics/barrel.png");
|
||||
loadImage(texture[9], "pics/pillar.png");
|
||||
loadImage(texture[10], "pics/greenlight.png");
|
||||
}
|
||||
|
||||
void draw_sfml_rect(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, uint8_t color) {
|
||||
|
@ -412,3 +436,8 @@ int main() {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sortSprites(int* order, double* dist, int amount)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue