lil_blizzard [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=37413 Help with understanding some basic concepts. <p> <table><tr><td> <a href="/bbs/?pid=64663#p"> <img src="/bbs/thumbs/pico8_twinbeeclone-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=64663#p"> twinbeeclone</a><br><br> by <a href="/bbs/?uid=37413"> lil_blizzard</a> <br><br><br> <a href="/bbs/?pid=64663#p"> [Click to Play]</a> </td></tr></table> </p> <p>Beginner here, so forgive me if I'm missing something obvious. I'm currently working on a simple clone of Twin Bee to learn a little bit about design. I'm running into a blockade due to my lack of programming experience, so I'm hoping someone may have some answers from me.</p> <p>I've got clouds that fall from the top of the screen. The function that sets all the variables for the cloud table looks 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 spawncloud() local c = { x = rnd(95)+16, y = -16, dy = rnd(.5)+.75, sp = 5, hb = {x1=0,y1=0,x2=13,y2=1} } -- bell properties - is it necessary for me to declare -- these properties within the spawncloud function -- because the bell position depends on the cloud position? local b = { x=c.x, y=c.y, boost=3, dy=0, sp=7, hb={x1=0,y1=0,x2=3,y2=3} } --add to cloud table add(clouds,c) --add to bell table add(bells, b) 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>The cloud spawn perfectly when I iterate through the cloud array in the _draw() function.</p> <p>My next objective is spawning a bell when my bullet hit's one of these clouds. As you can see in the spawncloud() function above, I'm setting up a local table for the bells as well, because their x&amp;y variables are dependent on those of the cloud. I would like to have an entirely separate spawnbell() function so I can call it when necessary, but I'm not quite sure how I would go about this because of the dependent x&amp;y variables.</p> <p>Additionally, my collision seems to be working about 75% of the time, so any help with making that more consistent would be greatly appreciated. I've borrowed the code from another project, so I'm not 100% clear on what it's doing. Here's what that code looks like:</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>--creating a box collider function abs_box(s) local box = {} box.x1 = s.hb.x1 + s.x box.y1 = s.hb.y1 + s.y box.x2 = s.hb.x2 + s.x box.y2 = s.hb.y2 + s.y return box end --collision function function coll(a,b) --create relative hitboxes local box_a = abs_box(a) local box_b = abs_box(b) if box_a.x1 &gt; box_b.x2 or box_a.y1 &gt; box_b.y2 or box_b.x1 &gt; box_a.x2 or box_b.y1 &gt; box_a.y2 then return false end return true end --check if our bullet is colliding --with our cloud function checkbulletcoll() for e in all(bullets) do for c in all(clouds) do if coll(e,c) then --delete bullet if collision del(bullets,e) end end 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>Please let me know if there's additional code you'd like to see.<br /> Thanks for the help!</p> https://www.lexaloffle.com/bbs/?tid=34298 https://www.lexaloffle.com/bbs/?tid=34298 Wed, 22 May 2019 00:06:11 UTC