0,]']>S}Wup8d%qy)6o;]AsVl3>??????? PQ0S@U`XpZp\p^p_pPPPPPPPPPPPPPPPPPPPPP 0000p0p0p000000000000000000000000 `@@ @ @@@ @ @@@@@@@@@@@@@@@@@@@@@@@ 037<??000000000000000000000000 $@@@@@@@@@@@ @@@@ @@@@@ @@@@ @@@@@@H,bbbbbbv+*v+   v+*v+t) ,g *v+v+t)pPbbHbbbbbBJ Jj JJ * JjJ Jj JJ * JjJ Jj JJ *jjjjJJJ JJfF&v)*6)c c cc c cccc c cc c cccc c cc c cccc c cc c cccT)T(`@  [(``{/`@ bBi*`@ v)*6)0 , g g     v,`@ t,v,v,`@ t,`t,`y,`{,`@ ~,t,{,`@ y,`y,{,`       v,pp ppy,nnnn       c ccccccc c ccc  c ccccccc c ccc v,ggg gv,gg ggv,   v,   v,    c ccccccc c ccc  c ccccccc c ccc bbbb6'6' 8'8'   9'9'  ccc cc c  c cc c c  c c cCc c c ccccc cc c  c cc c c  c c cCc c c c ccccv,pp pkK+='g?'g?'g['g='g?'g?'g['g]'gM'gQ0fF&   f*gh*gm*GfF&ifiFi&iiiΆniifiFif*f*h*h*h*h*y,{,t,t*                     ɆɆ†f*f*h*h*h*h*y,{,y,,i*i*k*l*l*n* ,,,,z,                  g gg g g g g g g gg g g gg g g g g g g ggbbidD$$d c c c c ccccccccc c c c c cbbbbbb           n0n   G$4$@@R@R@@@@XXXXX\Xxx@x#x x@xx((+ + o ܹ ܹ ԳԴԳ  FT4dĴtT4dĴt? " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " """"""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""" " " " " " " " " " " " " " " " """"""""""""""""""""""""""""""""""""""""""""""""" " " " " " " " " " " " " " " " """"""""""""""""""""""""""""""""""""""""""""""""" " " " " " " " " " " " " " " " """"""""""""""""""""""""""""""""""""""""""""""""" " " " " " " " " " " " " " " " """""""""""""""""""""""""""""""""nn""""""""""""fefe""""nV\nV\ " " " " " " " " " " " "nWunWu " " " "vgvg""""""""""""nn""""_U""""""""""""UU""""""""UUnn""""""""""""UUfe""""fe""""_UnV\oV\ " " " " " " " " " RU% "UnWu " " " "oWu " " " "UUU_vgvg""""""""""UU"n""""n""""UU"""""""""""RU""""""""""""nn""""""""""""^Ufe""""""""fe""""_UnV\oV\ " " " " " " " " "UUU" "^UnWu " " " " " " " "oWu " " " "UUUvgvg"""""""""UUU"n""""""""n""""UUUUUU""""""""UUU^fUU%"""""""^U_UUn""""""""VU"""""""fe^oV\ " " " " " " " "^%" " " " " " " "oWu^fffvg""""""""UUU""""""""n^U"""""""""U"""""""nnn""""""""""""fefe""""fenV\nV\oV\ " " " " " " " " " " " "nWunWu " " " "oWuvgvgvg""""""""UUU""""nn""""n^UUUU"""""""U%^UUUU""""""""""_UU^UUUUnn"""""""RUUUUU""fe""""fe""""_UUnV\oV\ " " " " " " RUU " " " "nWu " " " "oWu " " " "_UUvgvg"""""""RUU""""n""""n""""U"""""""U%""""""""""""_UU^U_Unn"""""""RUUUUUUU""fe""""""""fe_UUUUUUUnV\oV\ " " " " " " "U%UUUUU " "nWu " " " " " " " "oWuP^^U^U_Uvgvg""""""""UUU""""n""""""""nUUUUU^U"""""""""""RUU%UU"UU""""""""""""""""""""""""""""""""_UU_UUU"""""""""""RUU""UU%"""""""""""""""""""""""""""""""UUUU " " " " " " " " " " "PUU"%" "UU%" " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " "PUU_UUU""""""""""RURUU%"RU""""""""""""""""""""""""""""""""UUUUU ^UUUU^UUUU^UU^U^^^UUUUUUUU^UUUUU^%-- title: Multiple Maze -- author: verysoftwares -- desc: room-shifting puzzle-platformer. -- script: lua t=0; at=0; start_t=0 x=7*8+1 y=0*8+2 dx=0 dy=0 onladder=0 sx=110-20-20-50; sy=62-12-12-26 debug=false if debug then sx=sx+40; sy=sy+24 end if debug then sx=170-50; sy=98-26 end if debug then sx=120; sy=60; x=x+8*8 end if debug then sx=100; sy=0; y=y+8 end if debug then sx=140; sy=84; x=3*8; y=3*8; mset(152,92,98) end if debug then sx=140; sy=0; x=18*8; y=5*8; end if debug then sx=180; sy=24; x=18*8; y=5*8; end --if debug then sx=140; sy=85; x=x+6*8 end gemcombo=0 gemcombo_t=0 gems=0 gem_get={} deaths=0 save_sx=sx; save_sy=sy save_x=x; save_y=y enemies={} orient={dx=0,dy=1} music(2) function update() if t==0 and not debug then alert({'Welcome to the maze!','Arrow keys or D-pad to move.'},function() for i=0,3 do if btnp(i) then return true end end end) end if t==0 then -- spawn enemies for mx=0,240-1 do for my=0,136-1 do if mget(mx,my)==40 then mset(mx,my,0) table.insert(enemies,{type='bat',x=mx*8+2,y=my*8+2,dx=-0.5,stx=mx*8+2,sty=my*8+2}) end if mget(mx,my)==108 then mset(mx,my,0) table.insert(enemies,{type='saw',x=mx*8+1,y=my*8+1,dx=0.5,dy=0,stdx=0.5,stdy=0,stx=mx*8+1,sty=my*8+1}) end if mget(mx,my)==109 then mset(mx,my,0) table.insert(enemies,{type='saw',x=mx*8+1,y=my*8+1,dx=-0.5,dy=0,stdx=-0.5,stdy=0,stx=mx*8+1,sty=my*8+1}) end end end end if TIC==update and (not banner_msg or (banner_t2 and banner_t2>0)) then if onladder==1 and btn(0) then if dy>0 then dy=0; climb_t=t end; dy=dy-0.2 end if onladder==1 and btn(1) then if dy<0 then dy=0; climb_t=t end; dy=dy+0.2 end --if btn(1) then y=y+1 end if ((orient.dy>0 and btn(0)) or (orient.dy<0 and btn(1)) or (orient.dx<0 and btn(3)) or (orient.dx>0 and btn(2)) or btn(4)) and onground and (not jump) and (orient.dx~=0 or onladder==0) and (orient.dx~=0 or mget(sx+x//8,sy+y//8)~=33) then if dy>0 then dy=0 end; dx=dx-orient.dx*2.8; dy=dy-orient.dy*2.8; jump=0; onladder=0 end if orient.dx==0 then if btn(2) then if dx>0 then dx=0; plr_t=t end; if btnp(2) then plr_t=t end dx=dx-0.2; if orient.dy>0 then lastflip=1 elseif orient.dy<0 then lastflip=0 end end if btn(3) then if dx<0 then dx=0; plr_t=t end; if btnp(3) then plr_t=t end dx=dx+0.2; if orient.dy<0 then lastflip=1 elseif orient.dy>0 then lastflip=0 end end else if btn(0) then if dy>0 then dy=0; plr_t=t end; if btnp(0) then plr_t=t end dy=dy-0.2; if orient.dx<0 then lastflip=2 elseif orient.dx>0 then lastflip=0 end end if btn(1) then if dy<0 then dy=0; plr_t=t end; if btnp(1) then plr_t=t end dy=dy+0.2; if orient.dx>0 then lastflip=2 elseif orient.dx<0 then lastflip=0 end end end if (orient.dy~=0 and math.abs(dx)<0.02) or (orient.dx~=0 and math.abs(dy)<0.02) then plr_t=nil; if orient.dy~=0 then dx=0 end if orient.dx~=0 then dy=0 end end if btnp(5) and (gem_msg or debug) and not (banner_msg and banner_msg[1]=='Ouch!') then TIC=mapscr end end detect_gamepad() --spr(1+t%60//30*2,x,y,14,3,0,0,2,2) --print("HELLO WORLD!",84,84) --print(jump) --print(onladder,0,8) cls(0) --print(control) rect(240/2-80,136/2-48,80*2,48*2,14) rect(240/2-80-8-160,136/2-48,80*2,48*2,14) rect(240/2-80+8+160,136/2-48,80*2,48*2,14) rect(240/2-80,136/2-48-8-96,80*2,48*2,14) rect(240/2-80,136/2-48+8+96,80*2,48*2,14) processmap(0,0,0,0,0) processmap(0,-1,0,0,0) processmap(0,1,0,0,0) processmap(-1,0,0,0,0) processmap(1,0,0,0,0) processmap(-1,-1,0,0,0) processmap(-1, 1,0,0,0) processmap( 1,-1,0,0,0) processmap( 1, 1,0,0,0) drawmap(0,0,0,0,0) drawmap(0,-1,0,0,0) drawmap(0,1,0,0,0) drawmap(-1,0,0,0,0) drawmap(1,0,0,0,0) update_goo() rect(0,136/2-48-8,240,8,0) rect(240/2-80-8,0,8,136,0) rect(0,136/2+48,240,8,0) rect(240/2+80,0,8,136,0) --map(sx,sy-12,20,12,240/2-80,136/2-48-8-96,1) --spr(48,x+240/2-80,y+136/2-48,1) clip(240/2-80,136/2-48,160,96) --rect(x+240/2-80,y+136/2-48,6,6,0) --local sp if not plr_t then sp=304 end if onladder==1 then if dy<=0 and btn(0) then if (at-climb_t)%18<=17 then sp=355 end if (at-climb_t)%18<=17-6 then sp=356 end if (at-climb_t)%18<=17-6-6 then sp=354 end elseif dy>=0 and btn(1) then if (at-climb_t)%18<=17 then sp=354 end if (at-climb_t)%18<=17-6 then sp=356 end if (at-climb_t)%18<=17-6-6 then sp=355 end end elseif jump then sp=352+jump//4; if jump>=16 then sp=304 end elseif squash then if squash>3 then sp=352 else sp=353 end; squash=squash-1 if squash==0 then squash=nil end elseif plr_t then if (at-plr_t)%24<=23 then sp=288+32+3 end if (at-plr_t)%24<=23-6 then sp=288+32+2 end if (at-plr_t)%24<=23-6-6 then sp=288+32+1 end if (at-plr_t)%24<=23-6-6-6 then sp=288+32+0 end end flip=0 if dx<0 then flip=1 end if dx==0 then flip=lastflip end rot=0 nudgex,nudgey=0,0 if orient.dy<0 then rot=2; flip=0 nudgey=2 if dx>0 then flip=1 end if dx==0 then flip=lastflip end end if orient.dx<0 then if dy>0 then flip=0 else flip=2 end if dy==0 and lastflip~=1 then flip=lastflip end rot=1; nudgex=1 end if orient.dx>0 then if dy>0 then flip=2 else flip=0 end if dy==0 and lastflip~=1 then flip=lastflip end rot=3; nudgex=-1 end if TIC==idle then goto skipcoll end if onladder<1 then dx=dx+orient.dx*0.2; dy=dy+orient.dy*0.2 end for i,e in ipairs(enemies) do if e.type=='bat' then e.x=e.x+e.dx if not e.toggle then for mx=e.x//8-1,e.x//8+1 do for my=e.y//8-1,e.y//8+1 do local m=mget(mx,my) if (m==70 or m==71) and AABB(e.x,e.y,4,4,mx*8,my*8,8,8) then e.toggle={mx,my} end end end if e.toggle then toggle(e.toggle[1],e.toggle[2]) end else local toggle2=nil for mx=e.x//8-1,e.x//8+1 do for my=e.y//8-1,e.y//8+1 do local m=mget(mx,my) if (m==70 or m==71) and AABB(e.x,e.y,4,4,mx*8,my*8,8,8) then toggle2={mx,my} end end end if not toggle2 then e.toggle=nil end end for mx=e.x//8-1,e.x//8+1 do for my=e.y//8-1,e.y//8+1 do local m=mget(mx,my) if fget(m,2) and AABB(e.x,e.y,4,4,mx*8,my*8,8,8) then if mx*8e.x then e.x=mx*8-4 end e.dx=-e.dx end end end end if e.type=='saw' then if (e.x-1)%8==0 and (e.y-1)%8==0 then if e.dx~=0 and ((e.dx<0 and not fget(mget((e.x-1)//8,(e.y-1)//8-1),2)) or (e.dx>0 and not fget(mget((e.x-1)//8,(e.y-1)//8+1),2))) then if e.dx<0 then e.dy=-0.5 else e.dy=0.5 end e.dx=0; elseif e.dy~=0 and ((e.dy>0 and not fget(mget((e.x-1)//8-1,(e.y-1)//8),2)) or (e.dy<0 and not fget(mget((e.x-1)//8+1,(e.y-1)//8),2))) then if e.dy<0 then e.dx=0.5 else e.dx=-0.5 end e.dy=0; end end for mx=e.x//8-1,e.x//8+1 do for my=e.y//8-1,e.y//8+1 do local m=mget(mx,my) if fget(m,2) and AABB(mx*8,my*8,8,8,e.x-1,e.y-1,8,8) then if e.dx~=0 then if e.dx>0 then e.x=mx*8-8+1; e.dx=0; if fget(mget((e.x-1)//8,(e.y-1)//8-1),1) then e.dy=-0.5 elseif fget(mget((e.x-1)//8,(e.y-1)//8+1),1) then e.dy=0.5 else e.dx=-0.5 end--e.dx=0; e.dy=-0.5 else e.x=mx*8+8+1; e.dx=0; if fget(mget((e.x-1)//8,(e.y-1)//8+1),1) then e.dy=0.5 elseif fget(mget((e.x-1)//8,(e.y-1)//8-1),1) then e.dy=-0.5 else e.dx=0.5 end end--e.dx=0; e.dy=0.5 end elseif e.dy~=0 then if e.dy>0 then e.y=my*8-8+1; e.dy=0; if fget(mget((e.x-1)//8-1,(e.y-1)//8),1) then e.dx=-0.5 elseif fget(mget((e.x-1)//8+1,(e.y-1)//8),1) then e.dx=0.5 else e.dy=-0.5 end --e.dx=0; e.dy=-0.5 else e.y=my*8+8+1; e.dy=0; if fget(mget((e.x-1)//8+1,(e.y-1)//8),1) then e.dx=0.5 elseif fget(mget((e.x-1)//8-1,(e.y-1)//8),1) then e.dx=-0.5 else e.dy=0.5 end end--e.dx=0; e.dy=0.5 end end end if m==34 then if AABB((e.x+4)//8*8,(e.y+4)//8*8,8,8,mx*8+1,my*8+1,6,6) then mset((e.x+4)//8,(e.y+4)//8,35); if not gemroom(sx,sy) and mx<20 and mx>=0 and my<12 and my>=0 then sfx(4,'F-6',50,2) end end end end end e.x=e.x+e.dx e.y=e.y+e.dy end end for mx=x//8-1,x//8+1 do for my=y//8-1,y//8+1 do if (mget(sx+mx,sy+my)==39 and AABB(x,y,6,6,mx*8,my*8+4,8,4)) or (mget(sx+mx,sy+my)==41 and AABB(x,y,6,6,mx*8,my*8,8,4)) then die() goto skipcoll end end end for i,e in ipairs(enemies) do if e.type=='bat' then if AABB(sx*8+x,sy*8+y,6,6,e.x,e.y,4,4) then die() goto skipcoll end end if e.type=='saw' then if AABB(sx*8+x,sy*8+y,6,6,e.x,e.y,6,6) then die() goto skipcoll end end end if onground then onground=onground-1; if onground==0 then onground=nil end end for mx=x//8-1,x//8+1 do for my=y//8-1,y//8+1 do if mget(sx+mx,sy+my)==70 and AABB(x,y,6,6,mx*8,my*8+4,8,4) then if btnp(1) then toggle(sx+mx,sy+my) end if not switch_msg then alert({'Press down to flip switches.'},function() return btn(1) end); switch_msg=true end elseif mget(sx+mx,sy+my)==71 and AABB(x,y,6,6,mx*8,my*8+4,8,4) then if btnp(1) then toggle(sx+mx,sy+my) end if not switch_msg then alert({'Press down to flip switches.'},function() return btn(1) end); switch_msg=true end end end end for mx=x//8-1,x//8+1 do for my=y//8-1,y//8+1 do local m=mget(xmod(sx+mx),ymod(sy+my)) local function hiddenobjects() for mx=x//8-1,x//8+1 do for my=y//8-1,y//8+1 do local m=mget(xmod(sx+mx),ymod(sy+my)) if AABB(x,y,6,6,mx*8,my*8,8,8) and (m==73 or m==75 or m==102) then return true end end end for i,e in ipairs(enemies) do if AABB(e.stx,e.sty,8,8,sx*8+x,sy*8+y,6,6) then return true end end end if ((orient.dy>0 and dy>0 and y<=(my+1)*8) or (orient.dy<0 and dy<0 and y>=(my-1)*8+8)) and onladder<1 and fget(m,1) and mget(sx+mx,sy+my+1)==33 and AABB(x,y,6,6,(mx+orient.dx)*8+1,(my+orient.dy)*8,6,8) then onground=5; if (orient.dy~=0 and math.abs(dy)>0.4) or (orient.dx~=0 and math.abs(dx)>0.2) then squash=5; splatter(dy); if not (sy==60) and not (sx==180 and sy==48) and not hiddenobjects() then save_sx=sx; save_sy=sy; save_x=x; save_y=(my+1)*8-6; gem_get={}; save_odx=orient.dx; save_ody=orient.dy end end; if dx~=0 then gootrail() end; y=(my+1)*8-6; dy=0; jump=false; onladder=0; if btn(1) then onladder=1; climb_t=t; y=y+0.2; goto skipy end end local m=mget(xmod(sx+mx),ymod(sy+my)) if (arrow('up',m) or arrow('right',m) or arrow('down',m) or arrow('left',m)) and AABB(x,y,6,6,mx*8+2,my*8+2,4,4) then local old_odx,old_ody=orient.dx,orient.dy if arrow('up',m) then orient={dx=0,dy=-1} end if arrow('down',m) then orient={dx=0,dy=1} end if arrow('left',m) then orient={dx=-1,dy=0} end if arrow('right',m) then orient={dx=1,dy=0} end --local value = peek(0xFF9C+18*2+1)<<8|peek(0xFF9C+18*2) --local volume=(value&0xf000)>>12 lastflip=0 if (old_odx~=orient.dx or old_ody~=orient.dy) then sfx(15,'F-6',40,2) end end local m=mget(xmod(sx+mx),ymod(sy+my)) if fget(m,2) and AABB(x,y,6,6,mx*8,my*8,8,8) then --print('yooo'); y=y-dy; goto skipy if my*8=0 then y=my*8+8; onladder=0; goto skipy end if orient.dy<0 then onground=5; if dy<-0.4 then squash=5; splatter(-dy); if not (sy==60) and not (sx==180 and sy==48) and not hiddenobjects() then save_sx=sx; save_sy=sy; save_x=x; save_y=my*8+8; gem_get={}; save_odx=orient.dx; save_ody=orient.dy end else if dx~=0 then gootrail() end end; y=my*8+8; dy=0; jump=false; onladder=0; if (btn(0)) then goto skipy else goto skipy2 end end elseif my*8>y then if orient.dy>0 then onground=5; if dy>0.4 then squash=5; splatter(dy); if not (sy==60) and not (sx==180 and sy==48) and not hiddenobjects() then save_sx=sx; save_sy=sy; save_x=x; save_y=my*8-6; gem_get={}; save_odx=orient.dx; save_ody=orient.dy end else if dx~=0 then gootrail() end end; y=my*8-6; dy=0; jump=false; onladder=0; if (btn(0)) then goto skipy else goto skipy2 end end if orient.dy<=0 then y=my*8-6; onladder=0; goto skipy end end end end end for mx=x//8-1,x//8+1 do for my=y//8-1,y//8+1 do if mget(sx+mx,sy+my)==34 and AABB(x,y,6,6,mx*8+1,my*8+1,6,6) then mset(sx+mx,sy+my,35); table.insert(gem_get,{sx+mx,sy+my}); gems=gems+1; collect=15; sfx(1,12*3+9+gemcombo,16,2); gemcombo=gemcombo+1; gemcombo_t=30; if not gemroom(sx,sy) and mx<20 and mx>=0 and my<12 and my>=0 then sfx(4,'F-6',50,2) end end end end ::skipy:: for mx=x//8-1,x//8+1 do for my=y//8-1,y//8+1 do if mget(sx+mx,sy+my)==33 and (btn(0) or btn(1)) and AABB(x,y,6,6,mx*8+1,my*8,6,8) then if onladder==0 then dy=0; climb_t=t end; x=mx*8+1; onladder=1; jump=false; goto skipx end end end ::skipy2:: x=x+dx for mx=x//8-1,x//8+1 do for my=y//8-1,y//8+1 do local m=mget(xmod(sx+mx),ymod(sy+my)) if fget(m,2) and AABB(x,y,6,6,mx*8,my*8,8,8) then --print('yooo'); x=x-dx; goto skipx if mx*8x then if orient.dx>0 then onground=5; jump=false; onladder=0; if dx>0.2 then squash=5; splatter(dx); if not (sx==200 and sy==24+12 and x>20*8-8) then save_sx=sx; save_sy=sy; save_x=mx*8-6; save_y=y; save_odx=orient.dx; save_ody=orient.dy; gem_get={} end end end x=mx*8-6; dx=0; goto skipx end end end end for mx=x//8-1,x//8+1 do for my=y//8-1,y//8+1 do if mget(sx+mx,sy+my)==34 and AABB(x,y,6,6,mx*8+1,my*8+1,6,6) then mset(sx+mx,sy+my,35); table.insert(gem_get,{sx+mx,sy+my}); gems=gems+1; collect=15; sfx(1,12*3+9+gemcombo,16,2); gemcombo=gemcombo+1; gemcombo_t=30; if not gemroom(sx,sy) and mx<20 and mx>=0 and my<12 and my>=0 then sfx(4,'F-6',50,2) end end end end ::skipx:: if y>=96 then TIC=cooltrans; tr={dx=0, dy=4, t=t} end--sy=sy+12; y=y-96 end if y<-6 then TIC=cooltrans; tr={dx=0, dy=-4,t=t} end--sy=sy-12; y=y+96 end if x>=160 then TIC=cooltrans; tr={dx=4, dy=0, t=t} end--sy=sy+12; y=y-96 end if x<=-6 then TIC=cooltrans; tr={dx=-4,dy=0, t=t} end--sy=sy-12; y=y+96 end if onladder==1 and ((mget(sx+x//8,sy+y//8)~=33 and mget(sx+x//8,sy+y//8+1)~=33) or (mget(sx+x//8,sy+y//8)~=33 and mget(sx+x//8,sy+y//8+1)==33 and not AABB(x,y,6,6,x//8*8+1,y//8*8+8,6,8))) then onladder=0.5 end if orient.dx==0 then dx=dx*0.84 dy=dy*0.95 else dx=dx*0.95 dy=dy*0.84 end if onladder==1 then dy=dy*0.88 end ::skipcoll:: if not end_msg then spr(sp,x+240/2-80-1+nudgex,y+136/2-48-2+nudgey,1,1,flip,rot) --spr(273,x+240/2-80-1,y+136/2-48-2,1) clip(240/2-80,96+8+136/2-48,160,96) --rect(x+240/2-80,(y-96)+96+8+136/2-48,6,6,0) spr(sp,x+240/2-80-1+nudgex,(y-96)+96+8+136/2-48-2+nudgey,1,1,flip,rot) clip(240/2-80,-96-8+136/2-48,160,96) --rect(x+240/2-80,(y+96)-96-8+136/2-48,6,6,0) spr(sp,x+240/2-80-1+nudgex,(y+96)-96-8+136/2-48-2+nudgey,1,1,flip,rot) clip(240/2-80-160-8,136/2-48,160,96) --rect((x-160-16)+160+8+240/2-80,y+136/2-48,6,6,0) spr(sp,(x-160-16)+160+8+240/2-80-1+nudgex,y+136/2-48-2+nudgey,1,1,flip,rot) clip(240/2-80+160+8,136/2-48,160,96) --rect((x+160+16)-160-8+240/2-80,y+136/2-48,6,6,0) spr(sp,(x+160+16)-160-8+240/2-80-1+nudgex,y+136/2-48-2+nudgey,1,1,flip,rot) end clip() y=y+dy --if math.abs(dx)>0 then splatter(0.5) end if not gem_msg and--[[sx==20 and sy==12 and]] not emptyroom(sx,sy) and not gemroom(sx,sy) then local keymsg='Press X to activate.' if control=='gamepad' then keymsg='Press % to activate.' end alert({'Brought together, the gems','resonate with ancient power...',keymsg},function() return btnp(5) end,function() TIC=mapscr; local keymsg='Use Z and arrows to shift rooms'; if control=='gamepad' then keymsg='Use $ and D-pad to shift rooms' end alert({'This is a map of the maze.',keymsg,'with no gems in them.'},anykey) end) TIC=idle dx=0; dy=0 gem_msg=true end --if sy>=62-12-12+2*12+2*12+12 and not end_msg and not debug then if not end_msg then for mx=x//8-1,x//8+1 do for my=y//8-1,y//8+1 do local m=mget(sx+mx,sy+my) if sy>=72 and sy<=108 and (m==104 or m==105) and AABB(mx*8,my*8,8,8,x,y,6,6) then if mget(sx+mx,sy+my+1)>=76 and mget(sx+mx,sy+my+1)<=101 and fget(mget(sx+mx,sy+my+1),4) then sfx(13,'A-6',55,2) TIC=warp plr_t=at else if not tele_msg then alert({'A teleporter.','It\'s offline.'},function() return btnp(4) or btnp(5) end) tele_msg=true end end end end end end if TIC==update then local tm=time()-start_t if math.floor(tm/(1000*60*60))==0 then local tw=print(string.format('%.2d:%.2d',math.floor(tm/(1000*60))%60,math.floor(tm/1000)%60),0,-6,12,true) print(string.format('%.2d:%.2d',math.floor(tm/(1000*60))%60,math.floor(tm/1000)%60),240/2-tw/2,8*2-2,11,true) else local tw=print(string.format('%.2d:%.2d:%.2d',math.floor(tm/(1000*60*60)),math.floor(tm/(1000*60))%60,math.floor(tm/1000)%60),0,-6,12,true) print(string.format('%.2d:%.2d:%.2d',math.floor(tm/(1000*60*60)),math.floor(tm/(1000*60))%60,math.floor(tm/1000)%60),240/2-tw/2,8*2-2,11,true) end local tw=print(string.format('Gems: %.3d',gems),0,-6,12,true) print(string.format('Gems: %.3d',gems),240/2-tw/2,8*3+8*12-2,11,true) end for mx=0,20-1 do for my=0,12-1 do local m= mget(sx+mx,sy+my) if m==70 or m==71 or m==104 or m==105 then spr(m,240/2-80+mx*8,136/2-48+my*8,1) end end end if t%3==0 then maintain_toggle() end draw_banner() if collect then if collect>0 then collect=collect-1; poke(0x3FF8,7-collect//5) else collect=nil; poke(0x3FF8,0) end end if not gemroom(sx,sy) and not emptyroom(sx,sy) then poke(0x3FF8,5) end if gemcombo_t>0 then gemcombo_t=gemcombo_t-1 if gemcombo_t==0 then gemcombo=0 end end --[[for fx=0,240-1 do for fy=0,136-1 do if pix(fx,fy)==0 then local c=4+math.cos(fx*(1+math.sin(t*0.01))+t*0.2)+math.sin(fx*0.2+fy*0.2+t*0.1)*4 if math.floor(c)==3 then c=2 end pix(fx,fy,c) end end end]] --local anim --if at%24<=11+5+7 then anim=1 end --if at%24<=11+5 then anim=0 end --if at%24<=11 then anim=2 end --spr(288+anim,8*6,8*6,1) if jump and jump<20 then jump=jump+1 end if gamecyc[gamecyc.i]=='BETATEST' then if not end_msg2 and not gemroom(180,24) and not gemroom(180+20,24) and not gemroom(180,24+12) and not gemroom(180+20,24+12) and not gemroom(180,24+12*2) then local tm=time()-start_t local tmsg if math.floor(tm/(1000*60*60))==0 then tmsg=string.format('Time taken: %.2d:%.2d.%.3d',math.floor(tm/(1000*60))%60,math.floor(tm/1000)%60,math.floor(tm%1000)) else tmsg=string.format('Time taken: %.2d:%.2d:%.2d.%.3d',math.floor(tm/(1000*60*60)),math.floor(tm/(1000*60))%60,math.floor(tm/1000)%60,math.floor(tm%1000)) end alert({'You\'ve collected all gems!','Thanks for playtesting!',string.format('Gems collected: %.3d',gems),string.format('Deaths: %d',deaths),tmsg},function() end) TIC=idle end_msg2=true end end poke(ADDR+3+3+3+0,0xEF) poke(ADDR+3+3+3+1,0x7D) poke(ADDR+3+3+3+2,0x57) poke(ADDR+3*11+0,0x73) poke(ADDR+3*11+1,0xEF) poke(ADDR+3*11+2,0xF7) palette=0 --spr(368+(t*0.2)%5,6*8,6*8,1) if TIC==update then at=at+1 end t=t+1 end tele_tx=100; tele_ty=0 function warp() drawmap(0,0,0,0,0) drawmap(0,-1,0,0,0) drawmap(0,1,0,0,0) drawmap(-1,0,0,0,0) drawmap(1,0,0,0,0) update_goo() pal(5,12); pal(6,12); pal(15,12); pal(14,12) local spx,spy if at-plr_t<=29 then spx,spy=12*8,7*8 if (at-plr_t)%30<=29 then sp=355 end if (at-plr_t)%30<=29-6 then sp=356 end if (at-plr_t)%30<=29-6-6 then sp=354 end if (at-plr_t)%30<=29-6-6-6 then sp=353 end if (at-plr_t)%30<=29-6-6-6-6 then sp=352 end else spx,spy=9*8,5*8 if (at-plr_t)%30<=29 then sp=352 end if (at-plr_t)%30<=29-6 then sp=353 end if (at-plr_t)%30<=29-6-6 then sp=354 end if (at-plr_t)%30<=29-6-6-6 then sp=356 end if (at-plr_t)%30<=29-6-6-6-6 then sp=355 end end flip=0 if dx<0 then flip=1 end if dx==0 then flip=lastflip end spr(sp,spx+240/2-80,spy+136/2-48,1,1,flip) pal() for mx=0,20-1 do for my=0,12-1 do local m= mget(sx+mx,sy+my) if m==70 or m==71 or m==104 or m==105 then spr(m,240/2-80+mx*8,136/2-48+my*8,1) end end end if at-plr_t==29 and not end_msg then --[[sx=tele_tx; sy=tele_ty x=9*8+1; y=5*8+2 save_sx=sx; save_sy=sy save_x=x; save_y=y save_odx=orient.dx; save_ody=orient.dy]] local tm=time()-start_t local tmsg if math.floor(tm/(1000*60*60))==0 then tmsg=string.format('Time taken: %.2d:%.2d.%.3d',math.floor(tm/(1000*60))%60,math.floor(tm/1000)%60,math.floor(tm%1000)) else tmsg=string.format('Time taken: %.2d:%.2d:%.2d.%.3d',math.floor(tm/(1000*60*60)),math.floor(tm/(1000*60))%60,math.floor(tm/1000)%60,math.floor(tm%1000)) end alert({'You\'ve escaped the maze!','Thanks for playing!',string.format('Gems collected: %.3d',gems),string.format('Deaths: %d',deaths),tmsg},function() end) TIC=idle end_msg=true end --[[if at-plr_t==29*2 then TIC=update end]] plr_t=plr_t-1 t=t+1 end function idle() update() end --for mx=50,209 do for my=26,97 do -- mset(mx-50,my-26,mget(mx,my)) -- mset(mx,my,0) --end end --sync(4,0,true) function credits() map(0,102,30,17,0,0) local tw tw=print('Game by: verysoftwares',0,-6,11) print('Game by: verysoftwares',10*8+5*8-tw/2,8*5-2,11) tw=print('Speedrunners:',5*8,-6,11) print('Speedrunners:',10*8-8-tw/2,8*5-2+8+8,11) tw=print('* Jayrude',7*8-1,-6,11) print('* Jayrude',10*8-8-tw/2,8*6-2+8+8,11) tw=print('* Ten',7*8-1,-6,11) print('* Ten',10*8-8-tw/2,8*6-2+8+8+8,11) tw=print('Key testers:',5*8+6,-6,11) print('Key testers:',10*8+10*8-tw/2,8*8-2+8+8-8-8-8,11) for i,v in ipairs({'Mark Brown','shiona','Stefan','Ten * Typhin','Yuho'}) do tw=print('* '..v,7*8-1,-6,11) print('* '..v,10*8+10*8-tw/2,8*10-2+8-8-8-8-8+8+(i-1)*8,11) end tw=print('Code helpers:',0,-6,11) print('Code helpers:',10*8-8-tw/2,8*7-2+8+8+8+8,11) tw=print('* BORB',0,-6,11) print('* BORB',10*8-8-tw/2,8*8-2+8+8+8+8,11) poke(ADDR+3*11+0,0x73) poke(ADDR+3*11+1,0xEF) poke(ADDR+3*11+2,0xF7) palette=0 if anykey() then TIC=titlescr end end gamecyc={i=1,'Standard','BETATEST'} function gamesel() if btnp(0) or btnp(2) then gamecyc.i=gamecyc.i-1 end if btnp(1) or btnp(3) then gamecyc.i=gamecyc.i+1 end if gamecyc.i<1 then gamecyc.i=#gamecyc end if gamecyc.i>#gamecyc then gamecyc.i=1 end if btnp(4) then if gamecyc[gamecyc.i]=='Standard' then sx=110-20-20-50; sy=62-12-12-26; x=7*8+1; y=0*8+2 end if gamecyc[gamecyc.i]=='BETATEST' then sx=180; sy=24+12; x=2*8; y=5*8 end TIC_pend=update TIC_tpend=true start_t=time() end rect(240/2-8*5,136/2-8*2,8*10,8*4,15) rect(240/2-8*5,136/2-8*2,8*10,8,6) rect(240/2-8*5,136/2-8*2,8,8*4,6) rect(240/2-8*5,136/2+8*1,8*10,8,6) rect(240/2+8*5-8,136/2-8*2,8,8*4,6) print('Game mode',240/2-8*5+8+8-2,136/2-8*2+1,12) for i,v in ipairs(gamecyc) do local c=13 if i==gamecyc.i then c=4+(t*0.2)%4 end local tw=print(v,0,-6,13) print(v,240/2-tw/2,136/2-8*2+8+1+(i-1)*8,c) end poke(ADDR+3+3+3+0,0xEF) poke(ADDR+3+3+3+1,0x7D) poke(ADDR+3+3+3+2,0x57) palette=0 t=t+1 end cycle={i=1,gamesel,options,credits} function titlescr() if dist==0 then if btnp(0) or btnp(2) then cycle.i=cycle.i-1 end if btnp(1) or btnp(3) then cycle.i=cycle.i+1 end if cycle.i<1 then cycle.i=#cycle end if cycle.i>#cycle then cycle.i=1 end end if btnp(4) and not banner_msg and dist==0 then --TIC_pend=cycle[cycle.i] TIC=cycle[cycle.i] if TIC==nil then TIC=titlescr end --if TIC_pend==update then --end if cycle[cycle.i]==options then alert({'Not yet implemented!'},function() if banner_t<180-1 then return anykey() end end) --TIC_pend=titlescr end end if btnp(4) then dist=0 end cls(11) dist= dist or 3*99 if dist>0 then dist=dist-3 end for mx=0,0+29-1 do for my=119,119+7-1 do local m=mget(mx,my) if (m>0 and m<32) or fget(m,2) then --rect(-dist+4+(mx-30)*8+1,4+(my-1)*8+1,8,8,0) for ix=0,7 do for iy=0,7 do if sprpix(m,ix,iy)~=1 then pix(-dist+4+(mx-0)*8+ix+1,4+(my-119)*8+iy+1,0) end end end end end end for mx=0,0+17-1 do for my=119+10,119+10+5-1 do local m=mget(mx,my) if (m>0 and m<32) or fget(m,2) then rect(240/2-60+dist-4+(mx-0)*8+1,8*7+(my-119-10)*8+1,8,8,0) end end end map(0,119,29,7,-dist+4,4,1) map(0,119+10,17,5,240/2-60+dist-4,8*7,1) if dist==0 then print('Version 2d',-dist+240/2+20,8*12+2,15) local tw for i,v in ipairs({'New game','Options','Credits'}) do local msg=v if i==cycle.i then if t%21<7 then msg='[ '..msg..' ]' elseif t%21<14 then msg='[[ '..msg..' ]]' else msg='[ '..msg..' ]' end end tw=print(msg,240/2-80+(i-1)*80,-6,12,false,1,true) print(msg,240/2-80+(i-1)*80-tw/2,136-8*2-8*2+(i-1)*8+2,12,false,1,true) end end draw_banner() poke(ADDR+3+3+3+0,0xEF) poke(ADDR+3+3+3+1,0x7D) poke(ADDR+3+3+3+2,0x57) palette=0 t=t+1 end TIC=update TIC=titlescr function gameover() poke(0x3FF8,2) poke(ADDR+3+3+3+0,0xEF) poke(ADDR+3+3+3+1,0x7D) poke(ADDR+3+3+3+2,0x57) palette=0 if keyp(19) or btnp(7) then sx=save_sx; sy=save_sy x=save_x; y=save_y dx=0; dy=0 goo={} orient.dx=save_odx; orient.dy=save_ody for i,e in ipairs(enemies) do if e.type=='bat' then e.x=e.stx; e.y=e.sty; e.dx=-0.5 end; if e.type=='saw' then e.x=e.stx; e.y=e.sty; e.dx=e.stdx; e.dy=e.stdy end end TIC=update poke(0x3FF8,0) for i,v in ipairs(gem_get) do mset(v[1],v[2],34) end gems=gems-#gem_get gem_get={} if not gemroom(sx,sy) and not emptyroom(sx,sy) then poke(0x3FF8,5) end end clip(240/2-80,136/2-48,160,96) cls(14) drawmap(0,0,0,0,0) drawmap(-1,0,0,0,0) drawmap(1,0,0,0,0) drawmap(0,-1,0,0,0) drawmap(0,1,0,0,0) update_goo() clip() draw_banner() t=t+1 end function die() TIC=gameover splatter(6) local keymsg='Press S to reset.' if control=='gamepad' then keymsg='Press & to reset.' end if #gem_get>0 then if #gem_get==1 then alert({'Ouch!','1 gem lost.',keymsg},function() return keyp(19) or btnp(7) end) else alert({'Ouch!',string.format('%d gems lost.',#gem_get),keymsg},function() return keyp(19) or btnp(7) end) end else alert({'Ouch!',keymsg},function() return keyp(19) or btnp(7) end) end sfx(11,'B-5',20,2) deaths=deaths+1 end function cooltrans() cls(0) poke(0x3FF8,0) dist=dist or 0 rect(240/2-80-tr.dx*(t-tr.t),136/2-48-tr.dy*(t-tr.t),80*2,48*2,14) local xdist=0 local ydist=0 if tr.dx~=0 then ydist=dist end if tr.dy~=0 then xdist=dist end rect(240/2-80-8-160-tr.dx*(t-tr.t)-xdist,136/2-48-tr.dy*(t-tr.t),80*2,48*2,14) rect(240/2-80+8+160-tr.dx*(t-tr.t)+xdist,136/2-48-tr.dy*(t-tr.t),80*2,48*2,14) rect(240/2-80-tr.dx*(t-tr.t),136/2-48-8-96-tr.dy*(t-tr.t)-ydist,80*2,48*2,14) rect(240/2-80-tr.dx*(t-tr.t),136/2-48+8+96-tr.dy*(t-tr.t)+ydist,80*2,48*2,14) if tr.dx<0 then rect(240/2-80-8*2-160*2-tr.dx*(t-tr.t),136/2-48-tr.dy*(t-tr.t),80*2,48*2,14) end if tr.dx>0 then rect(240/2-80+8*2+160*2-tr.dx*(t-tr.t),136/2-48-tr.dy*(t-tr.t),80*2,48*2,14) end if tr.dy<0 then rect(240/2-80-tr.dx*(t-tr.t),136/2-48-8*2-96*2-tr.dy*(t-tr.t),80*2,48*2,14) end if tr.dy>0 then rect(240/2-80-tr.dx*(t-tr.t),136/2-48+8*2+96*2-tr.dy*(t-tr.t),80*2,48*2,14) end drawmap(0,0,tr.dx,tr.dy,t-tr.t) drawmap(0,-1,tr.dx,tr.dy,t-tr.t,0,-ydist) drawmap(0,1,tr.dx,tr.dy,t-tr.t,0,ydist) drawmap(-1,0,tr.dx,tr.dy,t-tr.t,-xdist,0) drawmap(1,0,tr.dx,tr.dy,t-tr.t,xdist,0) if tr.dx<0 then drawmap(-2,0,tr.dx,tr.dy,t-tr.t); drawmap(-1,-1,tr.dx,tr.dy,t-tr.t,0,-(240/4-(16*2)/2-4)+dist); drawmap(-1,1,tr.dx,tr.dy,t-tr.t,0,(240/4-(16*2)/2-4)-dist) end if tr.dx>0 then drawmap(2,0,tr.dx,tr.dy,t-tr.t); drawmap(1,-1,tr.dx,tr.dy,t-tr.t,0,-(240/4-(16*2)/2-4)+dist); drawmap(1,1,tr.dx,tr.dy,t-tr.t,0,(240/4-(16*2)/2-4)-dist) end if tr.dy<0 then drawmap(0,-2,tr.dx,tr.dy,t-tr.t); drawmap(-1,-1,tr.dx,tr.dy,t-tr.t,-(136/4-16/2)+dist); drawmap(1,-1,tr.dx,tr.dy,t-tr.t,(136/4-16/2)-dist) end if tr.dy>0 then drawmap(0,2,tr.dx,tr.dy,t-tr.t); drawmap(-1,1,tr.dx,tr.dy,t-tr.t,-(136/4-16/2)+dist); drawmap(1,1,tr.dx,tr.dy,t-tr.t,(136/4-16/2)-dist) end rect(0-tr.dx*(t-tr.t),136/2-48-8-tr.dy*(t-tr.t),240,8,0) rect(240/2-80-8-tr.dx*(t-tr.t),0-tr.dy*(t-tr.t),8,136,0) rect(0-tr.dx*(t-tr.t),136/2+48-tr.dy*(t-tr.t),240,8,0) rect(240/2+80-tr.dx*(t-tr.t),0-tr.dy*(t-tr.t),8,136,0) rect(0-tr.dx*(t-tr.t)+tr.dx*(160+8)*0.5,136/2-48-8-tr.dy*(t-tr.t)+tr.dy*(96+8)*0.5,240,8,0) rect(240/2-80-8-tr.dx*(t-tr.t)+tr.dx*(160+8)*0.5,0-tr.dy*(t-tr.t)+tr.dy*(96+8)*0.5,8,136,0) rect(0-tr.dx*(t-tr.t)+tr.dx*(160+8)*0.5,136/2+48-tr.dy*(t-tr.t)+tr.dy*(96+8)*0.5,240,8,0) rect(240/2+80-tr.dx*(t-tr.t)+tr.dx*(160+8)*0.5,0-tr.dy*(t-tr.t)+tr.dy*(96+8)*0.5,8,136,0) --map(sx,sy-12,20,12,240/2-80,136/2-48-8-96,1) --spr(48,x+240/2-80,y+136/2-48,1) clip(240/2-80-tr.dx*(t-tr.t),136/2-48-tr.dy*(t-tr.t),160,96) spr(sp,x+240/2-80-tr.dx*(t-tr.t)-1+nudgex,y+136/2-48-tr.dy*(t-tr.t)-2+nudgey,1,1,flip,rot) clip(240/2-80-tr.dx*(t-tr.t),96+8+136/2-48-tr.dy*(t-tr.t),160,96) spr(sp,x+240/2-80-tr.dx*(t-tr.t)-1+nudgex,(y-96)+96+8+136/2-48-tr.dy*(t-tr.t)-2+nudgey,1,1,flip,rot) clip(240/2-80-tr.dx*(t-tr.t),-96-8+136/2-48-tr.dy*(t-tr.t),160,96) spr(sp,x+240/2-80-tr.dx*(t-tr.t)-1+nudgex,(y+96)-96-8+136/2-48-tr.dy*(t-tr.t)-2+nudgey,1,1,flip,rot) clip(240/2-80-160-8-tr.dx*(t-tr.t),136/2-48-tr.dy*(t-tr.t),160,96) spr(sp,(x-160-16)+160+8+240/2-80-tr.dx*(t-tr.t)-1+nudgex,y+136/2-48-tr.dy*(t-tr.t)-2+nudgey,1,1,flip,rot) clip(240/2-80+160+8-tr.dx*(t-tr.t),136/2-48-tr.dy*(t-tr.t),160,96) spr(sp,(x+160+16)-160-8+240/2-80-tr.dx*(t-tr.t)-1+nudgex,y+136/2-48-tr.dy*(t-tr.t)-2+nudgey,1,1,flip,rot) clip() dist=dist+1 local nx,ny=sx+tr.dx*0.25*20,sy+tr.dy*0.25*12 local musa=peek(0x13FFC) if (detect_area(nx,ny)==4 and musa~=6) or (detect_area(nx,ny)==5 and musa~=7) or (nx==60 and ny==36 and musa~=4) or (nx==60 and ny==36-12 and musa~=3) or (nx==120 and ny==72 and musa~=5) or (nx==120 and ny==72-12 and musa~=4) or (nx==100 and ny==12 and musa~=4) or (nx==100 and ny==0 and musa~=5) or (nx==140 and ny==0 and musa~=6) or (nx==120 and ny==0 and musa~=5) then local vol if tr.dy~=0 then vol=(1-(t-tr.t)/(136/4-16/2))*15 end if tr.dx~=0 then vol=(1-(t-tr.t)/(240/4-(16*2)/2-4))*15 end vol=math.floor(vol) for ch=0,3 do if ch~=2 then setvol(ch,vol) end end end if (tr.dy~=0 and t-tr.t>=136/4-16/2) or (tr.dx~=0 and t-tr.t>=240/4-(16*2)/2-4) then TIC=update local musa=peek(0x13FFC) if nx==60 and ny==36 and musa~=4 then music(4) end if nx==60 and ny==36-12 and musa~=3 then music(3) end if nx==120 and ny==72 and musa~=5 then music(5) end if nx==120 and ny==72-12 and musa~=4 then music(4) end if nx==100 and ny==12 and musa~=4 then music(4) end if nx==100 and ny==0 and musa~=5 then music(5) end if nx==140 and ny==0 and musa~=6 then music(6) end if nx==120 and ny==0 and musa~=5 then music(5) end if (detect_area(nx,ny)==4 and musa~=6) then music(6) end if (detect_area(nx,ny)==5 and musa~=7) then music(7) end x=x-tr.dx*160*0.25 y=y-tr.dy*96*0.25 sx=sx+tr.dx*0.25*20 if sx>=240 then sx=0 end if sx<0 then sx=240-20 end sy=sy+tr.dy*0.25*12 if sy>=132 then sy=0 end if sy<0 then sy=132-12 end dist=nil --goo={} end t=t+1 end function detect_area(nx,ny) for nnx=0,20-1 do for nny=0,12-1 do local m= mget(nx+nnx,ny+nny) if m==32 then return 1 end if m==36 or m==37 then return 2 end if m==38 then return 3 end if m==106 then return 4 end if m==107 or m==139 then return 5 end end end end ADDR = 0x3FC0 palette = 0 function addLight(scnline) --for j=0, 2 do --poke(ADDR+3+j, palette+5+math.sin(scnline+t*0.1)*5) --end if TIC~=titlescr and TIC~=gamesel then poke(ADDR+3*11, palette+5+math.sin(scnline+t*0.1)*5) poke(ADDR+3*11+1, palette+5+math.sin(scnline+t*0.1)*5) poke(ADDR+3*11+2, palette+40+5+math.sin(scnline+t*0.1)*5) else poke(ADDR+3*11, palette+60+math.sin(scnline+t*0.1)*5) poke(ADDR+3*11+1, palette+15+math.sin(scnline+t*0.1)*5) poke(ADDR+3*11+2, palette+15+math.sin(scnline+t*0.1)*5) end palette = palette + 5 end function addLight2(scnline) if TIC~=titlescr and TIC~=gamesel and TIC~=mapscr then poke(ADDR+3*11, palette2+30) poke(ADDR+3*11+1, palette2+30) poke(ADDR+3*11+2, palette2+5) palette2 = palette2+12 end end function SCN(scnline) if (scnline) % 8 == 0 and TIC~=gameover and TIC~=update and TIC~=cooltrans then addLight(scnline) end if TIC_pend and scnline==135 then TIC=TIC_pend; TIC_pend=nil end if TIC_tpend then t=0; dist=nil; if gamecyc[gamecyc.i]=='Standard' then music(3) else music(6)--[[music(3+math.random(0,4))]] end; TIC_tpend=nil end if scnline%8==0 then palette2=50 end addLight2(scnline) end mapstate=nil function mapscr() cx=cx or sx; cy=cy or sy if not banner_msg or (banner_t2 and banner_t2>0) then if btnp(0) then cy=cy-12 end if btnp(1) then cy=cy+12 end if btnp(2) then cx=cx-20 end if btnp(3) then cx=cx+20 end if cysy+12 then cy=sy+12 end if cxsx+20 then cx=sx+20 end end if btnp(5) and mapstate~='copy' and (not banner_msg or #banner_msg==2) then TIC_pend=update; cx=nil; cy=nil; mapdata=nil; mapstate=nil; header_msg=nil; header_t=nil end detect_gamepad() cls(11) poke(ADDR+3*11+0,0x73) poke(ADDR+3*11+1,0xEF) poke(ADDR+3*11+2,0xF7) palette=0 old_left=left old_right=right mox,moy,left,_,right=mouse() if not leftclick then leftclick=left and not old_left else leftclick=false end if not rightclick then rightclick=right and not old_right else rightclick=false end if rightclick then mapstate=nil mapdata=nil end --if leftclick then -- trace('wee',2) --end local tw=3*20 local th=3*12 for tx=0,3-1 do for ty=0,3-1 do --rect(240/2-90+tx*60,136/2-60+ty*40,60,40,14) local c=12 if mapstate=='1click' and sx-20+tx*20==mapdata.x and sy-12+ty*12==mapdata.y then c=4+t*0.4%4 end if (sx-20+tx*20==cx and sy-12+ty*12==cy) then--or AABB(mox,moy,1,1,240/2-tw-tw/2+tx*tw-2+tx*2,136/2-th-th/2+ty*th-2+ty*2,tw+2,th+2) then if c==12 then c=t*0.4%16 end if btnp(4) and (not banner_msg or (banner_t2 and banner_t2>0)) then if not mapstate then if not gemroom(xmod(sx-20+tx*20),ymod(sy-12+ty*12)) then if not emptyroom(xmod(sx-20+tx*20),ymod(sy-12+ty*12)) then local adj=adjacent(sx-20+tx*20,sy-12+ty*12) if #adj==1 then if not AABB(adj[1].x*8,adj[1].y*8,20*8,12*8,sx*8+x,sy*8+y,6,6) and not AABB((sx+20)*8,(sy)*8,8,12*8,sx*8+x,sy*8+y,6,6) and not AABB((sx-1)*8,(sy)*8,8,12*8,sx*8+x,sy*8+y,6,6) and not AABB((sx)*8,(sy-1)*8,20*8,8,sx*8+x,sy*8+y,6,6) and not AABB((sx)*8,(sy+12)*8,20*8,8,sx*8+x,sy*8+y,6,6) then local function enemy_in_path() for i,e in ipairs(enemies) do if e.x//8>=adj[1].x and e.x//8=adj[1].y and e.y//81 then mapstate='1click' mapdata={x=sx-20+tx*20,y=sy-12+ty*12,adjacent=adj} complain('where to?') elseif #adj==0 then complain('room is surrounded') end else complain('room is empty') end else complain('gems in room') end elseif mapstate=='1click' then local findadj=function() for i,v in ipairs(mapdata.adjacent) do if v.x==sx-20+tx*20 and v.y==sy-12+ty*12 then return true end end end if findadj() then if not AABB((sx-20+tx*20)*8,(sy-12+ty*12)*8,20*8,12*8,sx*8+x,sy*8+y,6,6) and not AABB((sx+20)*8,(sy)*8,8,12*8,sx*8+x,sy*8+y,6,6) and not AABB((sx-1)*8,(sy)*8,8,12*8,sx*8+x,sy*8+y,6,6) and not AABB((sx)*8,(sy-1)*8,20*8,8,sx*8+x,sy*8+y,6,6) and not AABB((sx)*8,(sy+12)*8,20*8,8,sx*8+x,sy*8+y,6,6) then local function enemy_in_path() for i,e in ipairs(enemies) do if e.x//8>=sx-20+tx*20 and e.x//8=sy-12+ty*12 and e.y//8=32 then spr(m+16, 240/2-tw-tw/2+tx*tw-2+tx*2+1+mx*3, 136/2-th-th/2+ty*th-2+ty*2+1+my*3, 1 ) end if sx-20+tx*20+mx==sx+x//8 and sy-12+ty*12+my==sy+y//8 and (t*0.06)%2>=1 then spr(58, 240/2-tw-tw/2+tx*tw-2+tx*2+1+mx*3, 136/2-th-th/2+ty*th-2+ty*2+1+my*3, 1 ) end end end --if sx-20+tx*20==sx and sy-12+ty*12==sy then spr(257,240/2-tw-tw/2+tx*tw-2+tx*2+tw/2-4,136/2-th-th/2+ty*th-2+ty*2+th/2-4,1) end --[[ old and ugly method textri(240/2-tw-tw/2+tx*tw-2+tx*2+1, 136/2-th-th/2+ty*th-2+ty*2+1, 240/2-tw-tw/2+tx*tw+tw-2+tx*2+1,136/2-th-th/2+ty*th-2+ty*2+1, 240/2-tw-tw/2+tx*tw-2+tx*2+1, 136/2-th-th/2+ty*th+th-2+ty*2+1, (sx-20+tx*20)*8, (sy-12+ty*12)*8, (sx-20+tx*20+20)*8,(sy-12+ty*12)*8, (sx-20+tx*20)*8, (sy-12+ty*12+12)*8, true,1) textri(240/2-tw-tw/2+tx*tw+tw-2+tx*2+1,136/2-th-th/2+ty*th-2+ty*2+1, 240/2-tw-tw/2+tx*tw+tw-2+tx*2+1,136/2-th-th/2+ty*th+th-2+ty*2+1, 240/2-tw-tw/2+tx*tw-2+tx*2+1, 136/2-th-th/2+ty*th+th-2+ty*2+1, (sx-20+tx*20+20)*8,(sy-12+ty*12)*8, (sx-20+tx*20+20)*8,(sy-12+ty*12+12)*8, (sx-20+tx*20)*8, (sy-12+ty*12+12)*8, true,1) ]] end end clip(240/2-tw-tw/2,136/2-th-th/2,tw*3,th*3) for i,e in ipairs(enemies) do local flash=0 if (t*0.06)%2>=1 then flash=1 end local sp if e.type=='bat' then sp=56+flash*16 end if e.type=='saw' then sp=108+16+flash*16 end local bdrx,bdry bdrx,bdry=(e.x//8-sx-20)//20*2,(e.y//8-sy-12)//12*2 spr(sp, 240/2-tw-tw/2+120-2+4-1+2+bdrx+(e.x//8-sx-20)*3, 136/2-th-th/2+80-10+8-4-1+1+1+bdry+(e.y//8-sy-12)*3, 1 ) if sy-12<0 then bdrx,bdry=(e.x//8-sx-20)//20*2,(e.y//8-132-sy-12)//12*2 spr(sp, 240/2-tw-tw/2+120-2+4-1+2+bdrx+(e.x//8-sx-20)*3, 136/2-th-th/2+80-10+8-4-1+1+1+bdry+(e.y//8-132-sy-12)*3, 1 ) end if sy+12>=132 then bdrx,bdry=(e.x//8-sx-20)//20*2,(e.y//8+132-sy-12)//12*2 spr(sp, 240/2-tw-tw/2+120-2+4-1+2+bdrx+(e.x//8-sx-20)*3, 136/2-th-th/2+80-10+8-4-1+1+1+bdry+(e.y//8+132-sy-12)*3, 1 ) end if sx-20<0 then bdrx,bdry=(e.x//8-240-sx-20)//20*2,(e.y//8-sy-12)//12*2 spr(sp, 240/2-tw-tw/2+120-2+4-1+2+bdrx+(e.x//8-240-sx-20)*3, 136/2-th-th/2+80-10+8-4-1+1+1+bdry+(e.y//8-sy-12)*3, 1 ) end if sx+20>=240 then bdrx,bdry=(e.x//8+240-sx-20)//20*2,(e.y//8-sy-12)//12*2 spr(sp, 240/2-tw-tw/2+120-2+4-1+2+bdrx+(e.x//8+240-sx-20)*3, 136/2-th-th/2+80-10+8-4-1+1+1+bdry+(e.y//8-sy-12)*3, 1 ) end end clip() local nx,ny if mapdata and (mapdata.dx or mapdata.dy) then nx,ny=mapdata.x+mapdata.dx,mapdata.y+mapdata.dy end if mapstate=='copy' then sfx(5,'E-3',2,2) if sx==mapdata.x and sy==mapdata.y and ((nx==60 and ny==36 and peek(0x13FFC)~=4) or (nx==60 and ny==36-12 and peek(0x13FFC)~=3) or (nx==120 and ny==72 and peek(0x13FFC)~=5) or (nx==120 and ny==72-12 and peek(0x13FFC)~=4)) or (nx==100 and ny==12 and peek(0x13FFC)~=4) or (nx==100 and ny==0 and peek(0x13FFC)~=5) or (nx==140 and ny==0 and peek(0x13FFC)~=6) or (nx==120 and ny==0 and peek(0x13FFC)~=5) then local vol if mapdata.dy~=0 then vol=(1-(mapdata.prog)/math.abs(mapdata.dy))*15 end if mapdata.dx~=0 then vol=(1-(mapdata.prog)/math.abs(mapdata.dx))*15 end vol=math.floor(vol) for ch=0,3 do if ch~=2 then setvol(ch,vol) end end end end if mapstate=='copy' and t%3==0 then if mapdata.dx~=0 then if mapdata.dx>0 then for mx=20-1,0,-1 do for my=0,12-1 do mset(xmod(mapdata.x+mapdata.prog+mx+1),ymod(mapdata.y+my),mget(xmod(mapdata.x+mapdata.prog+mx),ymod(mapdata.y+my))) mset(xmod(mapdata.x+mapdata.prog+mx),ymod(mapdata.y+my),0) end end if sx+x//8>=mapdata.x+mapdata.prog and sx+x//8=mapdata.y and sy+y//8=mapdata.x+mapdata.prog and e.x//8=mapdata.y and e.y//8=mapdata.x+mapdata.prog and e.stx//8=mapdata.y and e.sty//8=mapdata.x-mapdata.prog and sx+x//8=mapdata.y and sy+y//8=mapdata.x-mapdata.prog and e.x//8=mapdata.y and e.y//8=mapdata.x-mapdata.prog and e.stx//8=mapdata.y and e.sty//80 then for mx=0,20-1 do for my=12-1,0,-1 do mset(xmod(mapdata.x+mx),ymod(mapdata.y+mapdata.prog+my+1),mget(xmod(mapdata.x+mx),ymod(mapdata.y+mapdata.prog+my))) mset(xmod(mapdata.x+mx),ymod(mapdata.y+mapdata.prog+my),0) end end if sx+x//8>=mapdata.x and sx+x//8=mapdata.y+mapdata.prog and sy+y//8=mapdata.x and e.x//8=mapdata.y+mapdata.prog and e.y//8=mapdata.x and e.stx//8=mapdata.y+mapdata.prog and e.sty//8=mapdata.x and sx+x//8=mapdata.y-mapdata.prog and sy+y//8=mapdata.x and e.x//8=mapdata.y-mapdata.prog and e.y//8=mapdata.x and e.stx//8=mapdata.y-mapdata.prog and e.sty//8=240 then cx=xmod(mapdata.tgtx) end sy=ymod(mapdata.tgty) if mapdata.tgty<0 then cy=ymod(mapdata.tgty) end if mapdata.tgty>=132 then cy=ymod(mapdata.tgty) end y=y-mapdata.dy*8 x=x-mapdata.dx*8 end if mapdata.x==save_sx and mapdata.y==save_sy then save_sx=mapdata.tgtx save_sy=mapdata.tgty end for i,g in ipairs(goo) do if g.x>=mapdata.x*8 and g.x=mapdata.y*8 and g.y=mapdata.x and g[1]=mapdata.y and g[2]=mapdata.x and tele_tx=mapdata.y and tele_ty0 then collect=collect-1; poke(0x3FF8,7-collect//5) else collect=nil; poke(0x3FF8,0) end else poke(0x3FF8,0) end t=t+1 end function ymod(pos) if pos<0 then return pos+132 end if pos>=132 then return pos-132 end return pos end function ymod2(pos) if pos<0 then return pos+132*8 end if pos>=132*8 then return pos-132*8 end return pos end function xmod(pos) if pos<0 then return pos+240 end if pos>=240 then return pos-240 end return pos end function xmod2(pos) if pos<0 then return pos+240*8 end if pos>=240*8 then return pos-240*8 end return pos end function adjacent(rx,ry) local out={} for i,v in ipairs({{-20,0},{20,0},{0,-12},{0,12}}) do if rx+v[1]>=sx-20 and rx+v[1]<=sx+20 and ry+v[2]>=sy-12 and ry+v[2]<=sy+12 and emptyroom(xmod(rx+v[1]),ymod(ry+v[2])) then table.insert(out,{x=rx+v[1],y=ry+v[2]}) end end return out end function drawmap(dx,dy,trdx,trdy,trt,xdist,ydist) xdist=xdist or 0 ydist=ydist or 0 local sxdx=sx+dx*20 if sxdx<0 then sxdx=240-20 end if sxdx>=240 then sxdx=0 end local sydy=sy+dy*12 if sydy<0 then sydy=132-12 end if sydy>=132 then sydy=0 end clip(240/2-80+dx*(160+8)-trdx*trt+xdist,136/2-48+dy*(96+8)-trdy*trt+ydist,20*8,12*8) cls(14) -- drop shadows for tiles for mx=0,20-1 do for my=0,12-1 do local m=mget(sxdx+mx,sydy+my) if fget(m,2) and m~=103 then rect(240/2-80+dx*(160+8)+mx*8+1-trdx*trt+xdist,136/2-48+dy*(96+8)+my*8+1-trdy*trt+ydist,8,8,15) end end end --for mx=-20,40-1 do for my=-12,24-1 do map(sxdx,sydy,20,12,240/2-80+dx*(160+8)-trdx*trt+xdist,136/2-48+dy*(96+8)-trdy*trt+ydist,1) for i,e in ipairs(enemies) do if e.type=='bat' then local anim if at%24<=11+5+7 then anim=1 end if at%24<=11+5 then anim=0 end if at%24<=11 then anim=2 end local flip=0 if e.dx>0 then flip=1 end spr(288+anim,240/2-80+e.x-(sx)*8+dx*8-1-trdx*trt+xdist,136/2-48+e.y-(sy)*8+dy*8-1-trdy*trt+ydist,1,1,flip) if sy-12<0 then spr(288+anim,240/2-80+e.x-(sx)*8+dx*8-1-trdx*trt+xdist,136/2-48+e.y-(sy)*8-132*8+dy*8-1-trdy*trt+ydist,1,1,flip) end if sy+12>=132 then spr(288+anim,240/2-80+e.x-(sx)*8+dx*8-1-trdx*trt+xdist,136/2-48+e.y-(sy)*8+132*8+dy*8-1-trdy*trt+ydist,1,1,flip) end if sx-20<0 then spr(288+anim,240/2-80+e.x-(sx)*8-240*8+dx*8-1-trdx*trt+xdist,136/2-48+e.y-(sy)*8+dy*8-1-trdy*trt+ydist,1,1,flip) end if sx+20>=240 then spr(288+anim,240/2-80+e.x-(sx)*8+240*8+dx*8-1-trdx*trt+xdist,136/2-48+e.y-(sy)*8+dy*8-1-trdy*trt+ydist,1,1,flip) end end if e.type=='saw' then local anim=((at%25)//5) local flip=0 --if e.dx<0 or e.dy<0 then flip=1 end spr(368+16+anim,240/2-80+e.x-(sx)*8+dx*8-1-trdx*trt+xdist,136/2-48+e.y-(sy)*8+dy*8-1-trdy*trt+ydist,1,1,flip) if sy-12<0 then spr(368+16+anim,240/2-80+e.x-(sx)*8+dx*8-1-trdx*trt+xdist,136/2-48+e.y-(sy)*8-132*8+dy*8-1-trdy*trt+ydist,1,1,flip) end if sy+12>=132 then spr(368+16+anim,240/2-80+e.x-(sx)*8+dx*8-1-trdx*trt+xdist,136/2-48+e.y-(sy)*8+132*8+dy*8-1-trdy*trt+ydist,1,1,flip) end if sx-20<0 then spr(368+16+anim,240/2-80+e.x-(sx)*8-240*8+dx*8-1-trdx*trt+xdist,136/2-48+e.y-(sy)*8+dy*8-1-trdy*trt+ydist,1,1,flip) end if sx+20>=240 then spr(368+16+anim,240/2-80+e.x-(sx)*8+240*8+dx*8-1-trdx*trt+xdist,136/2-48+e.y-(sy)*8+dy*8-1-trdy*trt+ydist,1,1,flip) end end end draw_goo(dx,dy,trdx,trdy,trt,xdist,ydist) clip() end function processmap(dx,dy) local sxdx=sx+dx*20 if sxdx<0 then sxdx=240-20 end if sxdx>=240 then sxdx=0 end local sydy=sy+dy*12 if sydy<0 then sydy=132-12 end if sydy>=132 then sydy=0 end for mx=0,20-1 do for my=0,12-1 do local m=mget(sxdx+mx,sydy+my) if (m==104 or m==105) and (mget(sxdx+mx,sydy+my+1)>=76 and mget(sxdx+mx,sydy+my+1)<=101 and fget(mget(sxdx+mx,sydy+my+1),4)) then mset(sxdx+mx,sydy+my,104+(t*0.4)%2) end if m==107 or m==107+2*16 or m==107+4*16 then local m2=107 local m2a=math.floor((t*0.02)%2)*2*16 mset(sxdx+mx,sydy+my,m2+m2a) end if arrow('up',m) or arrow('right',m) or arrow('down',m) or arrow('left',m) then if arrow('up',m) then mset(sxdx+mx,sydy+my,133+(t*0.4)%4) if orient.dy==-1 then mset(sxdx+mx,sydy+my,156) end end if arrow('right',m) then mset(sxdx+mx,sydy+my,149+16+(t*0.4)%4) if orient.dx==1 then mset(sxdx+mx,sydy+my,172+16) end end if arrow('down',m) then local m2=137 local m2a=(t*0.4)%4 if m2a>=2 then m2a=m2a-2+16+16 end mset(sxdx+mx,sydy+my,m2+m2a) if orient.dy==1 then mset(sxdx+mx,sydy+my,157) end end if arrow('left',m) then local m2=142 local m2a=(t*0.4)%4 if m2a>=2 then m2a=m2a-2+16+16 end mset(sxdx+mx,sydy+my,m2+m2a) if orient.dx==-1 then mset(sxdx+mx,sydy+my,173+16) end end end end end end function arrow(dir,m) if dir=='up' then return ((m>=133 and m<=136) or m==156) end if dir=='right' then return ((m>=149+16 and m<=152+16) or m==172+16) end if dir=='down' then return (((m>=137 and m<=138) or (m>=137+16+16 and m<=138+16+16)) or m==157) end if dir=='left' then return (((m>=142 and m<=143) or (m>=142+16+16 and m<=143+16+16)) or m==173+16) end end function emptyroom(ssx,ssy) for mx=0,20-1 do for my=0,12-1 do if mget(ssx+mx,ssy+my)>0 then return false end end end return true end function gemroom(ssx,ssy) for mx=0,20-1 do for my=0,12-1 do if mget(ssx+mx,ssy+my)==34 then return true end end end return false end checked_on={} checked_off={} function toggle(mx,my) if mget(mx,my)==70 then mset(mx,my,71) if mx>=sx and mx=sy and my=44 and mget(mx,ymod(my-1))<=69 and fget(mget(mx,ymod(my-1)),6) then table.insert(checked_on,{mx,ymod(my-1)}) end if mget(mx,ymod(my+1))>=44 and mget(mx,ymod(my+1))<=69 and fget(mget(mx,ymod(my+1)),4) then table.insert(checked_on,{mx,ymod(my+1)}) end if mget(xmod(mx-1),my)>=44 and mget(xmod(mx-1),my)<=69 and fget(mget(xmod(mx-1),my),7) then table.insert(checked_on,{xmod(mx-1),my}) end if mget(xmod(mx+1),my)>=44 and mget(xmod(mx+1),my)<=69 and fget(mget(xmod(mx+1),my),5) then table.insert(checked_on,{xmod(mx+1),my}) end elseif mget(mx,my)==71 then mset(mx,my,70) if mx>=sx and mx=sy and my=76 and mget(mx,ymod(my-1))<=101 and fget(mget(mx,ymod(my-1)),6) then table.insert(checked_off,{mx,ymod(my-1)}) end if mget(mx,ymod(my+1))>=76 and mget(mx,ymod(my+1))<=101 and fget(mget(mx,ymod(my+1)),4) then table.insert(checked_off,{mx,ymod(my+1)}) end if mget(xmod(mx-1),my)>=76 and mget(xmod(mx-1),my)<=101 and fget(mget(xmod(mx-1),my),7) then table.insert(checked_off,{xmod(mx-1),my}) end if mget(xmod(mx+1),my)>=76 and mget(xmod(mx+1),my)<=101 and fget(mget(xmod(mx+1),my),5) then table.insert(checked_off,{xmod(mx+1),my}) end end end function maintain_toggle() local len=#checked_on local new=false local rem={} for i=1,len do local v=checked_on[i] if not v[3] then local m=mget(v[1],v[2]) mset(v[1],v[2],m+32) local mx,my=v[1],v[2] if fget(m,4) and fget(mget(mx,ymod(my-1)),6) and mget(mx,ymod(my-1))>=44 and mget(mx,ymod(my-1))<=69 and not findv2(checked_on,{mx,ymod(my-1),true}) then table.insert(checked_on,{mx,ymod(my-1),prev=v}) end if fget(m,6) and fget(mget(mx,ymod(my+1)),4) and mget(mx,ymod(my+1))>=44 and mget(mx,ymod(my+1))<=69 and not findv2(checked_on,{mx,ymod(my+1),true}) then table.insert(checked_on,{mx,ymod(my+1),prev=v}) end if fget(m,5) and fget(mget(xmod(mx-1),my),7) and mget(xmod(mx-1),my)>=44 and mget(xmod(mx-1),my)<=69 and not findv2(checked_on,{xmod(mx-1),my,true}) then table.insert(checked_on,{xmod(mx-1),my,prev=v}) end if fget(m,7) and fget(mget(xmod(mx+1),my),5) and mget(xmod(mx+1),my)>=44 and mget(xmod(mx+1),my)<=69 and not findv2(checked_on,{xmod(mx+1),my,true}) then table.insert(checked_on,{xmod(mx+1),my,prev=v}) end if fget(m,4) and (mget(mx,ymod(my-1))==39 or mget(mx,ymod(my-1))==41) then mset(mx,ymod(my-1),mget(mx,ymod(my-1))+(73-39)) end if fget(m,6) and (mget(mx,ymod(my+1))==39 or mget(mx,ymod(my+1))==41) then mset(mx,ymod(my+1),mget(mx,ymod(my+1))+(73-39)) end if fget(m,5) and (mget(xmod(mx-1),my)==39 or mget(xmod(mx-1),my)==41) then mset(xmod(mx-1),my,mget(xmod(mx-1),my)+(73-39)) end if fget(m,7) and (mget(xmod(mx+1),my)==39 or mget(xmod(mx+1),my)==41) then mset(xmod(mx+1),my,mget(xmod(mx+1),my)+(73-39)) end if fget(m,4) and mget(mx,ymod(my-1))==102 then mset(mx,ymod(my-1),103); if AABB(x,y,6,6,(mx-sx)*8,(my-1-sy)*8,8,8) then die() end end if fget(m,6) and mget(mx,ymod(my+1))==102 then mset(mx,ymod(my+1),103); if AABB(x,y,6,6,(mx-sx)*8,(my+1-sy)*8,8,8) then die() end end if fget(m,5) and mget(xmod(mx-1),my)==102 then mset(xmod(mx-1),my,103); if AABB(x,y,6,6,(mx-1-sx)*8,(my-sy)*8,8,8) then die() end end if fget(m,7) and mget(xmod(mx+1),my)==102 then mset(xmod(mx+1),my,103); if AABB(x,y,6,6,(mx+1-sx)*8,(my-sy)*8,8,8) then die() end end v[3]=true if v.prev and v.prev.prev and find(checked_on,v.prev.prev) then table.insert(rem,find(checked_on,v.prev.prev)) end new=true end end for i=#rem,1,-1 do table.remove(checked_on,rem[i]) end for i=#checked_on,1,-1 do local v=checked_on[i] if v[3] and (v.prev and not find(checked_on,v.prev.prev)) or not v.prev then table.remove(checked_on,i) end end if not new then checked_on={} end len=#checked_off new=false rem={} for i=1,len do local v=checked_off[i] if not v[3] then local m=mget(v[1],v[2]) mset(v[1],v[2],m-32) local mx,my=v[1],v[2] if fget(m,4) and fget(mget(mx,ymod(my-1)),6) and mget(mx,ymod(my-1))>=76 and mget(mx,ymod(my-1))<=101 and not findv2(checked_off,{mx,ymod(my-1),true}) then table.insert(checked_off,{mx,ymod(my-1),prev=v}) end if fget(m,6) and fget(mget(mx,ymod(my+1)),4) and mget(mx,ymod(my+1))>=76 and mget(mx,ymod(my+1))<=101 and not findv2(checked_off,{mx,ymod(my+1),true}) then table.insert(checked_off,{mx,ymod(my+1),prev=v}) end if fget(m,5) and fget(mget(xmod(mx-1),my),7) and mget(xmod(mx-1),my)>=76 and mget(xmod(mx-1),my)<=101 and not findv2(checked_off,{xmod(mx-1),my,true}) then table.insert(checked_off,{xmod(mx-1),my,prev=v}) end if fget(m,7) and fget(mget(xmod(mx+1),my),5) and mget(xmod(mx+1),my)>=76 and mget(xmod(mx+1),my)<=101 and not findv2(checked_off,{xmod(mx+1),my,true}) then table.insert(checked_off,{xmod(mx+1),my,prev=v}) end if fget(m,4) and (mget(mx,ymod(my-1))==73 or mget(mx,ymod(my-1))==75) then mset(mx,ymod(my-1),mget(mx,ymod(my-1))-(73-39)) end if fget(m,6) and (mget(mx,ymod(my+1))==73 or mget(mx,ymod(my+1))==75) then mset(mx,ymod(my+1),mget(mx,ymod(my+1))-(73-39)) end if fget(m,5) and (mget(xmod(mx-1),my)==73 or mget(xmod(mx-1),my)==75) then mset(xmod(mx-1),my,mget(xmod(mx-1),my)-(73-39)) end if fget(m,7) and (mget(xmod(mx+1),my)==73 or mget(xmod(mx+1),my)==75) then mset(xmod(mx+1),my,mget(xmod(mx+1),my)-(73-39)) end if fget(m,4) and mget(mx,ymod(my-1))==103 then mset(mx,ymod(my-1),102) end if fget(m,6) and mget(mx,ymod(my+1))==103 then mset(mx,ymod(my+1),102) end if fget(m,5) and mget(xmod(mx-1),my)==103 then mset(xmod(mx-1),my,102) end if fget(m,7) and mget(xmod(mx+1),my)==103 then mset(xmod(mx+1),my,102) end v[3]=true if v.prev and v.prev.prev and find(checked_off,v.prev.prev) then table.insert(rem,find(checked_off,v.prev.prev)) end new=true end end for i=#rem,1,-1 do table.remove(checked_off,rem[i]) end for i=#checked_off,1,-1 do local v=checked_off[i] if v[3] and (v.prev and not find(checked_off,v.prev.prev)) or not v.prev then table.remove(checked_off,i) end end if not new then checked_off={} end end function reconnect() local out_on={} local out_off={} for i,v in ipairs(checked_on) do if v[1]>=mapdata.x and v[1]<=mapdata.x+19 and v[2]>=mapdata.y and v[2]<=mapdata.y+11 then v[1]=xmod(v[1]+mapdata.dx) v[2]=ymod(v[2]+mapdata.dy) end end for i,v in ipairs(checked_off) do if v[1]>=mapdata.x and v[1]<=mapdata.x+19 and v[2]>=mapdata.y and v[2]<=mapdata.y+11 then v[1]=xmod(v[1]+mapdata.dx) v[2]=ymod(v[2]+mapdata.dy) end end for mx=mapdata.tgtx-1,mapdata.tgtx+20-1+1 do for my=mapdata.tgty+0-1,mapdata.tgty+12-1+1 do local mxx=mx-mapdata.tgtx local myy=my-mapdata.tgty if (not (((mxx==11 or mxx==12) and myy==-1) or ((mxx==19 or mxx==-1) and (myy<=0 or myy>=11)) or mxx==9 or (myy==11-4) or (myy==12 and mxx<=0))) and (mxx<=0 or mxx>=19 or myy<=0 or myy>=11) then local m=mget(xmod(mx),ymod(my)) if ((myy==0 or myy==12) and fget(m,4)) or ((myy==-1 or myy==11) and fget(m,6)) or ((mxx==0 or mxx==20) and fget(m,5)) or ((mxx==-1 or mxx==19) and fget(m,7)) then if m>=44 and m<=69 and not findv2(checked_off,{mx,my}) then out_off={{mx,my}} local connected=false for i,v in ipairs(out_off) do local m=mget(v[1],v[2]) local nx,ny=v[1],v[2] if #out_off>30 then connected=false; break end if fget(m,4) and mget(nx,ymod(ny-1))==71 then connected=true; break end if fget(m,6) and mget(nx,ymod(ny+1))==71 then connected=true; break end if fget(m,5) and mget(xmod(nx-1),ny)==71 then connected=true; break end if fget(m,7) and mget(xmod(nx+1),ny)==71 then connected=true; break end if fget(m,4) and fget(mget(nx,ymod(ny-1)),6) and not findv2(checked_on,{nx,ymod(ny-1)}) and not findv2(out_off,{nx,ymod(ny-1)}) then table.insert(out_off,{nx,ymod(ny-1)}) end if fget(m,6) and fget(mget(nx,ymod(ny+1)),4) and not findv2(checked_on,{nx,ymod(ny+1)}) and not findv2(out_off,{nx,ymod(ny+1)}) then table.insert(out_off,{nx,ymod(ny+1)}) end if fget(m,5) and fget(mget(xmod(nx-1),ny),7) and not findv2(checked_on,{xmod(nx-1),ny}) and not findv2(out_off,{xmod(nx-1),ny}) then table.insert(out_off,{xmod(nx-1),ny}) end if fget(m,7) and fget(mget(xmod(nx+1),ny),5) and not findv2(checked_on,{xmod(nx+1),ny}) and not findv2(out_off,{xmod(nx+1),ny}) then table.insert(out_off,{xmod(nx+1),ny}) end end if connected then table.insert(checked_on,out_off[1]) end elseif m>=76 and m<=101 and not findv2(checked_off,{mx,my}) then out_on={{mx,my}} local connected=false for i,v in ipairs(out_on) do local m=mget(v[1],v[2]) local nx,ny=v[1],v[2] if fget(m,4) and mget(nx,ymod(ny-1))==71 then connected=true; break end if fget(m,6) and mget(nx,ymod(ny+1))==71 then connected=true; break end if fget(m,5) and mget(xmod(nx-1),ny)==71 then connected=true; break end if fget(m,7) and mget(xmod(nx+1),ny)==71 then connected=true; break end if fget(m,4) and fget(mget(nx,ymod(ny-1)),6) and not findv2(checked_off,{nx,ymod(ny-1)}) and not findv2(out_on,{nx,ymod(ny-1)}) then table.insert(out_on,{nx,ymod(ny-1)}) end if fget(m,6) and fget(mget(nx,ymod(ny+1)),4) and not findv2(checked_off,{nx,ymod(ny+1)}) and not findv2(out_on,{nx,ymod(ny+1)}) then table.insert(out_on,{nx,ymod(ny+1)}) end if fget(m,5) and fget(mget(xmod(nx-1),ny),7) and not findv2(checked_off,{xmod(nx-1),ny}) and not findv2(out_on,{xmod(nx-1),ny}) then table.insert(out_on,{xmod(nx-1),ny}) end if fget(m,7) and fget(mget(xmod(nx+1),ny),5) and not findv2(checked_off,{xmod(nx+1),ny}) and not findv2(out_on,{xmod(nx+1),ny}) then table.insert(out_on,{xmod(nx+1),ny}) end end if not connected then table.insert(checked_off,out_on[1]) end end end end end end for mx=mapdata.x-1,mapdata.x+20-1+1 do for my=mapdata.y+0-1,mapdata.y+12-1+1 do local mxx=mx-mapdata.x local myy=my-mapdata.y if (not (((mxx==11 or mxx==12) and myy==-1) or ((mxx==19 or mxx==-1) and (myy<=0 or myy>=11)) or mxx==9 or (myy==11-4) or (myy==12 and mxx<=0))) and (mxx<=0 or mxx>=19 or myy<=0 or myy>=11) then local m=mget(mx,my) if ((myy==0 or myy==12) and fget(m,4)) or ((myy==-1 or myy==11) and fget(m,6)) or ((mxx==0 or mxx==20) and fget(m,5)) or ((mxx==-1 or mxx==19) and fget(m,7)) then if m>=44 and m<=69 and not findv2(checked_off,{mx,my}) then out_off={{mx,my}} local connected=false for i,v in ipairs(out_off) do local m=mget(v[1],v[2]) local nx,ny=v[1],v[2] if #out_off>30 then connected=false; break end if fget(m,4) and mget(nx,ymod(ny-1))==71 then connected=true; break end if fget(m,6) and mget(nx,ymod(ny+1))==71 then connected=true; break end if fget(m,5) and mget(xmod(nx-1),ny)==71 then connected=true; break end if fget(m,7) and mget(xmod(nx+1),ny)==71 then connected=true; break end if fget(m,4) and fget(mget(nx,ymod(ny-1)),6) and not findv2(checked_on,{nx,ymod(ny-1)}) and not findv2(out_off,{nx,ymod(ny-1)}) then table.insert(out_off,{nx,ymod(ny-1)}) end if fget(m,6) and fget(mget(nx,ymod(ny+1)),4) and not findv2(checked_on,{nx,ymod(ny+1)}) and not findv2(out_off,{nx,ymod(ny+1)}) then table.insert(out_off,{nx,ymod(ny+1)}) end if fget(m,5) and fget(mget(xmod(nx-1),ny),7) and not findv2(checked_on,{xmod(nx-1),ny}) and not findv2(out_off,{xmod(nx-1),ny}) then table.insert(out_off,{xmod(nx-1),ny}) end if fget(m,7) and fget(mget(xmod(nx+1),ny),5) and not findv2(checked_on,{xmod(nx+1),ny}) and not findv2(out_off,{xmod(nx+1),ny}) then table.insert(out_off,{xmod(nx+1),ny}) end end if connected then table.insert(checked_on,out_off[1]) end elseif m>=76 and m<=101 and not findv2(checked_off,{mx,my}) then out_on={{mx,my}} local connected=false for i,v in ipairs(out_on) do local m=mget(v[1],v[2]) local nx,ny=v[1],v[2] if fget(m,4) and mget(nx,ymod(ny-1))==71 then connected=true; break end if fget(m,6) and mget(nx,ymod(ny+1))==71 then connected=true; break end if fget(m,5) and mget(xmod(nx-1),ny)==71 then connected=true; break end if fget(m,7) and mget(xmod(nx+1),ny)==71 then connected=true; break end if fget(m,4) and fget(mget(nx,ymod(ny-1)),6) and not findv2(checked_off,{nx,ymod(ny-1)}) and not findv2(out_on,{nx,ymod(ny-1)}) then table.insert(out_on,{nx,ymod(ny-1)}) end if fget(m,6) and fget(mget(nx,ymod(ny+1)),4) and not findv2(checked_off,{nx,ymod(ny+1)}) and not findv2(out_on,{nx,ymod(ny+1)}) then table.insert(out_on,{nx,ymod(ny+1)}) end if fget(m,5) and fget(mget(xmod(nx-1),ny),7) and not findv2(checked_off,{xmod(nx-1),ny}) and not findv2(out_on,{xmod(nx-1),ny}) then table.insert(out_on,{xmod(nx-1),ny}) end if fget(m,7) and fget(mget(xmod(nx+1),ny),5) and not findv2(checked_off,{xmod(nx+1),ny}) and not findv2(out_on,{xmod(nx+1),ny}) then table.insert(out_on,{xmod(nx+1),ny}) end end if not connected then table.insert(checked_off,out_on[1]) end end end end end end end function alert(msg,manual,ending) banner_msg=msg banner_t=180 banner_t2=0 banner_manual=manual banner_end=ending end function draw_banner() if banner_msg then local bw=240 for i,bmsg in ipairs(banner_msg) do if banner_t2>0 then bw=math.max(0,240-(banner_t2-(i-1)*8)*16) end rect(math.max(0,240-(180-(i-1)*8-banner_t)*16),136/2-4-(#banner_msg-1)*6+(i-1)*12,bw,8,13) clip(math.max(0,240-(180-(i-1)*8-banner_t)*16),0,bw,136) for c=1,#bmsg do local char=string.sub(bmsg,c,c) if char=='$' then spr(5,-2+240/2-#bmsg/2*6+(c-1)*6,-1+136/2-3-(#banner_msg-1)*6+(i-1)*12,0) elseif char=='%' then spr(6,-2+240/2-#bmsg/2*6+(c-1)*6,-1+136/2-3-(#banner_msg-1)*6+(i-1)*12,0) elseif char=='&' then spr(22,-2+240/2-#bmsg/2*6+(c-1)*6,-1+136/2-3-(#banner_msg-1)*6+(i-1)*12,0) else print(char,240/2-#bmsg/2*6+(c-1)*6+math.cos(t*0.12+c*7)*1+1,136/2-3-(#banner_msg-1)*6+(i-1)*12+math.sin(t*0.12+c*9)*1+1,15,false,1,true) print(char,240/2-#bmsg/2*6+(c-1)*6+math.cos(t*0.12+c*7)*1,136/2-3-(#banner_msg-1)*6+(i-1)*12+math.sin(t*0.12+c*9)*1,4,false,1,true) end end clip() end if banner_t2>0 then banner_t2=banner_t2+1 if bw==0 then banner_msg=nil; banner_t=nil; banner_t2=nil if banner_end then banner_end(); banner_end=nil end end end if banner_t and banner_t>0 then banner_t=banner_t-1 if banner_t==0 and not banner_manual and not (banner_t2>0) then banner_t2=1 end end if banner_manual and banner_manual() then banner_t2=1 banner_manual=nil end end end goo={} function splatter(force) --trace(force) for i=0,6+(force-1)*8-1 do local a=math.random(180-20,360+20)*math.pi/180 table.insert(goo,{x=sx*8+x+3,y=sy*8+y+3,dx=math.cos(a)*(1+force-1.6)/2,dy=math.sin(a)*(1+force-1.6),r=math.random(1,2),t=t,sx=sx,sy=sy}) end end function gootrail() table.insert(goo,{x=sx*8+x+3,y=sy*8+y+6,dx=0,dy=0,r=1,sx=sx,sy=sy}) end function update_goo() for i=#goo,1,-1 do local s=goo[i] if TIC==update or TIC==gameover then s.x=s.x+s.dx; s.y=s.y+s.dy end local m=mget(s.x//8,s.y//8) if fget(m,2) then s.dx=0; s.dy=0 end if TIC==update or TIC==gameover then s.dy=s.dy+0.2; s.dy=s.dy*0.95 end if s.y>=sy*8+2*12*8+s.r then table.remove(goo,i) end --if s.y>=132*8 then s.y=s.y-132*8 end end end function draw_goo(dx,dy,trdx,trdy,trt,xdist,ydist) xdist=xdist or 0 ydist=ydist or 0 --local cx=240/2-80+dx*(160+8)-trdx*trt+xdist --local cy=136/2-48+dy*(96+8)-trdy*trt+ydist --clip(cx,cy,160,96) for i=#goo,1,-1 do local s=goo[i] --if s.x-(240/2-80)>=cx and s.x-(240/2-80)=cy and s.y-(136/2-48) x2 and y1 < y2 + h2 and y1 + h1 > y2) end -- from 1THRUSTR.EXE function sprpix(sprno,px,py) local byte= peek(0x4000 + 32*sprno + py*4 + px/2) if px%2==1 then byte=(byte&0xf0)>>4 else byte=byte&0x0f end return byte end -- palette swapping by BORB function pal(c0,c1) if(c0==nil and c1==nil) then for i=0,15 do poke4(0x3FF0*2+i,i) end else poke4(0x3FF0*2+c0,c1) end end -- from Sunray Valley function setvol(ch,vol)--ch 0-3,vol 0-15 local val=peek(0xFF9C+18*ch+1) poke(0xFF9C+18*ch+1,val&(0x0f|vol<<4)) end