Macronaut [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=14203 Orbit Around X Y <p>Hello everyone, how are you doing? I'm trying to do something here and if you guys could help me somehow it'd be nice, I'm already grateful for your attention.</p> <p>The thing is I was able to achieve the &quot;rotation around a point&quot; for Sprites ( in this case a circle ), but the issue is that I want to have multiple objects rotating around a point while starting at different &quot;steps&quot; of the rotation itself ( I'm attaching a image to explain it in more detail).</p> <img loading="lazy" style="margin-bottom:16px" border=0 src="/media/14203/2_pico8_rotation.png" alt="" /> <p>The code I'm using is the following:</p> <p>MAIN.LUA</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>--sincos math timer=0 scr={ w=128, h=128 } opt={ spd=.5 } pix={ c=12, x=0, y=0 } cir={ timer=0, a=false, spd=.5, init=3, o=20, c=12, x=0, y=0, r=6 } function _init() cir.x=scr.w/2 cir.y=scr.h/2 pix.x=scr.w/2 pix.y=scr.h/2 end function _draw() cls(1) pset(pix.x,pix.y,pix.c) print(&quot;speed &quot;..opt.spd) for entry in all(circles) do circ(entry.x,entry.y,entry.r,entry.c) end end function _update60() update_keys() for entry in all(circles) do entry.timer+= entry.spd/60 entry.x= pix.x+cos(entry.timer)*entry.o entry.y= pix.y-sin(entry.timer)*entry.o end if(keys.down) then opt.spd-=.1 elseif(keys.up) then opt.spd+=.1 end if(keys.right) then pix.x+=1 end if(keys.left) then pix.x-=1 end if(keys.activate) then make_circle(pix.x,pix.y,opt.spd,15,12) end if(keys.delete) then circles={} end end -- methods -- -- make_circle(x,y,s,o,c) </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>UTILS.LUA</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>--utils circles={} function make_circle(x,y,s,o,c) local obj={ timer=0, a=false, spd=s, o=o, c=c, x=x, y=y, r=6 } add(circles,obj) end function update_keys() keys={ activate=btnp(🅾️), delete=btnp(❎), right=btn(1), down=btnp(3), left=btn(0), up=btnp(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 in advance for any help and have a good day!</p> https://www.lexaloffle.com/bbs/?tid=141672 https://www.lexaloffle.com/bbs/?tid=141672 Fri, 12 Apr 2024 14:03:09 UTC