302. Decodificar atributos de sprite
Decodificar un byte de atributos de sprite en crudo.
Lección 302 de 356 · tests/chapter_09_sprite_rendering/test_302_decode_sprite_attributes.py
Archivo a actualizar
emulator/rendering/sprite_renderer.pyPor qué existe este paso
El paso anterior definió SpriteAttributes. Ahora convertimos el byte de atributos en crudo de OAM en esa estructura decodificada.
Ejemplo de implementación sugerido
def decode_sprite_attributes(attributes: int) -> SpriteAttributes:
attributes &= 0xFF
return SpriteAttributes(
palette_id=attributes & SPRITE_PALETTE_ID_MASK,
is_behind_background=(attributes & SPRITE_IS_BEHIND_BACKGROUND) != 0,
flip_horizontal=(attributes & SPRITE_FLIP_HORIZONTAL) != 0,
flip_vertical=(attributes & SPRITE_FLIP_VERTICAL) != 0,
)Ejemplo
attributes = 0b1110_0011Significado
palette_id = 3
is_behind_background = True
flip_horizontal = True
flip_vertical = TrueBits 2-4
Se ignoran por ahora. No lanzar excepción si están activos.
Fuera del alcance
- helper de paleta de sprite en RAM
- renderizado de píxeles
- sprite 0 hit
- sprite overflow
- pygame
Ejecutar esta lección
uv run pytest tests/chapter_09_sprite_rendering/test_302_decode_sprite_attributes.py -v