summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2026-04-21 12:41:00 -0700
committerElizabeth Hunt <me@liz.coffee>2026-04-21 12:41:00 -0700
commit3555b9ff88c3872c8f2dd8a8ab02382e2a7d0cb2 (patch)
tree55c6925e4dd9cf7f8fac76fb6b3bcef4f1a9b30a
parent2422c8c8f39a6aac0b76945bb0c7aa4b6a2ab031 (diff)
downloaddyl8-3555b9ff88c3872c8f2dd8a8ab02382e2a7d0cb2.tar.gz
dyl8-3555b9ff88c3872c8f2dd8a8ab02382e2a7d0cb2.zip
mov
-rw-r--r--dyl.p834
1 files changed, 18 insertions, 16 deletions
diff --git a/dyl.p8 b/dyl.p8
index 3c20be7..95f2e59 100644
--- a/dyl.p8
+++ b/dyl.p8
@@ -40,7 +40,7 @@ sword={
player={
id=next_id(),
typ=types.player,
- pos={x=10,y=10},
+ pos={x=50,y=50},
spritepos={x=10,y=10},
vel={x=0,y=0},
los={x=1,y=0}, -- lineofsight
@@ -125,9 +125,6 @@ end
-- behind the physical position
--
function update_spritepos(entity)
- --entity.spritepos.x=entity.pos.x
- --entity.spritepos.y=entity.pos.y
-
-- step in only x or y.
-- we can snap to the grid
-- without cobblestoning.
@@ -138,30 +135,35 @@ function update_spritepos(entity)
end
nv=normalize(entity.vel)
- dx,dy=abs(entity.pos.x-entity.spritepos.x),abs(entity.pos.y-entity.spritepos.y)
+ dx,dy=entity.pos.x-entity.spritepos.x,entity.pos.y-entity.spritepos.y
+ adx,ady=abs(dx),abs(dy)
yslow=abs(entity.vel.y)<abs(entity.vel.x)
- xslow=not yslow
+ xslow=abs(entity.vel.x)<=abs(entity.vel.y)
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
+ jerkdelta=1
+ if adx>=jerkdelta and xslow
+ and ady>=1 then
+ pushx,pushy=true,true
+ elseif ady>=jerkdelta and yslow
+ and adx>=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
+ elseif xslow and ady>=1 then
pushy=true
- elseif yslow and dx>=1 then
+ elseif yslow and adx>=1 then
pushx=true
end
if pushx then
- entity.spritepos.x=entity.pos.x
+ func=flr
+ if dx<0 then func=ceil end
+ entity.spritepos.x=entity.spritepos.x+func(dx)
end
if pushy then
- entity.spritepos.y=entity.pos.y
+ func=flr
+ if dy<0 then func=ceil end
+ entity.spritepos.y=entity.spritepos.y+func(dy)
end
end