Log In  
Follow
alpha_helix
[ :: Read More :: ]

Hi there,

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:

  • in the map editor, I have screen-sized (16x16 tiles) compatible level blocks
  • 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
  • in my draw function, I then loop through this table and draw the map
--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

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.

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!

Any help would be much appreciated!

P#103889 2021-12-31 06:00 ( Edited 2021-12-31 06:04)