Worm riding - codingstyle/swift-dune GitHub Wiki
Worm riding animation relies on several sprites :
SKY.HSQ
is responsible for the sky and define the background paletteDUNES.HSQ
is used for scrolling dunes and give a motion effectVER.HSQ
contains sprites for the worm ride
The animation consists in sprites of different worm rings moved using a parallax effect to create depth.
Animations are stored in a separate file: VERBIN.HSQ
.
First 88 bytes are designed for an animation not identified yet.
Then 39 frames are defined. Each frame is made of series of 3 bytes (sprite index, x, y) and terminated with a 0x0 byte, to the exception of the last frame. Sprite indexes start at 1 in the file, so you must substract 1 to have the correct index.
Finally, last part contains animations definitions. It's made of series of UINT16LE representing frame indexes. Each animation is terminated by a 0xFF marker byte. Frame indexes start at 2 in the file, so make sure to substract 2 for each to have the correct frame referenced.
Algorithm
// Skip first 88 bytes until that block is reverse-engineered :)
SEEK(88)
FRAMES = []
SPRITE_ARRAY = []
WHILE FILE_OFFSET < 577
IF PEEK_UINT8() == 0X0
FRAMES.ADD(SPRITE_ARRAY)
SPRITE_ARRAY = []
ENDIF
SPRITE_INDEX = READ_UINT8() - 1
X = READ_UINT8()
Y = READ_UINT8()
SPRITE_ARRAY.ADD({ SPRITE_INDEX, X, Y })
ENDWHILE
// Add remaining sprites to the last frame
FRAMES.ADD(SPRITE_ARRAY)
ANIMATIONS = []
ANIMATION = []
WHILE !EOF()
IF PEEK_UINT8() == 0xFF
ANIMATIONS.ADD(ANIMATION)
ANIMATION = []
ENDIF
IF EOF()
BREAK
ENDIF
FRAME_INDEX = READ_UINT16() - 2
ANIMATION.ADD(FRAME_INDEX)
ENDWHILE
File interpretation
- 🟦 = sprite index
- 🟩 = coordinates (X,Y)
- 🟧 = frame end marker
- 🟪 = frame index
- 🟧 = animation end marker