Log In  

Hello!

I have just started working on a little metroidvania-style platformer. I started by following the platformer tutorial on [youtube]Youtube[https://www.youtube.com/watch?v=q6c6DvGK4lg&list=PLyhkEEoUjSQtUiSOu-N4BIrHBFtLNjkyE] and looking at some carts here.

I want to have different rooms connected by doors, which I have all drawn in the map editor. But apparently I don't understand how the map() function works.

I have one rooms that stretches from the map cells x000/y000 to x063/y015 and another smaller one below that from x000/y016 to x026/y022. I have a simple camera function like this:

function update_cam(m_start, m_end)
  cam_x=plr.x-64+(plr.w/2)
  cam_y=plr.y-64+(plr.w/2)
    if cam_x<m_start then
      cam_x=m_start
    end
    if cam_x>m_end-128 then
      cam_x=m_end-128
    end
  camera(cam_x,cam_y)
end

I have collision checks done like this:

function collide_map(obj,aim,flag)
  -- obj = table needs x,y,w,h
  -- aim =  left,right,up,down

  local x=obj.x     local y=obj.y
  local w=obj.w     local h=obj.h

  local x1=0        local y1=0
  local x2=0        local y2=0

  if aim=="left" then
    x1=x-1  y1=y
    x2=x    y2=y+h-1
  elseif aim=="right" then
    x1=x+w-1    y1=y
    x2=x+w  y2=y+h-1
  elseif aim=="up" then
    x1=x+2  y1=y-1
    x2=x+w-3    y2=y
  elseif aim=="down" then
    x1=x+2  y1=y+h
    x2=x+w-3    y2=y+h
  end       

  --pixels to tiles
  x1/=8     y1/=8
  x2/=8     y2/=8

  if fget(mget(x1,y1), flag)
  or fget(mget(x1,y2), flag)
  or fget(mget(x2,y1), flag)
  or fget(mget(x2,y2), flag) then
   return true
   else
   return false
  end

end

And so far I'm calling the map function like this:

map(0, 0, 0, 0, 64, 32)

which will draw the upper portion of the map. But when I tested just drawing the portion with the second room like this:

map(0, 16, 0, 0, 64, 32)

the correct portion would be drawn but I still have the collisions from map(0, 0, 0, 0, 64, 32). They player will seeming hang in the air and collide with invisible parts of the map. Can someone explain to me what is goind wrong?

P#116420 2022-08-28 21:11

You are only drawing the map- Your player still exists at first portion, with the map tiles in the same spot. If you can, I would reccomend just calling map() with no arguments, as that shows the entire map. You could also, when doing collision checks, add the offsetted amount. Hope this helps.

P#116428 2022-08-28 21:49

look at the camera function to change what’s drawn on screen without messing up map coordinates for mget!

I warmly recommend working through https://mboffin.itch.io/pico8-educational-toolset (the ones related to camera and map)

P#116437 2022-08-28 22:14

Thank you two. I think both of you gave me some good clues :).

P#116615 2022-08-30 21:32

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 17:00:43 | 0.007s | Q:14