Player Movement
Player movement is handled byengine/overworld/movement.asm and processes sprite updates every frame.
Update Cycle
TheUpdatePlayerSprite function is the core of overworld rendering:
Animation Counter Check
First checks if a walk animation is in progress by examining the animation counter.
Tile Detection
Checks what tile the player is standing on to determine if a text box or menu is blocking the sprite.
Direction Processing
Determines which direction the player is facing and updates the sprite accordingly.
Direction System
The game uses bit flags to track player direction:Movement State Machine
The walk animation cycles through 4 frames (0-3) for smooth movement. Each frame is held for multiple update cycles based on the intra-frame counter.
Tile Interaction
The game distinguishes between map tiles and UI elements:Tile IDs below
$60 (96) are map tiles. Higher IDs represent text boxes and menus, which hide the player sprite when active.Grass Priority
A special rendering trick makes the player appear to walk through tall grass:Sprite Animation
Sprites use two counters for smooth animation:- Intra-frame counter (
wSpritePlayerStateData1IntraAnimFrameCounter): Counts up to 4 before advancing the frame - Animation frame counter (
wSpritePlayerStateData1AnimFrameCounter): Current animation frame (0-3)
Map Structure
Maps are defined with dimensions and unique IDs inconstants/map_constants.asm:
Maps are organized by type: cities first, then routes, then indoor locations. Each map definition includes width and height in tiles. The macro automatically generates
MAP_WIDTH and MAP_HEIGHT constants.Map Groups
Indoor maps are grouped by their associated outdoor location:- Map headers (tiles, connections, objects)
- Sprite sets
- Music tracks
- Wild encounter data
- Toggleable objects (items, hidden items)
Collision Detection
The engine performs several types of collision checks:Sprite-to-Sprite Collision
Sprite-to-Sprite Collision
DetectCollisionBetweenSprites checks if the player overlaps with any NPCs or objects to trigger interactions.Tile Collision
Tile Collision
Certain tiles (walls, ledges, water) block movement unless the player has the appropriate ability (Surf, etc.).
Map Boundaries
Map Boundaries
Prevents the player from walking off the edge of the map or triggers map transitions when crossing connection points.
Movement Flags
Special movement states are tracked with bit flags:Walking Counter
ThewWalkCounter variable tracks movement progress between tiles:
- Value of 0: Player is standing still
- Non-zero: Player is mid-transition between tiles
Sprite State Data
Each sprite (including the player) maintains state data in RAM:wSpritePlayerStateData1ImageIndex- Current sprite framewSpritePlayerStateData1FacingDirection- Direction sprite is facingwSpritePlayerStateData1IntraAnimFrameCounter- Sub-frame counterwSpritePlayerStateData1AnimFrameCounter- Animation frame (0-3)wSpritePlayerStateData2GrassPriority- Priority flag for grass renderingwSpritePlayerStateData2WalkAnimationCounter- Walk animation timer
Font Loading
The system checks if fonts are loaded before allowing movement animations:Maps
Map data and structure
Battle Engine
Wild battles and transitions
Reference
Map and sprite constants
Engine Modules
Overworld engine implementation
Key Files
engine/overworld/movement.asm- Player sprite and movementengine/overworld/- All overworld systemsconstants/map_constants.asm- Map IDs and dimensionsconstants/map_object_constants.asm- Sprite object constantsmaps/- Individual map data filesdata/maps/- Map headers and metadata