ÌÌÌÌ À ÌÌÀ ÀÀ ÀÀ ÌÌÀ ÀÌÌÌÌffff6333633363336333633363336333ffff3333333333333333333333333333ffff333c333c333c333c333c333c333cffff633c633c633c633c633c633cffff6333633363336333633363336333633333333333333333333333333333333333333c333c333c333c333c333c333c333c6333633363336333633363336333ffff3333333333333333333333333333ffff333c333c333c333c333c333c333cffff >%  À?ÌÌÌÌ À ÌÌÀ ÀÀ ÀÀ ÌÌÀ ÀÌÌÌÌffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff633333333333333c63333333333333333333333333333333333333333333333333333333633333333333333c63333333333333333333333333333333333333333333333333333333633333333333333c63333333333333333333333333333333333333333333333333333333633333333333333c63333333333333333333333333333333333333333333333333333333633333333333333c63333333333333333333333333333333333333333333333333333333633333333333333c63333333333333333333333333333333333333333333333333333333633333333333333c63333333333333333333333333333333333333333333333333333333ffffffffffffffffffffffff3333333333333333ffffffffffff63333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c63333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c63333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c63333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c63333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c63333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c63333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c633333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333ffff633333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c633333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c633333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c633333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c633333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c633333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c633333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333c6333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333ffffffff33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333¡-- title: 2D Physics Engine -- author: team lightning -- desc: physics engine for 2d platformers. port from pico-8. -- script: lua t=0 x=96 y=24 player={} world={} cycles=0 --player init player.x=1 player.y=0 player.xvel=0 player.yvel=0 player.lfi=false --world init world.accel=0.1 world.maxspd=1 world.drag=0.5 world.grav=1 world.tvel=2 world.jump=8 world.maps=1 world.cmap=0 function grounded() if fget(mget((player.x)//8,(player.y)//8+1),1)or fget(mget((player.x+7)//8,(player.y)//8+1),1) then return (player.y//8)*8 else return nil end end function wall() py1=player.y//8 py2=(player.y+6)//8 ret={} ret.side=0 ret.x=player.x l1=fget(mget((player.x-1)//8,py1),2) l2=fget(mget((player.x-1)//8,py2),2) r1=fget(mget(player.x//8+1,py1),0) r2=fget(mget(player.x//8+1,py2),0) if l1 or l2 then ret.side=1 elseif r1 or r2 then ret.side=2 end if (l1 and l2) or (r1 and r2) then ret.x=(player.x//8)*8 end return ret end function clamp(val,low,high) return math.max(math.min(val,high),low) end w=wall() function TIC() g=grounded() xg=player.xvel>0 xl=player.xvel<0 if cycles%1==0 then w=wall() end --gravity if g==nil and player.yvel < world.tvel then player.yvel=player.yvel+world.grav end if g~=nil and player.yvel > 0 then player.yvel=0 player.y=g end --friction if player.xvel>world.drag and not player.lfi then player.xvel=player.xvel-world.drag elseif player.xvel<-world.drag and not player.lfi then player.xvel=player.xvel+world.drag elseif not player.lfi then player.xvel=0 end --input if btnp(0) and g then player.yvel=-world.jump end if btn(2) then player.xvel=player.xvel-world.accel;player.lfi=true elseif btn(3) then player.xvel=player.xvel+world.accel;player.lfi=true else player.lfi=false end player.xvel=clamp(player.xvel,-world.maxspd,world.maxspd) --walls if w.side==1 then player.x=w.x player.xvel=clamp(player.xvel,0,world.maxspd) elseif w.side==2 then player.x=w.x player.xvel=clamp(player.xvel,-world.maxspd,0) end --apply motion player.x=player.x+player.xvel player.y=player.y+player.yvel --draw cls() map(world.cmap*30,0) --print(w.side) --debug things spr(1,player.x,player.y) cycles=cycles+1 end