Got rid of the wolf3d textures and now using 256px textures that are open source. Added a simple portal that can go on the floor.
BIN
pics/barrel.png
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.5 KiB |
BIN
pics/chess.png
Before Width: | Height: | Size: 124 KiB |
Before Width: | Height: | Size: 3.3 KiB |
BIN
pics/eagle.png
Before Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 393 B |
Before Width: | Height: | Size: 3.6 KiB |
BIN
pics/mossy.png
Before Width: | Height: | Size: 4.2 KiB |
BIN
pics/pillar.png
Before Width: | Height: | Size: 1.5 KiB |
BIN
pics/portal.png
Normal file
After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 3 KiB |
BIN
pics/teleporter.png
Normal file
After Width: | Height: | Size: 196 KiB |
BIN
pics/wood.png
Before Width: | Height: | Size: 1.4 KiB |
|
@ -11,23 +11,22 @@
|
|||
using matrix::Matrix;
|
||||
using namespace fmt;
|
||||
|
||||
#define texWidth 64 // must be power of two
|
||||
#define texHeight 64 // must be power of two
|
||||
#define texWidth 256 // must be power of two
|
||||
#define texHeight 256 // must be power of two
|
||||
|
||||
|
||||
#define numSprites 3
|
||||
#define numSprites 1
|
||||
#define numTextures 11
|
||||
|
||||
struct Sprite {
|
||||
double x;
|
||||
double y;
|
||||
double elevation;
|
||||
int texture;
|
||||
};
|
||||
|
||||
//parameters for scaling and moving the sprites
|
||||
#define uDiv 1
|
||||
#define vDiv 1
|
||||
#define vMove 0.0
|
||||
|
||||
const int RAY_VIEW_WIDTH=1280;
|
||||
const int RAY_VIEW_HEIGHT=720;
|
||||
|
@ -75,9 +74,9 @@ double planeY = 0.66;
|
|||
#define gray_color(c) rgba_color(c, c, c, 255)
|
||||
|
||||
Sprite SPRITE[numSprites] = {
|
||||
{3.0, 4.5, 8},
|
||||
{3.4, 1.95, 9},
|
||||
{7.34, 5.5, 10}
|
||||
{4.0, 3.55, 0, 8},
|
||||
// {3.4, 1.95, 9},
|
||||
// {7.34, 5.5, 10}
|
||||
};
|
||||
|
||||
double ZBuffer[RAY_VIEW_WIDTH];
|
||||
|
@ -107,18 +106,15 @@ void load_textures() {
|
|||
texture[i].resize(texWidth * texHeight);
|
||||
}
|
||||
|
||||
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");
|
||||
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[8], "pics/portal.png");
|
||||
}
|
||||
|
||||
void draw_sfml_rect(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, uint8_t color) {
|
||||
|
@ -318,9 +314,10 @@ void ray_casting(sf::RenderWindow &window, Matrix& map) {
|
|||
// after sorting the sprites, do the projection
|
||||
for(int i = 0; i < numSprites; i++) {
|
||||
int sprite_index = spriteOrder[i];
|
||||
double spriteX = SPRITE[sprite_index].x - posX;
|
||||
double spriteY = SPRITE[sprite_index].y - posY;
|
||||
int sprite_texture_number = SPRITE[sprite_index].texture;
|
||||
Sprite& sprite_rec = SPRITE[sprite_index];
|
||||
double spriteX = sprite_rec.x - posX;
|
||||
double spriteY = sprite_rec.y - posY;
|
||||
int sprite_texture_number = sprite_rec.texture;
|
||||
auto sprite_texture = texture[sprite_texture_number];
|
||||
|
||||
//transform sprite with the inverse camera matrix
|
||||
|
@ -337,7 +334,7 @@ void ray_casting(sf::RenderWindow &window, Matrix& map) {
|
|||
|
||||
int spriteScreenX = int((w / 2) * (1 + transformX / transformY));
|
||||
|
||||
int vMoveScreen = int(vMove / transformY);
|
||||
int vMoveScreen = int(sprite_rec.elevation * -1 / transformY);
|
||||
|
||||
// calculate the height of the sprite on screen
|
||||
//using "transformY" instead of the real distance prevents fisheye
|
||||
|
|