overworld sprite cleanup

This commit is contained in:
scawful
2024-08-20 13:06:35 -04:00
parent 49611d4944
commit e404eabe64
5 changed files with 101 additions and 116 deletions

View File

@@ -6,57 +6,13 @@ namespace yaze {
namespace app {
namespace zelda3 {
void Sprite::InitSprite(const std::vector<uint8_t>& src, uchar mapid, uchar id, uchar x,
uchar y, int map_x, int map_y) {
current_gfx_ = src;
overworld_ = true;
map_id_ = static_cast<int>(mapid);
id_ = id;
this->type_ = zelda3::OverworldEntity::EntityType::kSprite;
this->entity_id_ = id;
this->x_ = map_x_;
this->y_ = map_y_;
nx_ = x;
ny_ = y;
name_ = core::kSpriteDefaultNames[id];
map_x_ = map_x;
map_y_ = map_y;
preview_gfx_.reserve(64 * 64);
for (int i = 0; i < 64 * 64; i++) {
preview_gfx_.push_back(0xFF);
}
}
Sprite::Sprite(std::vector<uint8_t> src, uchar mapid, uchar id, uchar x, uchar y, int map_x,
int map_y)
: current_gfx_(src),
map_id_(static_cast<int>(mapid)),
id_(id),
nx_(x),
ny_(y),
map_x_(map_x),
map_y_(map_y) {
this->type_ = zelda3::OverworldEntity::EntityType::kSprite;
this->entity_id_ = id;
this->x_ = map_x_;
this->y_ = map_y_;
current_gfx_ = src;
overworld_ = true;
name_ = core::kSpriteDefaultNames[id];
preview_gfx_.reserve(64 * 64);
for (int i = 0; i < 64 * 64; i++) {
preview_gfx_.push_back(0xFF);
}
}
void Sprite::UpdateMapProperties(short map_id) {
map_x_ = x_;
map_y_ = y_;
name_ = core::kSpriteDefaultNames[id_];
}
void Sprite::updateCoordinates(int map_x, int map_y) {
void Sprite::UpdateCoordinates(int map_x, int map_y) {
map_x_ = map_x;
map_y_ = map_y;
}
@@ -69,8 +25,8 @@ void Sprite::updateBBox() {
}
void Sprite::Draw() {
uchar x = nx_;
uchar y = ny_;
uint8_t x = nx_;
uint8_t y = ny_;
if (overlord_ == 0x07) {
if (id_ == 0x1A) {
@@ -123,22 +79,22 @@ void Sprite::Draw() {
} else if (id_ == 0x02) {
DrawSpriteTile((x * 16), (y * 16), 0, 16, 10);
} else if (id_ == 0x04) {
uchar p = 3;
uint8_t p = 3;
DrawSpriteTile((x * 16), (y * 16), 14, 28, p);
DrawSpriteTile((x * 16), (y * 16), 14, 30, p);
} else if (id_ == 0x05) {
uchar p = 3;
uint8_t p = 3;
DrawSpriteTile((x * 16), (y * 16), 14, 28, p);
DrawSpriteTile((x * 16), (y * 16), 14, 30, p);
} else if (id_ == 0x06) {
uchar p = 3;
uint8_t p = 3;
DrawSpriteTile((x * 16), (y * 16), 14, 28, p);
DrawSpriteTile((x * 16), (y * 16), 14, 30, p);
} else if (id_ == 0x07) {
uchar p = 3;
uint8_t p = 3;
DrawSpriteTile((x * 16), (y * 16), 14, 28, p);
DrawSpriteTile((x * 16), (y * 16), 14, 30, p);
@@ -948,7 +904,7 @@ void Sprite::DrawSpriteTile(int x, int y, int srcx, int srcy, int pal,
int index = (x) + (y * 64) + (mx + (my * 0x80));
if (index >= 0 && index <= 4096) {
preview_gfx_[index] = (uchar)((pixel & 0x0F) + 112 + (pal * 8));
preview_gfx_[index] = (uint8_t)((pixel & 0x0F) + 112 + (pal * 8));
}
}
}

View File

@@ -26,10 +26,42 @@ namespace zelda3 {
class Sprite : public OverworldEntity {
public:
Sprite() = default;
Sprite(std::vector<uint8_t> src, uchar mapid, uchar id, uchar x, uchar y, int map_x,
int map_y);
void InitSprite(const std::vector<uint8_t>& src, uchar mapid, uchar id, uchar x, uchar y,
int map_x, int map_y);
Sprite(std::vector<uint8_t> src, uint8_t mapid, uint8_t id, uint8_t x,
uint8_t y, int map_x, int map_y)
: current_gfx_(src),
map_id_(static_cast<int>(mapid)),
id_(id),
nx_(x),
ny_(y),
map_x_(map_x),
map_y_(map_y) {
type_ = zelda3::OverworldEntity::EntityType::kSprite;
entity_id_ = id;
x_ = map_x_;
y_ = map_y_;
current_gfx_ = src;
overworld_ = true;
name_ = core::kSpriteDefaultNames[id];
preview_gfx_.resize(64 * 64, 0xFF);
}
void InitSprite(const std::vector<uint8_t>& src, uint8_t mapid, uint8_t id,
uint8_t x, uint8_t y, int map_x, int map_y) {
current_gfx_ = src;
overworld_ = true;
map_id_ = static_cast<int>(mapid);
id_ = id;
type_ = zelda3::OverworldEntity::EntityType::kSprite;
entity_id_ = id;
x_ = map_x_;
y_ = map_y_;
nx_ = x;
ny_ = y;
name_ = core::kSpriteDefaultNames[id];
map_x_ = map_x;
map_y_ = map_y;
preview_gfx_.resize(64 * 64, 0xFF);
}
void updateBBox();
void Draw();
@@ -40,11 +72,11 @@ class Sprite : public OverworldEntity {
void UpdateMapProperties(short map_id) override;
// New methods
void updateCoordinates(int map_x, int map_y);
void UpdateCoordinates(int map_x, int map_y);
auto PreviewGraphics() const { return preview_gfx_; }
auto id() const { return id_; }
auto set_id(uchar id) { id_ = id; }
auto set_id(uint8_t id) { id_ = id; }
auto x() const { return x_; }
auto y() const { return y_; }
auto nx() const { return nx_; }
@@ -52,6 +84,7 @@ class Sprite : public OverworldEntity {
auto map_id() const { return map_id_; }
auto map_x() const { return map_x_; }
auto map_y() const { return map_y_; }
auto game_state() const { return game_state_; }
auto layer() const { return layer_; }
auto subtype() const { return subtype_; }
@@ -64,36 +97,33 @@ class Sprite : public OverworldEntity {
auto set_deleted(bool deleted) { deleted_ = deleted; }
private:
std::vector<uint8_t> current_gfx_;
bool overworld_;
uchar map_id_;
uchar id_;
// uchar x_;
// uchar y_;
uchar nx_;
uchar ny_;
uchar overlord_ = 0;
std::string name_;
int subtype_;
int layer_;
int map_x_;
int map_y_;
std::vector<uint8_t> preview_gfx_;
uchar lowerX_;
uchar lowerY_;
uchar higherX_;
uchar higherY_;
SDL_Rect bounding_box_;
uint8_t map_id_;
uint8_t game_state_;
uint8_t id_;
uint8_t nx_;
uint8_t ny_;
uint8_t overlord_ = 0;
uint8_t lowerX_;
uint8_t lowerY_;
uint8_t higherX_;
uint8_t higherY_;
int width_ = 16;
int height_ = 16;
int map_x_;
int map_y_;
int layer_;
int subtype_;
int key_drop_;
bool deleted_ = false;
bool overworld_;
std::string name_;
std::vector<uint8_t> preview_gfx_;
std::vector<uint8_t> current_gfx_;
SDL_Rect bounding_box_;
};
} // namespace zelda3