bythemeadow [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=59186 [Help] Tile collision issue <p>So I have an issue where the player object can clip through about half a collision tile, but only when moving to the left. As I type that I realize how weird and niche this problem is. Anyways, here's my move function:</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 control_player() newx=p.x newy=p.y if (btn(⬅️)) then newx-=.1 p.sprite=d.left elseif (btn(➡️)) then newx+=.1 p.sprite=d.right elseif (btn(⬆️)) then newy-=.1 p.sprite=d.up elseif (btn(⬇️)) then newy+=.1 p.sprite=d.down end if (can_move(newx,newy)) then p.x=mid(0,newx,127) p.y=mid(0,newy,63) end if (door_tile(newx,newy)) then scene=&quot;room1&quot; p.x=6 p.y=10 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 here's my collision function:</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 is_tile(tile_type,x,y) local tile_x=newx+pixeloffset_x local tile_y=newy+pixeloffset_y tile=mget(tile_x,tile_y) has_flag=fget(tile,tile_type) return has_flag end function can_move(x,y) return not is_tile(wall,x,y) end function door_tile(x,y) return is_tile(door,x,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>pixel_offset is initially 0, and changes based on scene to account for the map change.<br /> Any idea what is causing this? </p> <p>side note: Everyone on this forum has been so helpful and I just want to say thanks for all the help! This is my first coding project outside of html and I really appreciate it :]</p> https://www.lexaloffle.com/bbs/?tid=45106 https://www.lexaloffle.com/bbs/?tid=45106 Fri, 22 Oct 2021 02:53:06 UTC [Help] Attempt to index global value (a nil value) <p>I am trying to use values in a table to dictate which scene is being shown in the game. I defined the table 'S' at the top of the code but a piece at the bottom referring to it comes back nil. What's the problem?</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 _init() cls() music(0) s={} s.menu=1 s.start=0 s.t1=0 s.one=0 map_setup() make_player() end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <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> if s.menu&gt;0 then screen_menu() end if s.start&gt;0 then screen_start() end if s.t1&gt;0 then screen_t1() end if s.one&gt;0 then screen_scene1() end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=45059 https://www.lexaloffle.com/bbs/?tid=45059 Wed, 20 Oct 2021 09:37:34 UTC SFX loops way too fast <p>So I want to make a sound effect that only plays when a direction is pushed, and the trouble that I'm running into is that:</p> <ul> <li>using (btn(input)) loops the sound so fast it almost crashes PICO-8</li> <li>using (btnp(input)) only plays it when the button is first pressed</li> </ul> <p>How do I make it so it plays consistently while pressing a direction, and loops at a normal speed? I tried making a timer that gets added to while a direction is pushed, but the only way I could find to do it was i+=1 which only added 1 a single time. Is a timer the right way to go or is there a more efficient way?</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 move_player() newx=p.x newy=p.y if (btn(⬅️)) then newx-=.1 p.sprite=d.left sfx(0) elseif (btn(➡️)) then newx+=.1 p.sprite=d.right sfx(0) elseif (btn(⬆️)) then newy-=.1 p.sprite=d.up sfx(0) elseif (btn(⬇️)) then newy+=.1 p.sprite=d.down sfx(0) 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>Here's a snippet of my code if it helps. Thanks!</p> https://www.lexaloffle.com/bbs/?tid=45038 https://www.lexaloffle.com/bbs/?tid=45038 Tue, 19 Oct 2021 01:09:34 UTC How to vary a walk sprite? <p>So I currently have a movement system down for my player, and the sprite changes based on direction. Here's an excerpt:</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 make_player() p={} p.x=3 p.y=10 p.sprite=4 end function draw_player() spr(p.sprite,p.x*8,p.y*8) end function move_player() newx=p.x newy=p.y if (btn(⬅️)) newx-=.1 if (btn(➡️)) newx+=.1 if (btn(⬆️)) newy-=.1 if (btn(⬇️)) newy+=.1 if (can_move(newx,newy)) then p.x=mid(0,newx,127) p.y=mid(0,newy,63) else p.x+=0 p.y+=0 end end function player_anim() if (btnp(⬅️)) p.sprite=3 if (btnp(➡️)) p.sprite=2 if (btnp(⬆️)) p.sprite=4 if (btnp(⬇️)) p.sprite=1 end function player_walk() 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>Now how would I go about adding footstep animations every second or so as a direction is pressed?</p> https://www.lexaloffle.com/bbs/?tid=45010 https://www.lexaloffle.com/bbs/?tid=45010 Sun, 17 Oct 2021 03:27:48 UTC