diff --git a/engine/src/sprites/sprite.cpp b/engine/src/sprites/sprite.cpp index 19df17d..8969492 100644 --- a/engine/src/sprites/sprite.cpp +++ b/engine/src/sprites/sprite.cpp @@ -133,13 +133,13 @@ void Sprite::buildOam(int tileIndex) { if(!oam) { this->oam = std::unique_ptr(new OBJ_ATTR()); - this->oam->attr0 = ATTR0_Y(this->y) | + this->oam->attr0 = ATTR0_Y(this->y & 0x00FF) | ATTR0_MODE(0) | (GFX_MODE << 10) | (MOSAIC_MODE << 12) | (COLOR_MODE_256 << 13) | (this->shape_bits << 14); - this->oam->attr1 = this->x | + this->oam->attr1 = (this->x & 0x01FF) | (AFFINE_FLAG_NONE_SET_YET << 9) | (HORIZONTAL_FLIP_FLAG << 12) | (VERTICAL_FLIP_FLAG << 13) | diff --git a/test/spritetest.cpp b/test/spritetest.cpp index 42db11d..195cd78 100644 --- a/test/spritetest.cpp +++ b/test/spritetest.cpp @@ -182,6 +182,12 @@ public: SpriteWithStubOam() : Sprite(nullptr, imageSize, x, y, SIZE_8_8) { oam = std::unique_ptr(new OBJ_ATTR()); } + + OBJ_ATTR* buildOamForTesting() { + buildOam(0); + return oam.get(); + } + }; class SpriteSuite : public ::testing::Test { @@ -234,6 +240,16 @@ TEST_F(SpriteSuite, CollidesWith_B_Half_In_A_On_X_Axis_Collides) { ASSERT_TRUE(a->collidesWith(*b)); } +TEST_F(SpriteSuite, MovesToNegativeCoordsAreMaskedIntoOAM) { + s->moveTo(-10, -15); + auto oam = s->buildOamForTesting(); + auto attr0 = std::bitset<16>(oam->attr0).to_string(); + auto attr1 = std::bitset<16>(oam->attr1).to_string(); + + ASSERT_EQ(std::string("0000000011110001"), attr0); + ASSERT_EQ(std::string("0000000111110110"), attr1); +} + TEST_F(SpriteSuite, BuildingWithSize_SetsWidthAndHeight) { auto s = SpriteBuilder().withSize(SIZE_64_32).buildPtr(); ASSERT_EQ(64, s->getWidth());