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 <memory>
|
||||
#include <numbers>
|
||||
#include "components.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
using std::make_unique;
|
||||
|
@ -69,12 +70,12 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) {
|
|||
|
||||
// after sorting the sprites, do the projection
|
||||
for(auto& rec : sprite_order) {
|
||||
const Sprite& sprite_rec = $sprites.at(rec.second);
|
||||
// TODO: this must die
|
||||
auto sf_sprite = sprite_rec.sprite.sprite;
|
||||
// BUG: eventually this needs to go away too
|
||||
auto& sf_sprite = $sprites.at(rec.second).sprite;
|
||||
auto sprite_pos = $level.world->get<components::Position>(rec.second);
|
||||
|
||||
double spriteX = sprite_rec.x - $posX;
|
||||
double spriteY = sprite_rec.y - $posY;
|
||||
double spriteX = double(sprite_pos.location.x) - $posX + 0.5;
|
||||
double spriteY = double(sprite_pos.location.y) - $posY + 0.5;
|
||||
|
||||
//transform sprite with the inverse camera matrix
|
||||
// [ $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
|
||||
for(auto &thing : $level.collision->table) {
|
||||
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
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "texture.hpp"
|
||||
#include <SFML/System/Clock.hpp>
|
||||
#include "texture.hpp"
|
||||
#include "animator.hpp"
|
||||
#include "spatialmap.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
|
@ -34,7 +34,7 @@ struct Raycaster {
|
|||
int $height;
|
||||
GameLevel $level;
|
||||
Matrix $map;
|
||||
std::unordered_map<DinkyECS::Entity, Sprite> $sprites;
|
||||
std::unordered_map<DinkyECS::Entity, SpriteTexture> $sprites;
|
||||
std::vector<double> ZBuffer; // width
|
||||
Animator $anim;
|
||||
|
||||
|
|
|
@ -13,12 +13,6 @@ struct SpriteTexture {
|
|||
std::shared_ptr<sf::Texture> texture = nullptr;
|
||||
};
|
||||
|
||||
struct Sprite {
|
||||
double x;
|
||||
double y;
|
||||
SpriteTexture sprite;
|
||||
};
|
||||
|
||||
struct TexturePack {
|
||||
std::vector<sf::Image> surfaces;
|
||||
std::unordered_map<std::string, SpriteTexture> sprite_textures;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue