StrangeD0S [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=47770 Need help with different rooms on map <p>Hello!</p> <p>I have just started working on a little metroidvania-style platformer. I started by following the platformer tutorial on [youtube]Youtube[<a href="https://www.youtube.com/watch?v=q6c6DvGK4lg&amp;list=PLyhkEEoUjSQtUiSOu-N4BIrHBFtLNjkyE">https://www.youtube.com/watch?v=q6c6DvGK4lg&amp;list=PLyhkEEoUjSQtUiSOu-N4BIrHBFtLNjkyE</a>] and looking at some carts here.</p> <p>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. </p> <p>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:</p> <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>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&lt;m_start then cam_x=m_start end if cam_x&gt;m_end-128 then cam_x=m_end-128 end camera(cam_x,cam_y) 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>I have collision checks done like this:</p> <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>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==&quot;left&quot; then x1=x-1 y1=y x2=x y2=y+h-1 elseif aim==&quot;right&quot; then x1=x+w-1 y1=y x2=x+w y2=y+h-1 elseif aim==&quot;up&quot; then x1=x+2 y1=y-1 x2=x+w-3 y2=y elseif aim==&quot;down&quot; 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</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>And so far I'm calling the map function like this:</p> <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>map(0, 0, 0, 0, 64, 32)</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>which will draw the upper portion of the map. But when I tested just drawing the portion with the second room like this:</p> <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>map(0, 16, 0, 0, 64, 32)</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>the correct portion would be drawn but I still have the collisions from <code>map(0, 0, 0, 0, 64, 32)</code>. 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> https://www.lexaloffle.com/bbs/?tid=49085 https://www.lexaloffle.com/bbs/?tid=49085 Sun, 28 Aug 2022 21:11:29 UTC