Articles

Affichage des articles du mai, 2021

Shake my chicken with Pico8...

Image
      Fig.1 #Pixcode Shake The syntax of the code does not correspond to a particular language. This "code" just allows to understand the process to follow.       Fig.2 Do it with Pico8     --Shake my chicken! function _init() intensity=0 end function _update()     cls()     if btnp(❎) then         intensity=5     end end function _draw()     shake()     spr(1+(time()*5%4),60,60)         print(intensity,0,10,15)     print("press ❎ to shake",35,80,15) end function shake()     local shakex=(rnd({-intensity,intensity}))     local shakey=(rnd({-intensity,intensity}))     print(shakex,0,17,15)     print(shakey,0,24,15)     intensity*=0.9     if (intensity<=0.5) intensity=0     camera(shakex,shakey) end

Collision Circle/Square or Rectangle with Pico8

Image
1- Collision circle/square with sine and cosine just for fun!     Sometimes I do useless stuff just for fun and to get my brain fired up, when simpler solutions exist!!! If you had to choose only one solution, the second one is the most reasonable ;-)    #pixcode 1: Detect the corners of a square     #pixcode 2: There is a collision, but D > 0, so the collision is not detected. We need to check the vertical and horizontal alignment.  function _init() --circle center x1=90 y1=60 --square center x2=60 y2=80 d=10 --square side/2 r=10 --radius end function _update() --controls if (btn(0)) x1-=1 if (btn(1)) x1+=1 if (btn(2)) y1-=1 if (btn(3)) y1+=1 --calculate oc a=abs(x1-x2) b=abs(y1-y2) oc=sqrt(a^2+b^2) --calculate sine and cosine cosa=b/oc sina=a/oc --calculate di. The value 0.7071 is only for a square if cosa <= 0.7071 then     di=d/sina else di=d/cosa end --check collision with a corner or middle edge if (oc<=(r+di)) then     corner=1 else corner=0 end --check the collision