Tried out 512px tiles and sprites and they actually look like crap. They just look like bad textures not better painted. With 256 they look nicely pixelated.

master
Zed A. Shaw 1 month ago
parent d397c02d38
commit 5e6f95513c
  1. BIN
      assets/armored_knight_1-256.png
  2. BIN
      assets/armored_knight_1-512.png
  3. BIN
      assets/ceiling_test-256.png
  4. BIN
      assets/ceiling_test-512.png
  5. BIN
      assets/ceiling_worm-256.png
  6. BIN
      assets/cinqueda_1-512.png
  7. 20
      assets/config.json
  8. BIN
      assets/evil_eye_test-256.png
  9. BIN
      assets/evil_eye_test-512.png
  10. BIN
      assets/evileye.png
  11. BIN
      assets/floor_tile_test-256.png
  12. BIN
      assets/floor_tile_test-512.png
  13. BIN
      assets/portal.png
  14. BIN
      assets/teleporter.png
  15. BIN
      assets/tile01.png
  16. BIN
      assets/tile02.png
  17. BIN
      assets/tile03.png
  18. BIN
      assets/tile05.png
  19. BIN
      assets/tile06.png
  20. BIN
      assets/tile07.png
  21. BIN
      assets/tile08.png
  22. BIN
      assets/tile09.png
  23. BIN
      assets/tile10.png
  24. BIN
      assets/tile11.png
  25. BIN
      assets/tile12.png
  26. BIN
      assets/tile13.png
  27. BIN
      assets/tile15.png
  28. BIN
      assets/tile16.png
  29. BIN
      assets/tile17.png
  30. BIN
      assets/tile30.png
  31. BIN
      assets/tile31.png
  32. BIN
      assets/tile32.png
  33. BIN
      assets/wall_texture_test-256.png
  34. BIN
      assets/wall_texture_test-512.png
  35. BIN
      assets/wood_barrel_large-256.png
  36. BIN
      assets/wood_barrel_large-512.png
  37. BIN
      assets/wood_wall-256.png
  38. BIN
      assets/wood_wall-512.png
  39. 4
      constants.hpp
  40. 29
      raycaster.cpp
  41. 18
      texture.cpp
  42. 14
      texture.hpp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 75 KiB

