8bit_gnosis [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=87901 Need help with simple pendulum motion <p>Hi friends,</p> <p>I'm struggling to create a simple pendulum motion. I'm just trying to get a pixel to move along an arc and swing back. If I understand correctly, I need an angle variable that oscillates between .25 and .75. Right now, my angle variable (&quot;a&quot;) oscillates between 1 and 0. How do I modulate the angle so it bounces between .75 and .25? </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>x,y=63,63 function _update() a = abs(time()/2 % 2-1) x=x+sin(a) y=y+cos(a) end function _draw() cls() pset(x,y,7) 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=148945 https://www.lexaloffle.com/bbs/?tid=148945 Mon, 12 May 2025 17:25:46 UTC Need Help with Particle Collisions <img loading="lazy" style="margin-bottom:16px" border=0 src="/media/87901/pixel_col_forum_2.gif" alt="" /> <p>Hello everybody,</p> <p>I'm trying to implement collision and knock-back(?) for the particles in my game. I've got it sort of working, but--as you can see from the gif above--some particles behave oddly. Some drip down the tiles, others get caught in mid-air. </p> <p>I was hoping some kind soul could take a look at my code and tell me if there is a better way of going about this. I'm guessing my issue is a result of how I'm checking for collisions. Thanks!</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>parts = {} function make_px() for i=1,10 do p={} if not p1.left then p.x=p1.x+7 else p.x=p1.x end p.y=p1.y+7 p.c=4 if not p1.left then p.dx=1+rnd(2) else p.dx=-1-rnd(2) end p.dy=rnd(1)-rnd(.5) p.age=rnd(2) add(parts,p) end end function update_px() local g = .05 --check pixels left, right, above, and below. If there is a collision, add knock-back for p in all(parts) do if (fget(mget((p.x-1)/8,p.y/8),0)) p.dy*=-.5 p.dx*=-.5 if (fget(mget((p.x+1)/8,p.y/8),0)) p.dy*=-.5 p.dx*=-.5 if (fget(mget((p.x)/8,p.y-1/8),0)) p.dy*=-.5 p.dx*=-.5 if (fget(mget((p.x)/8,p.y+1/8),0)) p.dy*=-.5 p.dx*=-.5 p.x+=p.dx p.dy-=g p.y-=p.dy p.age+=.1 if (p.age&gt;5) del(parts,p) --delete old particles end end function draw_parts() for p in all(parts) do pset(p.x,p.y,p.c) 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> https://www.lexaloffle.com/bbs/?tid=148910 https://www.lexaloffle.com/bbs/?tid=148910 Fri, 09 May 2025 18:42:44 UTC Help a dummy understand basic recursive(?) function <p>I'm a newbie and I'd like to learn procedural generation to add things like dynamic grass and vegetation to my game. I really like how Zep created the swaying trees in the fireflies gif for the 0.2.4 release, so I thought I'd examine his code. But I'm having some trouble parsing it because the function seems to call itself. I'm assuming this is what's called a recursive function.</p> <img loading="lazy" style="margin-bottom:16px" border=0 src="/media/87901/fireflies_024.gif" alt="" /> <p>How does the function know to stop calling itself? I'm guessing the if statement regarding the l variable terminates it but how? I'm confused because, to my mind, logically, there should be an &quot;else&quot; following the if/then to call the function again. What is the point of the return command? </p> <p>Here is his function for drawing the trees:</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 tree(x,y,a,l) if (l&lt;3) then for ii=0,3 do circfill( x+rnd(8)-rnd(8), y+ii, 1,lcol[4-ii]) end return end local x1=x+cos(a)*l local y1=y+sin(a)*l local q=l/8 local col=l&gt;8 and 13 or 0 for xx=-q,q do line(x+xx,y,x1+xx,y1,col) col=0 end local d= ( cos(t()/3+x1/50)+ cos(t()/4+x1/70) )/500 tree(x1,y1,d+a-.04-rnd(0.04),l*(.9-rnd(0.2))) tree(x1,y1,d+a+.04+rnd(0.04),l*(.9-rnd(0.2))) 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>Thanks!</p> https://www.lexaloffle.com/bbs/?tid=148867 https://www.lexaloffle.com/bbs/?tid=148867 Wed, 07 May 2025 18:56:46 UTC Help with Alpha Mask with Scrolling Camera <img loading="lazy" style="margin-bottom:16px" border=0 src="/media/87901/4forum2_1.gif" alt="" /> <p>Is there a wise, benevolent soul out there willing to explain to my feeble mind why this alpha effect doesn't seem to work with a scrolling camera? I can't seem to anchor the light circle to the center of my player character.</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() px,py=64,64 end function _draw() cls() map() camera(cx,cy) draw_light() --draw alpha effect print(&quot;🐱&quot;,px,py) --player end function _update() if (btn(0)) px-=1 if (btn(1)) px+=1 if (btn(2)) py-=1 if (btn(3)) py+=1 cx=px-64 --cam cy=py-64 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 is the draw function for the alpha effect:</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 draw_light() poke(0x5f54,0x60) pal({2}) --draw a circle for i=-24,24 do x=sqrt(24*24-i*i) sspr(px-x,py+i, x*2,1, (px-x)+cx,(py+cy)+i) end poke(0x5f54,0x00) pal() 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=148353 https://www.lexaloffle.com/bbs/?tid=148353 Fri, 11 Apr 2025 13:27:49 UTC Update #2 - Please help <p> <table><tr><td> <a href="/bbs/?pid=140599#p"> <img src="/bbs/thumbs/pico8_blocks-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=140599#p"> blocks</a><br><br> by <a href="/bbs/?uid=87901"> 8bit_gnosis</a> <br><br><br> <a href="/bbs/?pid=140599#p"> [Click to Play]</a> </td></tr></table> </p> <h1>My second progress update:</h1> <p>I'm trying to implement the ability for my player character to create temporary blocks which can be used as platforms to reach otherwise unreachable areas. The idea is that the bunny player character digs up earth which piles up behind him and then disappears after a few seconds. </p> <ol> <li>When the player presses the o button while on a ground tile, a 'newblock' is added to a table so that it can be deleted after its set duration. In order to ensure the original map tile is restored after the 'dirt block' disappears, mget is used to grab the original tile sprite as 'oldblock.'</li> </ol> <p><code>if btnp(🅾️) and p.landed then newblock={} newblock.spr=14 newblock.x=p.x newblock.y=p.y newblock.age=0 oldblock = mget(flr(p.x/8)-1,flr(p.y/8)) add(blocks,newblock)</code></p> <ol start="2"> <li>The block is drawn according to the coordinates stored in a table. The block is drawn behind the player based on whether the character sprite is flipped.</li> </ol> <p><code>function draw_block() for myblock in all(blocks) do if p.flp then mset((myblock.x/8)+2,(myblock.y/8),myblock.spr) else mset((myblock.x/8)-1,(myblock.y/8),myblock.spr) end end end</code></p> <ol start="3"> <li>The block is deleted from the table after it's aged past its duration and mset replaces the block with the original 'oldblock' variable.</li> </ol> <p><code>function update_block() for myblock in all(blocks) do myblock.age+=.1 if myblock.age&gt;10 then del(blocks,myblock) mset((myblock.x/8)-1,(myblock.y/8),oldblock) end end end</code></p> <h2>Problems</h2> <img loading="lazy" style="margin-bottom:16px" border=0 src="/media/87901/block p8_0.gif" alt="" /> <p>There are multiple problems I'm encountering. </p> <ol> <li> <p>The dirt block doesn't always draw directly behind the player sprite but sometimes 2 tiles away.</p> </li> <li> <p>Two blocks are drawn if the player happens to move in the opposite direction immediately after the first block is drawn.</p> </li> <li> <p>The original map tile is not always stored and replaced. Frequently, the 'oldblock' variable will store the adjacent tile sprite instead.</p> </li> <li>If the button is held down, multiple dirt blocks are drawn and only the final one appears to delete.</li> </ol> <h2>Gratitude</h2> <p>If anyone has any insight into how to fix these problems, even it is simply nudging me in the right direction or pointing to a resource, you have my eternal gratitude. I'm still a complete novice at this. Thank you.</p> https://www.lexaloffle.com/bbs/?tid=139966 https://www.lexaloffle.com/bbs/?tid=139966 Thu, 25 Jan 2024 16:28:51 UTC First Blog Update <p> <table><tr><td> <a href="/bbs/?pid=139921#p"> <img src="/bbs/thumbs/pico8_fsatobugu-1.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=139921#p"> fsatobugu</a><br><br> by <a href="/bbs/?uid=87901"> 8bit_gnosis</a> <br><br><br> <a href="/bbs/?pid=139921#p"> [Click to Play]</a> </td></tr></table> This is my first blog update. I'm feeling a bit defeated. I'm not making meaningful progress any more. The progress I have made is all but entirely owed to tutorials from nerdy teachers and lazy devs. I'm now spending way more of my time trying to find relevant content to learn from than I am actually learning. I've spent hours combing through BBS posts, reddit, youtube, and discord. When I do find discussion that seems relevant to what I want do, it's rare that I am able to parse the code to learn from it. Trying to stay motivated and move forward.</p> <p>What I have thus far:<br /> -A running, jumping player sprite which I don't understand how to further animate without continuously looping through a cycle of sprites (How do I do a once-and-done animation?)<br /> -A functional camera that follows the player<br /> -Collision detection for the map tiles<br /> -An expanding and contracting field of view effect which I have no idea how to adjust due to the math involved.<br /> -A particle effect simulating kicked-up dirt whose location I'm not fully able to anchor behind the sprite when it's flipped.</p> <p>What I would like to have:<br /> -Some sort of animated background, perhaps glistening or dripping rocks.<br /> -Breakable tiles for a digging mechanic.</p> https://www.lexaloffle.com/bbs/?tid=139776 https://www.lexaloffle.com/bbs/?tid=139776 Tue, 09 Jan 2024 23:11:14 UTC Pressing start <p>My first post. I'm beginning this blog to document my progress in pursuing a passion project, the creation of my first game. The existence of Pico-8 and 'mini metroid-vanias' such as Metroid Crimson, The Ascent, and Subsurface have inspired me. I grew up with an NES and my finest childhood memories involved exploring the game worlds of Zelda and Metroid. My goal is to create a game with a focus on exploration and environmental puzzle solving with progression through an ability-gated game world. I lack programming experience and have a general aversion to math. I'm hopeful the community here will share its wisdom if I'm earnest in my attempt to understand conceptually all the code and math and I refrain from making a million requests for information.</p> <p>My progress so far: With the assistance of a set of super helpful youtube tutorials, I've created a player sprite capable of running and jumping using platformer controls. I've also managed to alter existing camera code to track the player character room by room.</p> <p>My current obstacle: Collision detection is proving to be a struggle. My player sprite is capable of landing on tiles of empty space. The code uses a combination of local variables and 'objects.' Conceptually I don't understand 'objects' and what the code is doing. Perhaps I need to turn my focus toward learning how Lua works.</p> https://www.lexaloffle.com/bbs/?tid=55545 https://www.lexaloffle.com/bbs/?tid=55545 Fri, 29 Dec 2023 19:28:00 UTC