Hey pico 8 community. I recently started making some demos and carts for myself and my friends. Although I have been struggling with collisions. Most tutorials use fget and mget. I want to use them, although I don't understand the parameters that are used.
I am not looking for a one size fits all code. I am just looking for a explanation for how they work, and what the parameters are used for and how they work in functions.
Thank you :D
-BEiNg139
The ultimate reference for how PICO-8 native functions work is always the PICO-8 Manual, you can read more about fget() and mget() there to learn the specifics of the parameters and return values, etc.
In short, mget()
will take map coordinates in x,y (tiles, not pixels) and return the sprite number that exists on the map at that tile. fget()
will take a sprite (number) as the first argument, and usually the flag value you want to check against as the second argument, and return true
or false
based on whether or not that flag is set for that sprite (either in the sprite editor from using fset()
)
By combining them, you can check if a given flag is present for (the sprite of) a given map tile.
fget(mget(tilex,tiley),1)
will return true
if the tile at map coords tilex,tiley is of a sprite with flag 1 set.
Because these coordinates are in map tiles and not pixels, you may often see the conversion from pixel coordinates to tile coordinates done in the same line:
fget(mget(x/8,y/8),f) |
However, this is just one step in map collision, checking if a given tile is "solid" (or death, or whatever else). How collisions will actually work in your game depends on the kind of game you want to make. For example, if you move in a Sokoban style (one whole tile at a time) you can check the single target adjacent tile and simply prevent the move if its solid. If you're making a game with a more precise style of movement (pixel by pixel) you will probably need to look into bounding boxes, and use a system that checks various pixel points around your player and prevents movement on a specific axis when certain points hit tiles with certain flags.
I hope this helps your understanding. Feel free to follow-up with any questions you may still have.
[Please log in to post a comment]