@ -1,15 +1,17 @@
{
"textures": [
"assets/tile01.png",
"assets/tile16.png",
"assets/tile02.png",
"assets/tile03.png",
"assets/tile05.png",
"assets/tile17.png"
"assets/floor_tile_test-512.png",
"assets/wall_texture_test-512.png",
"assets/ceiling_test-512.png",
"assets/wood_wall-512.png"
],
"sprites": [
"assets/portal.png"
"assets/armored_knight_1-512.png",
"assets/cinqueda_1-512.png",
"assets/wood_barrel_large-512.png",
"assets/evil_eye_test-512.png",
"assets/undead_peasant-256.png"
],
"floor": "assets/tile32.png",
"ceiling": "assets/tile10.png"
"floor": "assets/floor_tile_test-512.png",
"ceiling": "assets/ceiling_test-512.png"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 405 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 335 KiB

@ -1,7 +1,7 @@
#pragma once
constexpr const int TEXTURE_WIDTH=256;
constexpr const int TEXTURE_HEIGHT=256;
constexpr const int TEXTURE_WIDTH=512;
constexpr const int TEXTURE_HEIGHT=512;
constexpr const int RAY_VIEW_WIDTH=960;
constexpr const int RAY_VIEW_HEIGHT=720;
constexpr const int RAY_VIEW_X=(1280 - RAY_VIEW_WIDTH);

@ -65,8 +65,8 @@ void Raycaster::clear() {
}
void Raycaster::sprite_casting() {
const int textureWidth = $textures.TEXTURE_WIDTH;
const int textureHeight = $textures.TEXTURE_HEIGHT;
const int textureWidth = TEXTURE_WIDTH;
const int textureHeight = TEXTURE_HEIGHT;
// sort sprites from far to close
for(int i = 0; i < $textures.NUM_SPRITES; i++) {
@ -126,7 +126,7 @@ void Raycaster::sprite_casting() {
if(!(transformY > 0 && transformY < ZBuffer[stripe])) break;
}
int texX_end = int(256 * (stripe - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 256;
int texX_end = int(512 * (stripe - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 512;
if(drawStartX < drawEndX && transformY > 0 && transformY < ZBuffer[drawStartX]) {
int vMoveScreen = int(sprite_rec.elevation * -1 / transformY);
@ -136,15 +136,15 @@ void Raycaster::sprite_casting() {
int drawEndY = spriteHeight / 2 + $height / 2 + vMoveScreen;
if(drawEndY >= $height) drawEndY = $height - 1;
int texX = int(256 * (drawStartX - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 256;
int texX = int(512 * (drawStartX - (-spriteWidth / 2 + spriteScreenX)) * textureWidth / spriteWidth) / 512;
float x = float(drawStartX + RAY_VIEW_X);
float y = float(drawStartY + RAY_VIEW_Y);
float sprite_w = float(spriteWidth) / float(textureWidth);
float sprite_h = float(spriteHeight) / float(textureHeight);
int d = (y - vMoveScreen) * 256 - $height * 128 + spriteHeight * 128;
int texY = ((d * textureHeight) / spriteHeight) / 256;
int d = (y - vMoveScreen) * 512 - $height * 256 + spriteHeight * 256;
int texY = ((d * textureHeight) / spriteHeight) / 512;
sf_sprite->setScale({sprite_w, sprite_h});
sf_sprite->setTextureRect(sf::IntRect({texX, texY}, {texX_end - texX, textureHeight}));
@ -155,8 +155,8 @@ void Raycaster::sprite_casting() {
}
void Raycaster::cast_rays() {
constexpr static const int textureWidth = $textures.TEXTURE_WIDTH;
constexpr static const int textureHeight = $textures.TEXTURE_HEIGHT;
constexpr static const int textureWidth = TEXTURE_WIDTH;
constexpr static const int textureHeight = TEXTURE_HEIGHT;
double perpWallDist;
// WALL CASTING
@ -229,7 +229,7 @@ void Raycaster::cast_rays() {
int drawEnd = lineHeight / 2 + $height / 2 + $pitch;
if(drawEnd >= $height) drawEnd = $height - 1;
auto &texture = $textures.get_texture($map[mapY][mapX] - 1);
auto texture = $textures.get_texture($map[mapY][mapX] - 1);
// calculate value of wallX
double wallX; // where exactly the wall was hit
@ -265,8 +265,8 @@ void Raycaster::cast_rays() {
}
void Raycaster::draw_ceiling_floor() {
constexpr static const int textureWidth = $textures.TEXTURE_WIDTH;
constexpr static const int textureHeight = $textures.TEXTURE_HEIGHT;
constexpr static const int textureWidth = TEXTURE_WIDTH;
constexpr static const int textureHeight = TEXTURE_HEIGHT;
for(int y = $height / 2 + 1; y < $height; ++y) {
// rayDir for leftmost ray (x=0) and rightmost (x = w)
@ -300,6 +300,9 @@ void Raycaster::draw_ceiling_floor() {
float floorX = $posX + rowDistance * rayDirX0;
float floorY = $posY + rowDistance * rayDirY0;
auto floor_texture = (const uint32_t *)$textures.floor.getPixelsPtr();
auto ceiling_texture = (const uint32_t *)$textures.ceiling.getPixelsPtr();
for(int x = 0; x < $width; ++x) {
// the cell coord is simply taken from the int parts of
// floorX and floorY.
@ -319,11 +322,11 @@ void Raycaster::draw_ceiling_floor() {
// floorX cellX to find the texture x/y. How?
// FLOOR
color = $textures.floor[textureWidth * ty + tx];
color = floor_texture[textureWidth * ty + tx];
$pixels[pixcoord(x, y)] = color;
// CEILING
color = $textures.ceiling[textureWidth * ty + tx];
color = ceiling_texture[textureWidth * ty + tx];
$pixels[pixcoord(x, $height - y - 1)] = color;
}
}

@ -3,16 +3,12 @@
#include "dbc.hpp"
#include <fmt/core.h>
#include "config.hpp"
#include "constants.hpp"
Image TexturePack::load_image(std::string filename) {
Image texture(TEXTURE_WIDTH * TEXTURE_HEIGHT);
sf::Image img;
bool good = img.loadFromFile(filename);
sf::Image TexturePack::load_image(std::string filename) {
sf::Image texture;
bool good = texture.loadFromFile(filename);
dbc::check(good, fmt::format("failed to load {}", filename));
uint32_t *pixbuf = (uint32_t *)img.getPixelsPtr();
std::copy_n(pixbuf, texture.size(), texture.begin());
return texture;
}
@ -29,7 +25,7 @@ void TexturePack::load_textures() {
floor = load_image(assets["floor"]);
ceiling = load_image(assets["ceiling"]);
sf::Texture* sprite_texture = new sf::Texture("assets/evil_eye_test-256.png");
sf::Texture* sprite_texture = new sf::Texture("assets/evil_eye_test-512.png");
sprite_texture->setSmooth(false);
sf::Sprite* sf_sprite = new sf::Sprite(*sprite_texture);
sprites.push_back({4.0, 3.55, 6, sf_sprite, sprite_texture});
@ -39,8 +35,8 @@ void TexturePack::load_textures() {
sword.sprite = new sf::Sprite(*sword.sprite_texture);
}
Image& TexturePack::get_texture(size_t num) {
return images[num];
const uint32_t* TexturePack::get_texture(size_t num) {
return (const uint32_t *)images[num].getPixelsPtr();
}
Sprite &TexturePack::get_sprite(size_t sprite_num) {

@ -17,21 +17,17 @@ struct Sprite {
int vDiv=1;
};
using Image = std::vector<uint32_t>;
struct TexturePack {
int NUM_SPRITES=1;
constexpr static const int TEXTURE_WIDTH=256; // must be power of two
constexpr static const int TEXTURE_HEIGHT=256; // must be power of two
std::vector<Image> images;
std::vector<sf::Image> images;
std::vector<Sprite> sprites;
Image floor;
Image ceiling;
sf::Image floor;
sf::Image ceiling;
Sprite sword;
void load_textures();
std::vector<uint32_t> load_image(std::string filename);
sf::Image load_image(std::string filename);
Sprite& get_sprite(size_t sprite_num);
Image& get_texture(size_t num);
const uint32_t* get_texture(size_t num);
};

Loading…
Cancel
Save