I haven't done any development for many years and in general hardly did any game development. Now I'm getting back into it with the awesome Pico-8 and to get familiar with the engine and game dev I'm working on a platformer.
The current status is that I have a player character, physics, a (very) basic map and some sound effects. It all works nicely and I'm currently working on items that the player can pick up (power-ups and such). Before moving forward I was hoping to learn some best practices from you all and get some feedback on my current approach.
Approach or implementing items
As I want to have rather large maps with many items I want to place items using the map editor, not by defining them manually in the code (as tweaking during play-testing would be a pita). At the same time I want the items to have some animation before they're picked up and of course an animation when they're picked up as well.
My current idea is to scan the map during _init() using mget() for these items and then add them to an array which would be scanned and updated during the game loop. The idea is to iterate over the elements in the array and use mset() to change the tiles to do the animation before they're picked up.
Then I'm using collision detection to detect whether the player is picking up an item and if so play a sound effect + run an animation.
- Does the above approach make sense or is there a better way to achieve this?
- What are the pros/cons? Are there any alternatives?
- Wouldn't iterating over the entire map to move the items to an array be too slow?
- Can I do the loading in chunks based on what's in view? (e.g. using the camera position)
All help is very much appreciated!
> You say you want to have a large map, though. Are you sure you have room for the entire map in the editor? It might be that you're forced to store the map in "code" at some point anyway.
Right, I haven't explored limitations of the map in Pico-8. Good point, I'll look into that. And thanks for your reply!
Another thought. Although I don't know about how efficient this method is,
- Go through the map at _Update() and add all the items in the camera's view to a table.
- Then remove the items from the map tiles.
- Render the items as "entities" by iterating over the table every _Update().
- If the player doesn't pick them up or interact, re-add them to the map if they are outside the camera.
Picking them up would mean that the are not re-added as there would be no entity. This would presumably work with enemies and other things too, as it could retain weather or not the enemy was killed or a door opened.
Just thinking aloud.
[Please log in to post a comment]