abad={x=24,y=24,flip=false,frame=1,wait=0,hab=0,vides=3,energia=40,step=0,update=nil,jumpfwd=false,anim={0,1,0,2},bb={x=4,y=0,w=8,h=16}} function abad_init() abad.update=abad_state_normal end function abad:draw() local flip=abad.flip if abad.update==abad_state_stairs then flip=(((abad.x>>1)+(abad.y>>1))%2)==0 end sspr(abad.frame*16,0,16,16,abad.x,abad.y,16,16,flip) end function abad_state_normal() abad.frame=0 abad.wait=0 abad.step=0 abad.jumpfwd=false if btn(KEY_RIGHT) then abad.update=abad_state_walking abad.flip=false elseif btn(KEY_LEFT) then abad.update=abad_state_walking abad.flip=true elseif btn(KEY_UP) then abad.update=abad_state_jumping abad.step=0 abad.jumpfwd=false elseif btn(KEY_DOWN) then abad.update=abad_state_crouch elseif btn(KEY_SPACE) and cacau.hab==-1 then abad.update=abad_state_fire abad.wait=0 cacau.init(abad.hab,abad.x+8,abad.y+8,abad.flip) end end function abad_state_crouch() abad.bb.y=8 abad.bb.h=8 abad.frame=5 abad.wait=0 abad.step=0 abad.jumpfwd=false if not btn(KEY_DOWN) then abad.update=abad_state_normal abad.bb.y=0 abad.bb.h=16 end end function abad_state_fire() abad.frame=6 abad.wait=abad.wait+1 if abad.wait==6 then abad.wait=0 abad.update=abad_state_normal end end function abad_advance() local inc=12 if abad.flip then inc=2 end local limit=tiletype.block if abad.update~=abad_state_walking then limit=tiletype.half end if not abad.flip and abad.x==84 then abad.hab=abad.hab+1 abad.x=-4 elseif check_tile(abad.hab,abad.x+inc,abad.y+14)0 then if check_tile(abad.hab,abad.x+4,abad.y-2)~=tiletype.block then if (abad.x+4)&7==0 or check_tile(abad.hab,abad.x+12,abad.y-2)~=tiletype.block then if check_tile(abad.hab,abad.x+4,abad.y-2)==tiletype.switch then -- Executar el switch local xx=min(11,max(0,flr((abad.x+4)/8))) local yy=min(5,max(0,flr((abad.y-2)/8))) switches.start(abad.hab,1+xx+yy*12) --cls(4) elseif (abad.x+4)&7~=0 and check_tile(abad.hab,abad.x+12,abad.y-2)==tiletype.switch then -- Executar el switch local xx=min(11,max(0,flr((abad.x+12)/8))) local yy=min(5,max(0,flr((abad.y-2)/8))) switches.start(abad.hab,1+xx+yy*12) --cls(4) else abad.y=abad.y-2 end end end else abad.hab=abad.hab-10 abad.y=32 end elseif abad.step>6 then abad.update=abad_state_falling end abad.step=abad.step+1 end end function abad_state_falling() abad.frame=3 abad.wait=abad.wait+1 if abad.wait==6 then abad.wait=0 if abad.jumpfwd then abad_advance() end local xx=flr((abad.x+4)/8) local yy=flr((abad.y+16)/8) if abad.y<32 then if (abad.y+16)&7==0 and (check_tile(abad.hab,abad.x+4,abad.y+16)>=tiletype.half or ((abad.x+4)&7~=0 and check_tile(abad.hab,abad.x+12,abad.y+16)>=tiletype.half)) then abad.update=abad_state_normal return end abad.y=abad.y+2 else abad.hab=abad.hab+10 abad.y=0 end end end function abad_state_stairs() abad.frame=4 abad.wait=abad.wait+1 if abad.wait==6 then abad.wait=0 if btn(KEY_RIGHT) then abad.flip=false abad_advance() elseif btn(KEY_LEFT) then abad.flip=true abad_advance() elseif btn(KEY_UP) then if abad.y>0 then if check_tile(abad.hab,abad.x+4,abad.y+8)==tiletype.stair or (abad.x+4)&7~=0 and check_tile(abad.hab,abad.x+12,abad.y+8)==tiletype.stair then abad.y=abad.y-2 end else abad.hab=abad.hab-10 abad.y=32 end elseif btn(KEY_DOWN) then if abad.y<32 then if check_tile(abad.hab,abad.x+4,abad.y+16)==tiletype.stair or (abad.x+4)&7~=0 and check_tile(abad.hab,abad.x+12,abad.y+16)==tiletype.stair then abad.y=abad.y+2 end else abad.hab=abad.hab+10 abad.y=0 end end end end