mirror of
https://github.com/ssloy/tinyraycaster.git
synced 2025-01-16 12:49:38 +01:00
sprite positioning bugfix + a bit of cleaning
This commit is contained in:
parent
023d91cc1d
commit
e89e94af0e
@ -1,6 +1,3 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
|
||||
#include "framebuffer.h"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef FRAMEBUFFER_H
|
||||
#define FRAMEBUFFER_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
struct FrameBuffer {
|
||||
|
5
gui.cpp
5
gui.cpp
@ -3,12 +3,7 @@
|
||||
#include <algorithm>
|
||||
#include "SDL.h"
|
||||
|
||||
#include "map.h"
|
||||
#include "utils.h"
|
||||
#include "player.h"
|
||||
#include "sprite.h"
|
||||
#include "framebuffer.h"
|
||||
#include "textures.h"
|
||||
#include "tinyraycaster.h"
|
||||
|
||||
int main() {
|
||||
|
2
map.cpp
2
map.cpp
@ -1,6 +1,4 @@
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include "map.h"
|
||||
|
||||
static const char map[] = "0000222222220000"\
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include <cstdlib>
|
||||
#include "sprite.h"
|
||||
|
||||
bool Sprite::operator < (const Sprite& s) const {
|
||||
|
@ -1,6 +1,4 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
@ -1,6 +1,9 @@
|
||||
#ifndef TEXTURES_H
|
||||
#define TEXTURES_H
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
struct Texture {
|
||||
size_t img_w, img_h; // overall image dimensions
|
||||
size_t count, size; // number of textures and size in pixels
|
||||
|
@ -1,18 +1,9 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "map.h"
|
||||
#include "utils.h"
|
||||
#include "player.h"
|
||||
#include "sprite.h"
|
||||
#include "framebuffer.h"
|
||||
#include "textures.h"
|
||||
#include "tinyraycaster.h"
|
||||
|
||||
int wall_x_texcoord(const float hitx, const float hity, const Texture &tex_walls) {
|
||||
@ -49,8 +40,8 @@ void draw_sprite(FrameBuffer &fb, const Sprite &sprite, const std::vector<float>
|
||||
while (sprite_dir - player.a > M_PI) sprite_dir -= 2*M_PI; // remove unncesessary periods from the relative direction
|
||||
while (sprite_dir - player.a < -M_PI) sprite_dir += 2*M_PI;
|
||||
|
||||
size_t sprite_screen_size = std::min(1000, static_cast<int>(fb.h/sprite.player_dist)); // screen sprite size
|
||||
int h_offset = (sprite_dir - player.a)*(fb.w/2) + (fb.w/2)/2 - tex_sprites.size/2; // do not forget the 3D view takes only a half of the framebuffer
|
||||
size_t sprite_screen_size = std::min(2000, static_cast<int>(fb.h/sprite.player_dist)); // screen sprite size
|
||||
int h_offset = (sprite_dir - player.a)*(fb.w/2)/(player.fov) + (fb.w/2)/2 - sprite_screen_size/2; // do not forget the 3D view takes only a half of the framebuffer, thus fb.w/2 for the screen width
|
||||
int v_offset = fb.h/2 - sprite_screen_size/2;
|
||||
|
||||
for (size_t i=0; i<sprite_screen_size; i++) {
|
||||
|
@ -1,6 +1,14 @@
|
||||
#ifndef TINYRAYCASTER_H
|
||||
#define TINYRAYCASTER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "map.h"
|
||||
#include "player.h"
|
||||
#include "sprite.h"
|
||||
#include "framebuffer.h"
|
||||
#include "textures.h"
|
||||
|
||||
struct GameState {
|
||||
Map map;
|
||||
Player player;
|
||||
|
Loading…
x
Reference in New Issue
Block a user