Refactor sprite handling for consistency by standardizing variable naming and improving constructor initialization

This commit is contained in:
scawful
2024-11-08 00:13:01 -05:00
parent 1c8285a498
commit 749defd1d4
3 changed files with 37 additions and 24 deletions

View File

@@ -7,7 +7,7 @@ namespace yaze {
namespace app { namespace app {
namespace zelda3 { namespace zelda3 {
static const std::string overlordnames[] = { static const std::string kOverlordNames[] = {
"Overlord_SpritePositionTarget", "Overlord_SpritePositionTarget",
"Overlord_AllDirectionMetalBallFactory", "Overlord_AllDirectionMetalBallFactory",
"Overlord_CascadeMetalBallFactory", "Overlord_CascadeMetalBallFactory",

View File

@@ -18,10 +18,10 @@ void Sprite::UpdateCoordinates(int map_x, int map_y) {
} }
void Sprite::UpdateBoundaryBox() { void Sprite::UpdateBoundaryBox() {
lowerX_ = 1; lower_x_ = 1;
lowerY_ = 1; lower_y_ = 1;
higherX_ = 15; higher_x_ = 15;
higherY_ = 15; higher_x_ = 15;
} }
void Sprite::Draw() { void Sprite::Draw() {
@@ -57,13 +57,13 @@ void Sprite::Draw() {
} }
if (nx_ != x || ny_ != y) { if (nx_ != x || ny_ != y) {
bounding_box_.x = (lowerX_ + (nx_ * 16)); bounding_box_.x = (lower_x_ + (nx_ * 16));
bounding_box_.y = (lowerY_ + (ny_ * 16)); bounding_box_.y = (lower_y_ + (ny_ * 16));
bounding_box_.w = width_; bounding_box_.w = width_;
bounding_box_.h = height_; bounding_box_.h = height_;
} else { } else {
bounding_box_.x = (lowerX_ + (x * 16)); bounding_box_.x = (lower_x_ + (x * 16));
bounding_box_.y = (lowerY_ + (y * 16)); bounding_box_.y = (lower_y_ + (y * 16));
bounding_box_.w = width_; bounding_box_.w = width_;
bounding_box_.h = height_; bounding_box_.h = height_;
} }
@@ -864,8 +864,8 @@ void Sprite::Draw() {
DrawSpriteTile((x * 16), (y * 16), 4, 4, 5); DrawSpriteTile((x * 16), (y * 16), 4, 4, 5);
} }
bounding_box_.x = (lowerX_ + (x * 16)); bounding_box_.x = (lower_x_ + (x * 16));
bounding_box_.y = (lowerY_ + (y * 16)); bounding_box_.y = (lower_y_ + (y * 16));
bounding_box_.w = width_; bounding_box_.w = width_;
bounding_box_.h = height_; bounding_box_.h = height_;
} }

View File

@@ -8,6 +8,7 @@
#include <vector> #include <vector>
#include "app/zelda3/common.h" #include "app/zelda3/common.h"
#include "app/zelda3/sprite/overlord.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -297,7 +298,18 @@ class Sprite : public GameEntity {
preview_gfx_.resize(64 * 64, 0xFF); preview_gfx_.resize(64 * 64, 0xFF);
} }
void InitSprite(const std::vector<uint8_t>& src, uint8_t overworld_map_id, Sprite(uint8_t id, uint8_t x, uint8_t y, uint8_t subtype, uint8_t layer)
: id_(id), nx_(x), ny_(y), subtype_(subtype), layer_(layer) {
x_ = x;
y_ = y;
name_ = kSpriteDefaultNames[id];
if (((subtype & 0x07) == 0x07) && id > 0 && id <= 0x1A) {
name_ = kOverlordNames[id - 1];
overlord_ = 1;
}
}
void InitSprite(const std::vector<uint8_t> &src, uint8_t overworld_map_id,
uint8_t id, uint8_t x, uint8_t y, int map_x, int map_y) { uint8_t id, uint8_t x, uint8_t y, int map_x, int map_y) {
current_gfx_ = src; current_gfx_ = src;
overworld_ = true; overworld_ = true;
@@ -341,11 +353,12 @@ class Sprite : public GameEntity {
auto layer() const { return layer_; } auto layer() const { return layer_; }
auto subtype() const { return subtype_; } auto subtype() const { return subtype_; }
auto Width() const { return bounding_box_.w; } auto width() const { return bounding_box_.w; }
auto Height() const { return bounding_box_.h; } auto height() const { return bounding_box_.h; }
auto name() { return name_; } auto name() { return name_; }
auto deleted() const { return deleted_; } auto deleted() const { return deleted_; }
auto set_deleted(bool deleted) { deleted_ = deleted; } auto set_deleted(bool deleted) { deleted_ = deleted; }
auto set_key_drop(int key) { key_drop_ = key; }
private: private:
uint8_t map_id_; uint8_t map_id_;
@@ -354,18 +367,18 @@ class Sprite : public GameEntity {
uint8_t nx_; uint8_t nx_;
uint8_t ny_; uint8_t ny_;
uint8_t overlord_ = 0; uint8_t overlord_ = 0;
uint8_t lowerX_; uint8_t lower_x_ = 32;
uint8_t lowerY_; uint8_t lower_y_ = 32;
uint8_t higherX_; uint8_t higher_x_ = 0;
uint8_t higherY_; uint8_t higher_y_ = 0;
int width_ = 16; int width_ = 16;
int height_ = 16; int height_ = 16;
int map_x_; int map_x_ = 0;
int map_y_; int map_y_ = 0;
int layer_; int layer_ = 0;
int subtype_; int subtype_ = 0;
int key_drop_; int key_drop_ = 0;
bool deleted_ = false; bool deleted_ = false;
bool overworld_; bool overworld_;