alpha_helix [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=61418 Level generation on the fly <p>Hi there,</p> <p>I'm new to pico-8 and was playing around with a system to generate levels for a top-down adventure game on the fly. My setup is as follows:</p> <ul> <li>in the map editor, I have screen-sized (16x16 tiles) compatible level blocks</li> <li>when I call my generate_map() function, it makes a table with a predefined number of entries, each containing the coordinates to row/columns in the map</li> <li>in my draw function, I then loop through this table and draw the map</li> </ul> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>--generate the map function map_setup(map_size) total_area=map_size level={} for area=1,total_area do level[area]={flr(rnd(7))*16, flr(rnd(3))*16} end end --draw the map function draw_map() t=1 for i=0,sqrt(total_area)-1 do for j=0,sqrt(total_area)-1 do map(level[t][1],level[t][2],i*128,j*128,16,16) t+=1 end end end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>This works for drawing the map nicely, however I am having a lot of trouble getting the collision detection with the map tiles to work. After digging around for hours, it appears my problem is that when I check player.y and player.x and feed these into mget (after dividing by 8 to convert to row/column coordinate), that mget returns whatever is at that coordinate in the map editor, not in my actually drawn map.</p> <p>Is there a clever way of checking what is actually on my screen, or do I need to rethink this entire setup? I was trying to transition smoothly from one screen to the other (i.e. the world is continuous), so getting hold of an offset is not super straightforward, I think, but I might be missing something super obvious!</p> <p>Any help would be much appreciated!</p> https://www.lexaloffle.com/bbs/?tid=45919 https://www.lexaloffle.com/bbs/?tid=45919 Fri, 31 Dec 2021 06:00:47 UTC