From 3397f47071898b76a0e1c88f04579789db49643b Mon Sep 17 00:00:00 2001 From: Sarah Ohlin Date: Mon, 31 Oct 2022 21:47:59 -0400 Subject: [PATCH] fix: gravity particles on moving gravity flips appears in the right spot --- game/moving_tile.cpp | 3 +++ game/tilemap.cpp | 8 ++++---- game/tilemap.hpp | 8 +++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/game/moving_tile.cpp b/game/moving_tile.cpp index 32843c7..be7b1aa 100644 --- a/game/moving_tile.cpp +++ b/game/moving_tile.cpp @@ -2,6 +2,7 @@ #include "debug.hpp" #include "resource.hpp" +#include "tilemap.hpp" #include @@ -342,6 +343,8 @@ void moving_blob::m_sync_tiles() { tile.m_yp = tpos.y; tile.m_xv = m_xv; tile.m_yv = m_yv; + tile.m_t.m_x = tile.m_xp; + tile.m_t.m_y = tile.m_yp; debug::get() << "i = " << i << " " << tpos << "\n"; } } diff --git a/game/tilemap.cpp b/game/tilemap.cpp index 3c5411d..631d488 100644 --- a/game/tilemap.cpp +++ b/game/tilemap.cpp @@ -381,8 +381,8 @@ void tilemap::load(std::string str) { m_tiles.resize(m_xs * m_ys, tile::empty); std::istringstream ss(str); for (int i = 0; i < m_xs * m_ys; ++i) { - m_tiles[i].m_x = i % m_xs; - m_tiles[i].m_y = i / m_xs; + m_tiles[i].m_x = int(i % m_xs); + m_tiles[i].m_y = int(i / m_xs); if (ss.peek() == '/') { m_tiles[i].type = tile::empty; char ch; @@ -443,11 +443,11 @@ bool tile::operator!=(const tile_type&& type) const { return type != this->type; } -int tile::x() const { +float tile::x() const { return m_x; } -int tile::y() const { +float tile::y() const { return m_y; } diff --git a/game/tilemap.hpp b/game/tilemap.hpp index 8fe4c82..ea890f7 100644 --- a/game/tilemap.hpp +++ b/game/tilemap.hpp @@ -56,8 +56,8 @@ struct tile { bool operator!=(const tile_type&& type) const; // check if a tile is not of a given type operator int() const; // retrieve the texture index of the tile - int x() const; // x pos of the tile - int y() const; // y pos of the tile + float x() const; // x pos of the tile + float y() const; // y pos of the tile static std::string description(tile_type type); // a user-friendly description of the tile @@ -69,8 +69,10 @@ struct tile { bool editor_only() const; // tiles only visible in the editor private: friend class tilemap; + friend class moving_tile; + friend class moving_blob; tile(tile_type type, int x, int y); - int m_x = -1, m_y = -1; + float m_x = -1, m_y = -1; }; // stores and renders all static tiles in a level