-
Notifications
You must be signed in to change notification settings - Fork 51
Maps
Zal0 edited this page Oct 9, 2021
·
3 revisions
Let's now focus on the creation of our game level.
- Open the file res/map.bgm with the Game Boy Map Builder and create your stage. This is how mine looks like
Save (don't export!) and make a build. If you are unlucky something like this will happen
The enemy has been spawned in the middle of a wall
- Luckily ZGB will let you place enemies on the map using the Game Boy Map Builder. This thing is accomplished by the function GetTileReplacement in ZGBMain.c
UINT8 GetTileReplacement(UINT8* tile_ptr, UINT8* tile) {
if(current_state == StateGame) {
if(U_LESS_THAN(255 - (UINT16)*tile_ptr, N_SPRITE_TYPES)) {
*tile = 0;
return 255 - (UINT16)*tile_ptr;
}
*tile = *tile_ptr;
}
return 255u;
}
-
This function is called for any tile that its placed in the background.
- It receives a UINT8* pointing to the tile that will be placed
- It must return an Sprite_Type or 255 to spawn nothing.
- It must assign on tile the tile index that should go in the background (usually the same that was passed on tile_ptr except when spawning an enemy)
- This default function will spawn and enemy of type 0 when the tile is 255, and enemy of type 1 when the tile is 254, and enemy of type 2 when the tile is 253... and so on
-
Open the tiles.bgr with the Game Boy Tile Designer and go to View->Tile Count and set that to 255. Now edit the tile 254 that corresponds to the sprite of type 1 (SPRITE_ENEMY) and create a thumbnail of the enemy
Save it.
- Open the res/map.bgm again and scroll down the list of tiles. You should see the thumbnail on the tile 254. Put it on some places of your map
Export and Save.
- Build the program now and you should see enemies spawned on those places instead of the thumbnail
You will also see that the Sprite we were spawning by code is still there so make sure you delete the line we wrote to spawn it