From f44fae1b7043fe9ed6803f989d9d1f53ff21f617 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Mon, 20 Apr 2026 16:10:24 -0600 Subject: Init --- dyl.p8 | 403 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 403 insertions(+) create mode 100644 dyl.p8 (limited to 'dyl.p8') diff --git a/dyl.p8 b/dyl.p8 new file mode 100644 index 0000000..671661c --- /dev/null +++ b/dyl.p8 @@ -0,0 +1,403 @@ +pico-8 cartridge // http://www.pico-8.com +version 43 +__lua__ +------------------------ +-- don't you leave -- +-- emprespresso, 2026 -- +------------------------ + +walk_speed=35 -- powerup increase? +step_t=time() +step_dt=0 + +id=0 +function next_id() + i=id + id=id+1 + return i +end + +types={ + player=0, + sword=1, + enemy=2, +} + +sword={ + id=next_id(), + typ=types.sword, + theta=0, -- pi/2=1,discrete [0,1] + pos={x=10,y=10}, + spritepos={x=10,y=10}, + states={ + equip={seq={83},dt=1}, + }, + state="equip", + state_t=step_t, + reflect={x=false,y=false}, +} + +player={ + id=next_id(), + typ=types.player, + pos={x=10,y=10}, + spritepos={x=10,y=10}, + vel={x=0,y=0}, + los={x=1,y=0}, -- lineofsight + states={ + idlex={seq={0,1},dt=1}, + idlepy={seq={3,19},dt=1}, + idleny={seq={6,22},dt=1}, + walkx={seq={2,0},dt=0.20}, + walkpy={seq={4,5},dt=0.20}, + walkny={seq={7,8},dt=0.20}, + }, + state="idle", + state_t=step_t, + equipped={sword}, + reflect={x=false,y=false}, +} + +enemy={ + id=next_id(), + typ=types.enemy, + pos={x=20,y=20}, + spritepos={x=20,y=20}, + vel={x=0,y=0}, + los={x=-1,y=0}, -- lineofsight + states={ + idlex={seq={32,33},dt=1}, + idlepy={seq={32,33},dt=1}, + idleny={seq={32,33},dt=1}, + walkx={seq={32,34},dt=0.28}, + walkpy={seq={32,34},dt=0.28}, + walkny={seq={32,34},dt=0.28}, + }, + state="idle", + state_t=step_t, + reflect={x=false,y=false}, + knockback={vector={x=0,y=0},remaining=0} +} + +entities={player,sword,enemy} + +sw,sh=8,8 +function is_colliding(a,b) + ax1,bx1=a.pos.x,b.pos.x + ax2,bx2=ax1+sw,bx1+sw + ay1,by1=a.pos.y,b.pos.y + ay2,by2=ay1+sh,by1+sh + return (ax1bx1 and + ay1by1) +end + +function handle_collision(a,b) + if b.typ==types.enemy then + --print(b.id,100,100) + end +end + +function run_collisions() + for _ai,a in ipairs(entities) do + for _bi,b in ipairs(entities) do + if a.id==b.id then + goto continue + end + if is_colliding(a,b) then + handle_collision(a,b) + end + ::continue:: + end + end +end + +function enter_state(entity, state) + if state==entity.state then + return + end + entity.tstate=step_t + entity.state=state +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. +function update_spritepos(entity) + tx=flr(entity.pos.x) + ty=flr(entity.pos.y) + dx=tx-entity.spritepos.x + dy=ty-entity.spritepos.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) + 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 + end + + entity.spritepos.x+=mid(-1,dx,1) + entity.spritepos.y+=mid(-1,dy,1) +end + +suffixes={"ny","","py"} +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 + ndx,ndy=normalize_scalar(dx),normalize_scalar(dy) + + if ndy!=0 then + walksuffix=suffixes[ndy+2] + enter_state(entity,"walk"..walksuffix) + elseif ndx!=0 then + enter_state(entity,"walkx") + end + + if ndx!=0 then + entity.los={x=ndx,y=0} + end + if ndy!=0 then + entity.los={x=0,y=ndy} + end + entity.reflect.x=(entity.los.x<0) + + if ndx==0 and ndy==0 then + if entity.los.x!=0 then + enter_state(entity,"idlex") + elseif entity.los.y!=0 then + suffix=suffixes[entity.los.y+2] + enter_state(entity,"idle"..suffix) + end + end + end + + if entity.equipped!=nil then + foreach(entity.equipped, + equipped_from(entity)) + end +end + +function equipped_from(entity) + return function(equipped) + if entity.los.y!=0 then + equipped.theta=1 + else + equipped.theta=0 + end + equipped.reflect={ + x=(entity.los.x<0 or entity.los.y<0), + y=(entity.los.y>0) + } + equipped.pos.y=entity.pos.y+entity.los.y*6 + equipped.pos.x=entity.pos.x+entity.los.x*6 + equipped.spritepos.x=flr(entity.spritepos.x+entity.los.x*6) + equipped.spritepos.y=flr(entity.spritepos.y+entity.los.y*6) + end +end + +function get_frame(anim,t,theta) + len=rawlen(anim.seq) + frames_passed=(t/anim.dt) + idx=flr(1+(frames_passed%len)) + dspritey=0 + if theta==1 then dspritey=16 end + return anim.seq[idx]+dspritey +end + +function draw(entity) + a=entity.states[entity.state] + t=step_t-entity.state_t + f=get_frame(a,t,entity.theta) + spr(f, + entity.spritepos.x,entity.spritepos.y, + 1,1, + entity.reflect.x,entity.reflect.y + ) +end + + +function handle_input() + dx,dy=0,0 + if btn(⬅️) then dx=dx-1 end + if btn(➡️) then dx=dx+1 end + if btn(⬇️) then dy=dy+1 end + if btn(⬆️) then dy=dy-1 end + + player.vel= + vec_scale( + normalize({x=dx,y=dy}), + walk_speed + ) +end + +function _init() + +end + +function _update60() + cls(0) + old_step=step_t + step_t=time() + step_dt=step_t-old_step + + handle_input() + run_collisions() + foreach(entities,update) +end + +function _draw() + foreach(entities,draw) +end + +function magnitude(vec) + return sqrt(vec.x*vec.x+vec.y*vec.y) +end + +function normalize_scalar(val) + if val!=0 then + return val/abs(val) + end + return val +end + +function vec_scale(vec,s) + return {x=vec.x*s,y=vec.y*s} +end + +function vec_add(a,b) + return {x=a.x+b.x,y=a.y+b.y} +end + +function normalize(vec) + m=magnitude(vec) + if m!=0 then + return {x=vec.x/m,y=vec.y/m} + end + return vec +end +__gfx__ +00000000000000000000000000000000000000000000000000000c0000000c0000000c0000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005555555 +00000000000000000000000000655000006550000065500000c7c60000c7c60000c7c60000000000000000000000000000000000000000000000000005555555 +006c7c0000000000006c7c00006c7c00006c7c00006c7c00005556000055560000555600000000000000000000000000000000000000000000000000055a0755 +00c1c100006c7c0000c1c10000c1c10000c1c10000c1c10000055000000550000005500000000000000000000000000000000000000000000000000005508555 +005ccc0c00c1c10c005ccc0c00000000000000000000000000000000000004000040000000000000000000000000000000000000000000000000000005505f55 +00000000005ccc000000000000400400000004000040000000400400004000000000040000000000000000000000000000000000000000000000000005555555 +004004000040040000044000000c0000004c0000000c040000000000000000000000000000000000000000000000000000000000000000000000000005555555 +00000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000c7c600000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000555600000000000000000000000000000000000000000000000000000000000000000000000000 +007eee00000000000000000000655000000000000000000000055000000000000000000000000000000000000000000000000000000000000000000000000000 +00e0e000007eee0000000000006c7c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00eeee0000e0e0000000000000c1c100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +0000000000eeee000000000000400400000000000000000000400400000000000000000000000000000000000000000000000000000000000000000000000000 +002002000020020000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00b33330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +0033a3a000b3333000b3333000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +003b33300033a3a00033a3a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00055b00003b3330003b333000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +0005b3000005b3000005b30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00335350003353500033535000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00500030005000300005030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000030005c00050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +04444000000000000000300005cc0c50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +0499400000000000000880000511c150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +04444000000000000087880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00440000000000000088880005111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000008800000555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00040000000400000000007000000040000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00504000005040000000075000030400000008e00005500005090000000900000000000000000000000000000000000000000000000000000000000000000000 +0050900005777900000075000000400000008e000055560000555550055555600000000000000000000000000000000000000000000000000000000000000000 +005040000500400000975000000404000058e0000006550000550000005500000000000000000000000000000000000000000000000000000000000000000000 +00504000005040000049000000400030006500000055500000500000005000000000000000000000000000000000000000000000000000000000000000000000 +00040000000400000400000004000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000007000000040000000800000000000050000000600000000000000000000000000000000000000000000000000000000000000000000 +00000000000900000000075000030400000008e00006500000050000000500000000000000000000000000000000000000000000000000000000000000000000 +0049440000474400000075000000400000008e000055550000050000000500000000000000000000000000000000000000000000000000000000000000000000 +040000400407004000975000000404000058e0000055650000955000009550000000000000000000000000000000000000000000000000000000000000000000 +00555500005705000049000000400030006500000005050000055500000555000000000000000000000000000000000000000000000000000000000000000000 +00000000000550000400000004000000060000000000000000500000000500000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00056000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000005650600000000000000000000005006500000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000560000000000000000005606056600650000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000060000000000000000650005665000660000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000650000005605000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000056600000000000000006000050000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000600000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +77055505000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000004444005555505000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +05550555044004405000055000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000040000400505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +55077705040550400550050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +0000000004000a400505550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +05550555040000400550050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +__sfx__ +000100002605026050240502305022050210502105021050220500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00090000000502b3502b3502a35029350293503235032350313503134031330209303032030320303303034031340313403334034340373400f050340502f0502c05000000000000000000000000000000000000 -- cgit v1.3