Sprite is no more, now using the position from the level's world.
This commit is contained in:
parent
d0badedbd9
commit
d5301acab5
3 changed files with 9 additions and 14 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <numbers>
|
#include <numbers>
|
||||||
|
#include "components.hpp"
|
||||||
|
|
||||||
using namespace fmt;
|
using namespace fmt;
|
||||||
using std::make_unique;
|
using std::make_unique;
|
||||||
|
@ -69,12 +70,12 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) {
|
||||||
|
|
||||||
// after sorting the sprites, do the projection
|
// after sorting the sprites, do the projection
|
||||||
for(auto& rec : sprite_order) {
|
for(auto& rec : sprite_order) {
|
||||||
const Sprite& sprite_rec = $sprites.at(rec.second);
|
// BUG: eventually this needs to go away too
|
||||||
// TODO: this must die
|
auto& sf_sprite = $sprites.at(rec.second).sprite;
|
||||||
auto sf_sprite = sprite_rec.sprite.sprite;
|
auto sprite_pos = $level.world->get<components::Position>(rec.second);
|
||||||
|
|
||||||
double spriteX = sprite_rec.x - $posX;
|
double spriteX = double(sprite_pos.location.x) - $posX + 0.5;
|
||||||
double spriteY = sprite_rec.y - $posY;
|
double spriteY = double(sprite_pos.location.y) - $posY + 0.5;
|
||||||
|
|
||||||
//transform sprite with the inverse camera matrix
|
//transform sprite with the inverse camera matrix
|
||||||
// [ $planeX $dirX ] -1 [ $dirY -$dirX ]
|
// [ $planeX $dirX ] -1 [ $dirY -$dirX ]
|
||||||
|
@ -335,6 +336,6 @@ void Raycaster::set_level(GameLevel level) {
|
||||||
// this will need to go away too but for now everything is evil eye
|
// this will need to go away too but for now everything is evil eye
|
||||||
for(auto &thing : $level.collision->table) {
|
for(auto &thing : $level.collision->table) {
|
||||||
auto sprite_txt = $textures.sprite_textures.at("evil_eye");
|
auto sprite_txt = $textures.sprite_textures.at("evil_eye");
|
||||||
$sprites.try_emplace(thing.second, thing.first.x + 0.5, thing.first.y + 0.5, sprite_txt);
|
$sprites.try_emplace(thing.second, sprite_txt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include "texture.hpp"
|
|
||||||
#include <SFML/System/Clock.hpp>
|
#include <SFML/System/Clock.hpp>
|
||||||
|
#include "texture.hpp"
|
||||||
#include "animator.hpp"
|
#include "animator.hpp"
|
||||||
#include "spatialmap.hpp"
|
#include "spatialmap.hpp"
|
||||||
#include "levelmanager.hpp"
|
#include "levelmanager.hpp"
|
||||||
|
@ -34,7 +34,7 @@ struct Raycaster {
|
||||||
int $height;
|
int $height;
|
||||||
GameLevel $level;
|
GameLevel $level;
|
||||||
Matrix $map;
|
Matrix $map;
|
||||||
std::unordered_map<DinkyECS::Entity, Sprite> $sprites;
|
std::unordered_map<DinkyECS::Entity, SpriteTexture> $sprites;
|
||||||
std::vector<double> ZBuffer; // width
|
std::vector<double> ZBuffer; // width
|
||||||
Animator $anim;
|
Animator $anim;
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,6 @@ struct SpriteTexture {
|
||||||
std::shared_ptr<sf::Texture> texture = nullptr;
|
std::shared_ptr<sf::Texture> texture = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Sprite {
|
|
||||||
double x;
|
|
||||||
double y;
|
|
||||||
SpriteTexture sprite;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TexturePack {
|
struct TexturePack {
|
||||||
std::vector<sf::Image> surfaces;
|
std::vector<sf::Image> surfaces;
|
||||||
std::unordered_map<std::string, SpriteTexture> sprite_textures;
|
std::unordered_map<std::string, SpriteTexture> sprite_textures;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue