diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2026-04-20 16:39:10 -0600 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2026-04-20 16:39:10 -0600 |
| commit | 2422c8c8f39a6aac0b76945bb0c7aa4b6a2ab031 (patch) | |
| tree | 645b2882ecd71918ae8778943a0704202c821070 | |
| parent | f44fae1b7043fe9ed6803f989d9d1f53ff21f617 (diff) | |
| download | dyl8-2422c8c8f39a6aac0b76945bb0c7aa4b6a2ab031.tar.gz dyl8-2422c8c8f39a6aac0b76945bb0c7aa4b6a2ab031.zip | |
Bruh
| -rw-r--r-- | dyl.p8 | 61 |
1 files changed, 36 insertions, 25 deletions
@@ -121,36 +121,48 @@ end -- prevent cobblestoning during -- non-manhattan movement --- if only one axis crossed a --- pixel boundary and we're moving --- diagonally enough to notice, --- hold it for a frame so both axes --- can step together. +-- by "lagging" the sprite +-- behind the physical position +-- function update_spritepos(entity) - tx=flr(entity.pos.x) - ty=flr(entity.pos.y) - dx=tx-entity.spritepos.x - dy=ty-entity.spritepos.y + --entity.spritepos.x=entity.pos.x + --entity.spritepos.y=entity.pos.y - if dx==0 and dy==0 then return end - - if dx!=0 and dy!=0 then - entity.spritepos.x+=mid(-1,dx,1) - entity.spritepos.y+=mid(-1,dy,1) + -- step in only x or y. + -- we can snap to the grid + -- without cobblestoning. + if entity.vel.y==0 or entity.vel.x==0 then + entity.spritepos.x=entity.pos.x + entity.spritepos.y=entity.pos.y return end - vx=abs(entity.vel.x) - vy=abs(entity.vel.y) - ratio=min(vx,vy)/max(vx,vy,0.001) - if ratio>0.4 - and abs(dx)<=1 - and abs(dy)<=1 then - return + nv=normalize(entity.vel) + dx,dy=abs(entity.pos.x-entity.spritepos.x),abs(entity.pos.y-entity.spritepos.y) + + yslow=abs(entity.vel.y)<abs(entity.vel.x) + xslow=not yslow + + pushx,pushy=false,false + jerkdelta=1+min(abs(abs(nv.y)-abs(nv.x)),0.4) + if dx>=jerkdelta and xslow + and dy>=1 then + pushx,pushy=true,true + elseif dy>=jerkdelta and yslow + and dx>=1 then + pushx,pushy=true,true + elseif xslow and dy>=1 then + pushy=true + elseif yslow and dx>=1 then + pushx=true end - entity.spritepos.x+=mid(-1,dx,1) - entity.spritepos.y+=mid(-1,dy,1) + if pushx then + entity.spritepos.x=entity.pos.x + end + if pushy then + entity.spritepos.y=entity.pos.y + end end suffixes={"ny","","py"} @@ -158,7 +170,6 @@ function update(entity) if entity.vel != nil then integral_vel=vec_scale(entity.vel,step_dt) entity.pos=vec_add(entity.pos,integral_vel) - update_spritepos(entity) dx,dy=entity.vel.x,entity.vel.y @@ -252,7 +263,7 @@ function _init() end -function _update60() +function _update() cls(0) old_step=step_t step_t=time() |
