Log In  

I'm currently working on a game where you collect items from different areas in a map. I have around 10 spots on the map where I want items to be, but I feel like only 6 or so should actually have items in them when playing as so to create some mediocre replay value. I'm currently detecting the spots using map flags, and sending that data to a function in which I'll create an entity spawner. However I dont know how I can create these exceptions in the code when generating where the items go, does anyone have any hints or ideas for solutions to this problem?

P#66222 2019-07-30 22:01 ( Edited 2019-07-30 22:01)

here's an idea: when reading the map, add each of the locations to a table. After you've read the whole map and have all the locations in that table, randomly remove 4 or so locations from the table. Then iterate through the table and spawn an item in each location.

P#66223 2019-07-30 22:11 ( Edited 2019-07-30 22:13)

@kittenm4ster That idea is so simple yet efficient! I love it! I hadn't actually worked with tables at all yet in Pico8, but I just spent the last hour researching them. The only problem I ccan find with it is that the delete function for tables only works with direct values, and not their index/position within the table. I have an idea of how to work around this, I'll probably just individually input the locations instead of using map flags. Thanks so much for the idea! Cant wait to get home now and try it out!

P#66240 2019-07-31 08:42 ( Edited 2019-07-31 08:43)

oh yeah; you can work around the weird delete-by-value thing by just doing this to delete by index instead:

del(t, t[1])

(that would delete the first item in the table)

P#66241 2019-07-31 15:03

@kittenm4ster Glad to report that it works! Currently grabbing 10 locations and randomly shortening the last to 6. Havent worked out a spawning function yet as it's gonna get a bit messing trying to integrate it with Zep's collision code, but I think the hardest part is out of the way. Thanks so much for your help!

P#66257 2019-07-31 20:44


P#66260 2019-07-31 21:06

[Please log in to post a comment]