summaryrefslogtreecommitdiff
path: root/dyl.p8
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2026-04-20 16:39:10 -0600
committerElizabeth Hunt <me@liz.coffee>2026-04-20 16:39:10 -0600
commit2422c8c8f39a6aac0b76945bb0c7aa4b6a2ab031 (patch)
tree645b2882ecd71918ae8778943a0704202c821070 /dyl.p8
parentf44fae1b7043fe9ed6803f989d9d1f53ff21f617 (diff)
downloaddyl8-2422c8c8f39a6aac0b76945bb0c7aa4b6a2ab031.tar.gz
dyl8-2422c8c8f39a6aac0b76945bb0c7aa4b6a2ab031.zip
Bruh
Diffstat (limited to 'dyl.p8')
-rw-r--r--dyl.p861
1 files changed, 36 insertions, 25 deletions
diff --git a/dyl.p8 b/dyl.p8
index 671661c..3c20be7 100644
--- a/dyl.p8
+++ b/dyl.p8
@@ -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()