ÿð"ÿ?3/ÿ33ÿÿ333Ãÿÿð"?3ðÿ33ÿÿ333Ãÿÿð"?3ð33ÿ"3ó33ÿð"ÿ?3/ÿ33ÿÿ333Ãÿÿð"/"ÿð33/ÿ33/ò33/ò33òòÿ33ó3333Ã<ó3Ã?óÿð"/"ð33ðÿ33/ò33/ò33òòÿ33ó3333Ã<ó3Ã?óÿð"ÿ"ð33?33?Ì3?ü3ÿ""ÿ3333ó3Ìó3Ïóÿð"/"ÿð33/ÿ33/ò33/ò33òòÿ33ó3333Ã<ó3Ã?ó/ò33/ÿD"ÿODðÿ333DDDDDôÿÿÿò33ðÿD"ODðÿ333DDDDDôÿÿðÃ?ð33ðBDODðÿÿó<33D$Dôÿÿ/ò33/ÿD"ÿODðÿ33óDDDDDôÿÿ/ò33/òDD/ÿDDÿODðÿð333ó"DDô"BDDDDÿÿÿ"ÿ/ò33/òDDðÿDDODðÿ/ð333ó"DDô"BDDDDÿÿÿò?33/DD/DDðDDÿÿðò33óDDòDDòDDÿÿ//ò33/òDD/ÿDDÿODðÿð333"DDô"BDDDDÿÿÿ"ÿðoðfÿofoÿffoöffööföÿffÿff,fffÿðoðfðofoöffoöffööföÿffÿff,fffÿðoðfofðÆbðfföffö&lffðoðfÿofoÿffoöffööföÿffÿff,fffÿðÿODðDDÿO4DOODDÿDÿDÄÿCDôDDòðÿODðDDðO4DOODDÿDÿDÄÿCDôDDòðÿðODO4DODDðDCDðDDDÿ4D4ðÿDôDCôDDôðDüDDDDDD$ÿððÿðODO4DODDðDCDðDDDÿ4D4ÿDôDCôðDDôDüDDDDDD$ÿoöfÿoÿVÅÿ_UðÿoðÿÿÿÅÅÅUUÿÿÿöoöfÿðÿVÅ_UðÿðÿÿÿÅÅÅUUÿÿÿfÿðÿÿð\\_UðÿoÿÿÅÅUõÿöoöföoÿVUÿ_Uðÿoð ÏÀÀÿÿÿöÿOC4ðÌÌÏÌðÿDDôÌÌÌüÿðOC4ðÌÌÏÌðÿDDôÌÌÌüÿðDDDðÌÌÌÏÌÌÏÌÌðÏÌðÿDDDÌÌÌÌÌüðÌÌüÌüÿððDDDðÌÌÌÏÌÌÏÌÌðÏÌðÿðDDDÌÌÌÌÌüÌÌüðÌüÿ@QUUÌQÅÌQÌ,QÌ,UÌUÌ\ÂÌÂÌQUUÌQÅÌQÌ,QÌ,DUÌUÌ\ÂÌÂÌ@QUQÅÌQÌ,QÌ,UQÌ\ÂÌÂÌÑÑÌÍ"!""",,ÑÝ"!""",,ÑÑÌÍ"!"""//»»»Á̱±Á»±Á±Ì»»»Ì±Á»Ì02 #0 0"# 2 02 #2#  "02QÅÌQUÌQUafffaÌ\ÌUUfffQÅÌQUÌQUafffaÌ\ÌUUfffQÅÌQQÁÁafaÌ\ÁÁf""!""//""""!""!""//""""!""!"Â,,""""ÁÁ±Á±Ì±Á»±ÁÌ»»»Ì»Á̱»»» " """"" """"" #""""ÿÿÿð333ÿÿÿ333ÿÿÿð#""ð333ðDDDÿÿÿÿÿÿ""2333DDDÿÿÿÿðDôðÄOÿðDDôOôOCðDCÿDCóÿðDôðÄOÿðDDôOôOCðDCðDCóP`VVV`eVP`V`eV`eVVàîàÞÝÞÝÝàÝÝîàÝîîîîîîþîîþÿÿÿÿííîîÝîîÝíîîîîîþÿÿÿÿðÿ?3óÿ?Ãÿ??DôÿODôðÿðÿ?3óÿ?Ãÿ??DôÿODôðÿÿÿð33ðüÏð33ðDDÿÿððÿ?3óÿ?Ãÿ??DÿODÿðÿÿÿðDLO4CôOC4ôOC4ôO4CôðD4ÿÿðOüOó?ô?ôOóOóðð#""ðDDDð33Oð""Oð33ÿðDDDð"""ÿÿÿ""2DDDô33ô""ÿ33DDD"""ÿÿÿðÄDÄðDDDð33Oð""Oð33ÿðDDDð"""ÿÿÿDÄDDDDô33ô""ÿ33DDD"""ÿÿÿ?O4ôÿD4ôðDCOCðDOOôðÿO4ô?O4ôÿDCOCðDOOôð`eVVV`e`VfV`eV`eVVVfð@@@@@@ðÿÿð¼«ϼªùÿÿÿÿ𻚯ùðÿÿ𻬿»¬ùÿÿÿÿð»œÏùðÿÿðÌÜÏÌÜýÏÌÝýÏÜÝþÏÝÝþðÝîÿÿðOó?óððÿ_\_eofðÿðÿÿÏÌ"òßÝòðÿÿÿÏÏüÏÌÏÌüÏÿÿ° ¼ °° » °¼°°°°» 033C30C300À ÜÍÀÍÍ ÀÍÍÍÀÍÍ ÜÜÐ àààîîàDDà4CàDDàîîD@D@DD@D@ÿð4ÿðOóððOóðÝÝÝÝ Ð­ªªÚ­3ªÚ­ª:ÚMDDÔÝÝÝÝðofÿoÆòooföÿ_\üðÿÿÿÿDDOOÄÿÿDDòÏÌðÿðOüODðôOCðDOðÝ ÐÐÐÐÝÝÝ Ý Ý Ý Ý ÝÝÝ @DDDD@DDD@D@@ ÿÿÿÿÿÿÿÿÿÿÿÿ2Tv˜ºÜþïÍ«‰gE#"3DUfwˆ™ª»ÌÝîÿ˜ÊíþÿîÍšh52eÈ½Ë |ÁW@Nu»eˆ¢@ÿÿ¨ìÿÿÿÿï¬XS˜ÊíþÿîÍšh52e˜ÊíþÿîÍšh52e˜ÊíþÿîÍšh52e˜ÊíþÿîÍšh52e˜ÊíþÿîÍšh52e˜ÊíþÿîÍšh52e˜ÊíþÿîÍšh52e˜ÊíþÿîÍšh52e €E GHJLMOOOOOOOOOOOOOOOOOOOOOOOOV_W[__________________________                  ttttttttttt t t t t t t v w y z | }         €134679 : <=?????????????????????‡$$%%&&''(())**++,,- - . . / / / / / / / / …RW PQQRRSTTUU V W W X X Y Z Z [ [ \ ] ] ^ ^ _ _ _ _ _ „gkoooooooooooooooooooooooooooo                   %EEF G I K M O O O O O O O O O O O O O O O O O O O O O O O ##$$% % &&& ' ) * + , . / / / / / / / / / / / / / / /           ¥##$%&'''''''''''''''''''''''''Z\^___________________________BDGJ MOOOOOOOOOOOOOOOOOOOOOOOOO„66 707 88à8Ð8à8à8à8à8à8à8à8à8à8à8à8à8à8à8à8à8à8à8à8à8à8à8à€UWY[]^________________________QSUWZ]______________________ƒ- �°°°°° ° �°° ° °°° �° °°°° ��° ° °°°�°°° �°° ° ° °°° ��° °qq Qq Q QQ Q Q Qq Q Q Qq Q“òµò“òµò“òµò“òµò“òµò“òµò“òµò“òµò ”´”´´´ ” ” ” ””´ Q Q q Q Q Q Q q Q Q Q Q q Q Q Q Q q Q Q Q Q q Q Q Q Q q Q QQQqQQQQqQQ“òµò“òµò“òµò“òµò“òµò“òµò“òµò“òµò˜Á@Â@Á@Â@Á@Â@Á@Â@Á@Â@Á@Â@Á@Â@Á@Â@…q…q…q…q…q…q…q…q…q…q…q…q…q…q…q…qÿ 0,]']±>Sï}WÿÍu§ðp8·d%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†344D4D4DDDDDDDDDDDDDDDDDDDVFDDDDDDDDDDDDDDDDDDDDDDDDDD"A4D4DîîîîîîîNDDDDDDVFDDdeDDCCDCDCLÃfFCCCCfFCCDCDCLCDCCCCÿÿÿÿÿÿÿÿLCCCCCCCCCCC3CCCCCCCCCCCCfFDCL3CCDCDCÃb then return b end return v end function rnd(a,b) return a+math.random()*(b-a) end function lerp(a,b,t) return a+(b-a)*t end function d2(x1,y1,x2,y2) local dx,dy=x2-x1,y2-y1 return dx*dx+dy*dy end function in_rect(px,py,x,y,w,h) return px>=x and py>=y and px0 then G.shake=G.shake-1 local m=math.min(3,G.shake//3+1) poke(0x3FF9,math.random(-m,m)%256) poke(0x3FFA,math.random(-m,m)%256) else poke(0x3FF9,0) poke(0x3FFA,0) end end -- particles. k: 0 pixel, 1 floating text, 2 ring, 3 coin flying to HUD, 4 sparkle function part(x,y,vx,vy,life,col,k,a) local P=G.parts if #P>200 then return end P[#P+1]={x=x,y=y,vx=vx,vy=vy,life=life,max=life,col=col,k=k or 0,a=a} end function burst(x,y,n,col,spd) spd=spd or 1.2 for i=1,n do local a=math.random()*6.2832 local s=rnd(0.3,spd) part(x,y,math.cos(a)*s,math.sin(a)*s,math.random(14,30),col,0) end end function ftext(x,y,s,col) part(x,y,0,-0.35,50,col,1,s) end function ring(x,y,col) part(x,y,0,0,18,col or 12,2) end function sparkle(x,y,col) part(x,y,0,-0.1,16,col or 12,4) end function parts_update() local P=G.parts for i=#P,1,-1 do local p=P[i] p.life=p.life-1 if p.k==3 then -- vx,vy hold the start point local t=1-p.life/p.max t=t*t p.x=lerp(p.vx,6,t) p.y=lerp(p.vy,4,t) else p.x=p.x+p.vx p.y=p.y+p.vy if p.k==0 then p.vx=p.vx*0.94 p.vy=p.vy*0.94+0.02 end end if p.life<=0 then table.remove(P,i) end end end function parts_draw() for _,p in ipairs(G.parts) do if p.k==0 then pix(p.x,p.y,p.col) elseif p.k==1 then if p.life>8 or p.life%2==0 then local w=tw(p.a,1,true) print(p.a,p.x-w//2+1,p.y+1,0,false,1,true) print(p.a,p.x-w//2,p.y,p.col,false,1,true) end elseif p.k==2 then circb(p.x,p.y,(p.max-p.life)*0.8+2,p.col) elseif p.k==3 then coin_sprite(p.col,p.x,p.y,0) elseif p.k==4 then local r=p.life>8 and 2 or 1 line(p.x-r,p.y,p.x+r,p.y,p.col) line(p.x,p.y-r,p.x,p.y+r,p.col) end end end -- [03_audio.lua] -- Audio manager: one sfx channel with simple priorities, music switching. AU={cur=-1,pri=0,busy=0} SFX_PRI={[SF.alert]=3,[SF.boom]=3,[SF.clear]=4,[SF.lose]=4,[SF.buy]=2,[SF.grow]=2, [SF.die]=2,[SF.chomp]=2,[SF.gem]=2,[SF.birth]=2,[SF.zap]=1,[SF.hit]=1} function snd(id,dur,note) local p=SFX_PRI[id] or 0 if AU.busy>0 and p0 then AU.busy=AU.busy-1 end end function mus(t) if AU.cur==t then return end AU.cur=t if t<0 then music() else music(t,0,0,true) end end -- [04_input.lua] -- Input: keyboard cursor with acceleration, plus optional mouse. -- Buttons (default TIC keyboard map): arrows, Z=4, X=5, A=6, S=7 IN={cx=120,cy=60,spd=1,mx=-1,my=-1,mouse=false,ml=false,mr=false,mlp=false,mrp=false,lock=false} function in_update() local mx,my,l,m,r=mouse() if IN.mx>=0 and (mx~=IN.mx or my~=IN.my) then IN.mouse=true end IN.mx,IN.my=mx,my IN.mlp=l and not IN.ml IN.mrp=r and not IN.mr IN.ml,IN.mr=l,r if l or r then IN.mouse=true end local dx,dy=0,0 if not IN.lock then if btn(0) then dy=-1 end if btn(1) then dy=1 end if btn(2) then dx=-1 end if btn(3) then dx=1 end end if dx~=0 or dy~=0 then IN.mouse=false IN.spd=math.min(IN.spd+0.08,3) IN.cx=clamp(IN.cx+dx*IN.spd,1,238) IN.cy=clamp(IN.cy+dy*IN.spd,TOP+1,HUDY-2) else IN.spd=1 end if IN.mouse then IN.cx,IN.cy=mx,my end end -- "confirm" in menus: Z or left click function in_ok() return btnp(4) or IN.mlp end -- [05_tank.lua] -- Aquarium manager: themed background (pre-rendered once into map RAM, -- copied back each frame), animated plants, bubbles and surface. BG_ADDR=0x8000 -- map RAM is unused by the game; holds the static background THEMES={ { -- 1 sunny shallows w={11,10,9},s={4,3},rays=true, weed={14,26,122,222,231}, deco={{"rock",58,FLOOR-4},{"coral",176,FLOOR-13},{"star",96,FLOOR+2}, {"shell",146,FLOOR+3},{"rock",196,FLOOR-3},{"shell",30,FLOOR+4}}, vents={70,165}}, { -- 2 kelp garden w={10,9,8},s={6,7},rays=true,kelp=true,tall=true, weed={8,20,46,92,140,168,200,226},weedpal={[6]=7,[5]=6}, deco={{"rock",112,FLOOR-4},{"rock",60,FLOOR-3},{"star",180,FLOOR+3}}, vents={34,150,214}}, { -- 3 coral canyon w={10,9,8},s={4,3},rays=true, weed={100,236}, deco={{"coral",4,FLOOR-13},{"coral",36,FLOOR-12,{[2]=1,[3]=2}},{"rock",70,FLOOR-3}, {"coral",150,FLOOR-13,{[2]=9,[3]=11}},{"coral",186,FLOOR-12},{"coral",216,FLOOR-13,{[2]=1,[3]=2}}, {"shell",128,FLOOR+3},{"star",58,FLOOR+3}}, vents={90,130}}, { -- 4 sunken ship w={9,8,15},s={13,14},ship=true, weed={10,24,104,230},weedpal={[6]=7,[5]=6}, deco={{"rock",30,FLOOR-3},{"shell",80,FLOOR+3},{"star",100,FLOOR+2}}, chest={58,FLOOR-12},vents={48,214}}, { -- 5 the abyss w={8,15,0},s={15,0},glow=true,tall=true, weed={12,40,90,150,200,228},weedpal={[6]=1,[5]=11}, deco={{"rock",64,FLOOR-3,{[13]=15,[14]=8}},{"rock",170,FLOOR-4,{[13]=15,[14]=8}}}, vents={30,120,210}}, } BAYER={0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5} function dith(x,y) return BAYER[(y%4)*4+(x%4)+1]/16 end function tank_build(th) local T=THEMES[th] G.theme=T math.randomseed(th*31) cls(0) local c1,c2,c3=T.w[1],T.w[2],T.w[3] -- water gradient (ordered dither) for y=TOP,FLOOR+6 do local t=(y-TOP)/(FLOOR-TOP) local a,b,f if t<0.5 then a,b,f=c1,c2,t*2 else a,b,f=c2,c3,math.min(1,(t-0.5)*2) end for x=0,239 do local d=dith(x,y) local c=f>d and b or a if T.rays and y520 sprt(open and "chestO" or "chestC",T.chest[1],T.chest[2]) if open and t%8==0 then G.bubbles[#G.bubbles+1]={x=T.chest[1]+8+rnd(-3,3),y=T.chest[2]+4,s=math.random(0,2),ph=math.random()*6} end end -- bubbles for _,b in ipairs(G.bubbles) do if b.s==0 then pix(b.x,b.y,11) elseif b.s==1 then sprt("bubM",b.x,b.y) else sprt("bubL",b.x-2,b.y-2) end end -- water surface local sc=T.w[1]==8 and 9 or 12 for x=0,239 do local w=math.sin((x+t*0.5)/9)+math.sin((x-t*0.3)/5)*0.5 pix(x,TOP+(w>0.6 and 1 or 0),w>0.9 and sc or 11) end end function bubbles_update() local B=G.bubbles local T=G.theme if #B<26 and math.random()<0.07 then local vx=T.vents[math.random(#T.vents)] B[#B+1]={x=vx+rnd(-3,3),y=FLOOR+1,s=math.random(0,2),ph=math.random()*6} end for i=#B,1,-1 do local b=B[i] b.y=b.y-(0.25+b.s*0.12) b.x=b.x+math.sin(b.y/8+b.ph)*0.25 if b.y medium -> large), snapper (eats fry, drops gems), -- puffer (guard, hurts aliens), seahorse (breeds fry) HUNGRY_PAL={[3]=13,[4]=12,[2]=14,[6]=13,[5]=12} STARVE_PAL={[3]=2,[4]=3,[6]=2,[5]=3,[12]=4} DEAD_PAL={[3]=13,[4]=13,[2]=14,[6]=14,[5]=13,[12]=13} function fdef(f) local d=FD[f.kind] if f.kind=="minnow" then return d[f.stage] end return d end function fish_new(kind,x,y,stage) local f={kind=kind,x=x,y=y,vx=0,vy=0,dir=math.random()<0.5 and -1 or 1,tx=x,ty=y,wt=0, hunger=100,stage=stage or 1,xp=0,anim=math.random(0,99),turn=0,eat=0,alive=true,dead=0, starve=0,spark=0,hit=0,gem=0,puff=0,breed=BREED_T} f.ci=(fdef(f).ci or 600)*rnd(0.5,1.0) G.fish[#G.fish+1]=f return f end -- filters (defined once, no per-frame closures) function F_food(p) return not p.dead end function F_prey(f) return f.alive and f.kind=="minnow" and f.stage==1 end function F_foeprey(f) return f.alive and f.kind~="puffer" end function nearest(list,x,y,filter,maxd) local best,bd=nil,maxd and maxd*maxd or 1e9 for _,o in ipairs(list) do if filter==nil or filter(o) then local d=d2(x,y,o.x,o.y) if d=fdef(f).need then f.stage=f.stage+1 f.xp=0 f.spark=40 snd(SF.grow) burst(f.x,f.y,14,4) ftext(f.x,f.y-12,"GROW!",11) end end end function fish_update(f) if not f.alive then f.dead=f.dead+1 if f.y>TOP+6 then f.y=f.y-0.3 end return f.dead<160 end local d=fdef(f) f.anim=f.anim+1 if f.turn>0 then f.turn=f.turn-1 end if f.eat>0 then f.eat=f.eat-1 end if f.spark>0 then f.spark=f.spark-1 end if f.hit>0 then f.hit=f.hit-1 end if d.hd and not G.demo then f.hunger=f.hunger-d.hd if f.hunger<=0 then f.hunger=0 f.starve=f.starve+1 if f.starve>=STARVE_T then fish_kill(f,"starve") return true end else f.starve=0 end end local sp=d.spd local mode="wander" local foe,fd=nearest(G.foes,f.x,f.y,nil,52) if foe and f.kind~="puffer" then local l=math.sqrt(fd)+0.01 f.tx=f.x+(f.x-foe.x)/l*40 f.ty=f.y+(f.y-foe.y)/l*40 sp=sp*1.8 mode="flee" elseif f.kind=="puffer" then local e,ed=nearest(G.foes,f.x,f.y,nil,100) if e then f.tx,f.ty=e.x,e.y sp=sp*1.7 mode="guard" end if e and ed<34*34 then f.puff=math.min(f.puff+1,20) else f.puff=math.max(f.puff-1,0) end elseif f.kind=="snapper" then if f.hunger<55 and not G.demo then local p=nearest(G.fish,f.x,f.y,F_prey) if p then f.tx,f.ty=p.x,p.y sp=sp*1.3 mode="hunt" if d2(f.x,f.y,p.x,p.y)<64 then fish_kill(p,"eaten") G.lost=G.lost-1 -- feeding the snapper is not a loss f.hunger=100 f.eat=20 f.gem=45 snd(SF.chomp) burst(p.x,p.y,6,3) end end end elseif d.hd and f.hunger1.5 then local k=(mode=="wander") and 0.04 or 0.09 f.vx=f.vx+(dx/l*sp-f.vx)*k f.vy=f.vy+(dy/l*sp*0.8-f.vy)*k else f.vx=f.vx*0.9 f.vy=f.vy*0.9 end f.x=clamp(f.x+f.vx,8,232) f.y=clamp(f.y+f.vy,SWIM_T,ymax) if f.vx>0.1 and f.dir<0 then f.dir=1 f.turn=7 elseif f.vx<-0.1 and f.dir>0 then f.dir=-1 f.turn=7 end if G.demo then return true end -- coins if f.kind=="minnow" and f.hunger>0 then f.ci=f.ci-1 if f.ci<=0 then coin_new(f.x,f.y+3,d.coin) f.ci=d.ci*rnd(0.85,1.15) end end if f.gem>0 then f.gem=f.gem-1 if f.gem==0 then coin_new(f.x,f.y+4,4) sparkle(f.x,f.y,11) end end -- seahorse births if f.kind=="seahorse" and f.hunger>30 then f.breed=f.breed-1 if f.breed<=0 then if fish_alive()6 then n=d.p[(f.anim//5)%2+1] elseif f.turn>0 then n=s[3] elseif f.eat>0 then n=s[4] else n=s[(f.anim//10)%2+1] end local fl=f.dir<0 and 1 or 0 local y=f.y if not f.alive then if f.dead>110 and f.dead%4<2 then return end fl=fl+2 palt(DEAD_PAL) else y=y+math.sin(f.anim/16)*0.8 if d.hd and f.hunger<=0 then if (f.anim//8)%2==0 then palt(STARVE_PAL) end elseif d.hd and f.hunger0 and (f.spark//3)%2==0 then palflash(12) end if f.hit>20 then palflash(4) end end sprc(n,f.x,y,fl) pal() if f.alive and d.hd and f.hunger<=0 and (f.anim//15)%2==0 then oprint("!",f.x-1,y-SPH[n]*4-4,2,0) end end function fish_update_all() local L=G.fish for i=#L,1,-1 do if not fish_update(L[i]) then table.remove(L,i) end end end -- [07_food.lua] -- Food manager: limited pellet stock that refills over time. function food_max() return 3+G.up.fc end function food_regen() return 80-G.up.fc*12 end function food_drop(x,y) if G.foodStock<1 then snd(SF.err) G.foodFlash=24 ftext(x,y-6,"NO FOOD",2) return end G.foodStock=G.foodStock-1 G.food[#G.food+1]={x=x,y=clamp(y,TOP+3,FLOOR-2),t=0,land=0,q=G.up.fq+1,dead=false} snd(SF.drop) ring(x,clamp(y,TOP+3,FLOOR-2),11) end function food_update() local L=G.food for i=#L,1,-1 do local p=L[i] p.t=p.t+1 if not p.dead then if p.land>0 then p.land=p.land+1 if p.land>100 then p.dead=true end else p.y=p.y+0.3 p.x=p.x+math.sin(p.t/12)*0.12 if p.y>=FLOOR-1 then p.y=FLOOR-1 p.land=1 end end end if p.dead then table.remove(L,i) end end if G.foodStock=food_regen() then G.foodT=0 G.foodStock=G.foodStock+1 end else G.foodT=0 end if G.foodFlash>0 then G.foodFlash=G.foodFlash-1 end end function food_draw() for _,p in ipairs(G.food) do if p.land<70 or p.land%4<2 then sprc(FOODQ[p.q].s,p.x,p.y) end end end -- [08_coins.lua] -- Coin manager: coins sink, rest on the sand, then vanish. function coin_mult() return 1+0.25*G.up.cv end function coin_new(x,y,k) local v=COINS[k].val if k<=3 then v=math.floor(v*coin_mult()+0.5) elseif k==5 then v=v+50*G.st end G.coins[#G.coins+1]={x=clamp(x,6,233),y=y,k=k,v=v,t=math.random(0,40),land=0} end function coin_update() local L=G.coins for i=#L,1,-1 do local c=L[i] c.t=c.t+1 if c.land==0 then c.y=c.y+(c.k>=4 and 0.5 or 0.36) if c.y>=FLOOR+1 then c.y=FLOOR+1 c.land=1 end else c.land=c.land+1 end if c.land>COIN_LIFE then table.remove(L,i) burst(c.x,c.y,4,13,0.5) end end end function coin_near(x,y) for _,c in ipairs(G.coins) do if d2(x,y,c.x,c.y)<11*11 then return c end end end function coin_try_collect(x,y) local got=false local L=G.coins for i=#L,1,-1 do local c=L[i] if d2(x,y,c.x,c.y)<11*11 then coin_collect(c) table.remove(L,i) got=true end end return got end function coin_collect(c) G.money=G.money+c.v G.earned=G.earned+c.v G.mbump=10 ftext(c.x,c.y-8,"+"..c.v,c.k>=4 and 11 or 4) part(c.x,c.y,c.x,c.y,22,c.k,3) sparkle(c.x,c.y,12) if c.k>=4 then snd(SF.gem) else snd(SF.coin) end end -- draws coin of kind k centred at x,y; t drives the spin function coin_sprite(k,x,y,t) local C=COINS[k] if C.gem then sprc((t//10)%2==0 and "gem1" or "gem2",x,y) return elseif C.pearl then sprc("pearl",x,y) if (t//6)%4==0 then pix(x-1,y-2,12) end return end local f=(t//6)%4 if C.pal then palt(C.pal) end if f==0 then sprc("coin1",x,y) elseif f==1 then sprc("coin2",x,y) elseif f==2 then sprc("coin3",x,y) else sprc("coin2",x,y,1) end pal() end function coin_draw() local hx,hy=IN.cx,IN.cy for _,c in ipairs(G.coins) do if c.land=#it.costs then return "max" end else if it.max and count_kind(it.fish)>=it.max then return "max" end if fish_alive()>=tank_cap() then return "full" end end if G.money0 then SH.flash=SH.flash-1 end if not SH.open then return end local x,y,w,h=SHX,SHY,SHW,SHH rect(x+2,y+2,w,h,0) rect(x,y,w,h,0) rectb(x,y,w,h,13) rect(x+1,y+1,w-2,9,8) sprt("ic_bag",x+3,y+1) print("SHOP",x+13,y+3,4) print("Z:BUY A:CLOSE",x+50,y+3,13,false,1,true) for i,it in ipairs(SHOP) do local ry=y+11+(i-1)*9 local st=item_state(it) if i==SH.sel then local c=15 if SH.frow==i and SH.flash>0 and (SH.flash//2)%2==0 then c=12 end rect(x+1,ry-1,w-2,9,c) rect(x+1,ry-1,2,9,4) end if st=="locked" then sprt("ic_lock",x+4,ry) print("STAGE "..it.st,x+15,ry+1,14) else sprt(it.icon,x+4,ry) print(it.name,x+15,ry+1,(st=="max" or st=="full") and 13 or 12) if it.kind=="up" then for l=1,#it.costs do rect(x+62+(l-1)*4,ry+2,3,4,l<=G.up[it.id] and 11 or 14) end else local k=count_kind(it.fish) if k>0 then print("x"..k,x+64,ry+2,13,false,1,true) end end local txt,c if st=="max" then txt,c="MAX",13 elseif st=="full" then txt,c="FULL",2 else txt="$"..item_cost(it) c=(st=="poor") and 2 or 4 end print(txt,x+w-3-tw(txt),ry+1,c) end end local it=SHOP[SH.sel] local dy=y+h-17 line(x+1,dy-1,x+w-2,dy-1,14) local d=it.desc if item_state(it)=="locked" then d="UNLOCKS IN STAGE "..it.st end print(d,x+3,dy+1,13,false,1,true) end -- [10_foes.lua] -- Enemy manager (alien director, AI) + combat (zapper). function zap_max() return 6+3*G.up.zp end function zap_dmg() return 1+G.up.zp end function zap_regen() return 40-6*G.up.zp end function foe_spawn(kind,x,y) local d=FOE[kind] local hp=math.floor(d.hp*STAGES[G.st].hpm+0.5) local e={kind=kind,x=x,y=y,hp=hp,max=hp,anim=0,stun=0,kx=0,ky=0,eating=0,flash=0, dir=x<120 and 1 or -1,rt=0,lone=0,ph=math.random()*6} G.foes[#G.foes+1]=e return e end function foe_hurt(e,dmg,sx,sy) e.hp=e.hp-dmg e.flash=6 local dx,dy=e.x-sx,e.y-sy local l=math.sqrt(dx*dx+dy*dy) if l<1 then dx,dy,l=0,-1,1 end e.kx,e.ky=dx/l*2.2,dy/l*2.2 e.stun=10 e.eating=0 snd(SF.hit) if e.hp<=0 then foe_die(e) end end function foe_die(e) snd(SF.boom) shake(12) burst(e.x,e.y,22,FOE[e.kind].col,2) burst(e.x,e.y,12,12,1.5) ring(e.x,e.y,12) coin_new(e.x,e.y,5) ftext(e.x,e.y-14,"ZAPPED!",11) G.kills=G.kills+1 end function foe_update(e) local d=FOE[e.kind] e.anim=e.anim+1 if e.flash>0 then e.flash=e.flash-1 end if e.stun>0 then e.stun=e.stun-1 e.x=e.x+e.kx e.y=e.y+e.ky e.kx=e.kx*0.8 e.ky=e.ky*0.8 elseif e.eating>0 then e.eating=e.eating-1 else e.rt=e.rt-1 if e.tgt==nil or not e.tgt.alive or e.rt<=0 then e.tgt=nearest(G.fish,e.x,e.y,F_foeprey) e.rt=90 end local t=e.tgt if t then e.lone=0 local dx,dy=t.x-e.x,t.y-e.y local l=math.sqrt(dx*dx+dy*dy)+0.01 local vx,vy=dx/l*d.spd,dy/l*d.spd if e.kind=="zipper" then local w=math.sin(e.anim/9+e.ph)*0.7 vx=vx-dy/l*w vy=vy+dx/l*w end e.x=e.x+vx e.y=e.y+vy if math.abs(vx)>0.05 then e.dir=vx>0 and 1 or -1 end if l360 then e.gone=true burst(e.x,e.y,16,11) ftext(e.x,e.y-12,"BYE!",13) end end end -- puffer spikes for _,f in ipairs(G.fish) do if f.alive and f.kind=="puffer" and f.puff>6 and f.hit<=0 and d2(f.x,f.y,e.x,e.y)<(d.r+8)*(d.r+8) then f.hit=30 foe_hurt(e,2,f.x,f.y) sparkle(e.x,e.y,4) if e.hp<=0 then break end end end e.x=clamp(e.x,10,230) e.y=clamp(e.y,TOP+8,FLOOR-6) return e.hp>0 and not e.gone end function foes_update() local L=G.foes for i=#L,1,-1 do if not foe_update(L[i]) then table.remove(L,i) end end end -- decides when aliens arrive; shows a warning portal first function foe_director() local S=STAGES[G.st] if G.warn then G.warn.t=G.warn.t-1 if G.warn.t<=0 then for _,w in ipairs(G.warn.list) do foe_spawn(w.k,w.x,w.y) burst(w.x,w.y,18,11,2) ring(w.x,w.y,1) end G.warn=nil end elseif #G.foes==0 and fish_alive()>0 then G.spawnT=G.spawnT-1 if G.spawnT<=0 then local n=1 if S.double and G.wave%2==1 then n=2 end local list={} for i=1,n do local k=S.foes[math.random(#S.foes)] if G.wave==0 then k=S.foes[1] end local side=(i==1) == (math.random()<0.5) list[i]={k=k,x=side and 24 or 216,y=rnd(32,80)} end G.warn={t=150,list=list} G.wave=G.wave+1 G.spawnT=S.every*60 snd(SF.alert,90) end end if G.warn or #G.foes>0 then mus(MU.tense) else mus(MU.calm) end end -- the zapper: a lightning strike at the cursor function zap(x,y) if G.zapCool>0 then return end if G.energy<1 then snd(SF.err) G.zapFlash=20 G.zapCool=12 return end G.energy=G.energy-1 G.zapCool=7 G.bolt={x=x,y=y,t=7,ox=math.random(-12,12)} snd(SF.zap) local hit=false for _,e in ipairs(G.foes) do if e.hp>0 and d2(x,y,e.x,e.y)<(FOE[e.kind].r+5)^2 then foe_hurt(e,zap_dmg(),x,y) hit=true end end if hit then burst(x,y,8,12,1.5) else burst(x,y,5,11,0.8) end end function zap_update() if G.zapCool>0 then G.zapCool=G.zapCool-1 end if G.zapFlash>0 then G.zapFlash=G.zapFlash-1 end if G.bolt then G.bolt.t=G.bolt.t-1 if G.bolt.t<=0 then G.bolt=nil end end if G.energy=zap_regen() then G.energyT=0 G.energy=G.energy+1 end else G.energyT=0 end end function bolt_draw() local b=G.bolt if not b then return end local x0,y0=b.x+b.ox,TOP+1 local px,py=x0,y0 local n=7 for i=1,n do local t=i/n local nx=lerp(x0,b.x,t)+(i0 or close then n=d.s[3] else n=d.s[(e.anim//10)%2+1] end if e.flash>0 then palflash(12) end sprc(n,e.x,e.y+math.sin(e.anim/12)*1.5,e.dir<0 and 1 or 0) pal() if e.hp=S.goal then G.state="clear" G.stateT=0 SH.open=false mus(-1) snd(SF.clear,90) if G.st<#STAGES and unlocked()100 then G.state="over" G.stateT=0 SH.open=false mus(-1) snd(SF.lose,90) end else G.overT=0 end end -- [12_ui.lua] -- UI: top HUD, bottom HUD, cursor, banners. UPS={{"fq","fd1"},{"fc","ic_cap"},{"cv","coin1"},{"ts","ic_tank"},{"zp","ic_zap"}} function hud_top() rect(0,0,240,TOP,0) line(0,TOP-1,239,TOP-1,15) -- money sprt("coin1",1,1) local mc=4 if G.mbump>0 then G.mbump=G.mbump-1 mc=(G.mbump%4<2) and 12 or 4 end print("$"..G.money,11,2,mc,true) -- stage print("STAGE "..G.st,58,2,13) -- fish count sprt("fry1",100,0) local n,cap=fish_alive(),tank_cap() print(n.."/"..cap,110,2,n>=cap and 3 or 12) -- goal bar local S=STAGES[G.st] local gx,gw=140,98 rect(gx,1,gw,7,15) local fw=math.floor((gw-2)*math.min(1,G.money/S.goal)) rect(gx+1,2,fw,5,(G.t//20)%2==0 and 6 or 5) rectb(gx,1,gw,7,14) local left=S.goal-G.money local s=left>0 and ("$"..left.." TO GOAL") or "GOAL!" local w=tw(s,1,true) print(s,gx+gw//2-w//2+1,3,0,false,1,true) print(s,gx+gw//2-w//2,2,12,false,1,true) end function hud_bottom() local y=HUDY rect(0,y,240,16,0) line(0,y,239,y,15) -- feed keycap(3,y+3,"Z",btn(4)) print("FEED",14,y+2,12,false,1,true) local fm=food_max() for i=1,fm do local x=14+(i-1)*5 local c=14 if i<=G.foodStock then c=4 elseif i==G.foodStock+1 then c=(G.foodT>food_regen()*0.5) and 3 or 15 end if G.foodFlash>0 and G.foodFlash%6<3 then c=2 end rect(x,y+9,4,4,c) end -- zap keycap(54,y+3,"X",btn(5)) print("ZAP",65,y+2,12,false,1,true) local zm=zap_max() rect(65,y+9,40,4,15) local zc=11 if G.zapFlash>0 and G.zapFlash%6<3 then zc=2 end rect(65,y+9,math.floor(40*G.energy/zm),4,zc) for i=1,zm-1 do pix(65+math.floor(40*i/zm),y+10,0) end -- shop keycap(110,y+3,"A",SH.open) print("SHOP",121,y+2,12,false,1,true) if shop_any_affordable() and (G.t//15)%2==0 then sprt("ic_bag",121,y+7) print("!",131,y+8,4) else sprt("ic_bag",121,y+7) end -- upgrade indicators for i,u in ipairs(UPS) do local x=152+(i-1)*17 sprt(u[1]=="fq" and FOODQ[G.up.fq+1].s or u[2],x,y+4) local lv=G.up[u[1]] print(lv,x+9,y+6,lv>0 and 11 or 14,false,1,true) end line(148,y+2,148,y+13,15) end function cursor_draw() local x,y=IN.cx,IN.cy if G.warn or #G.foes>0 then local c=(G.t//6)%2==0 and 2 or 12 circb(x,y,5,c) line(x-8,y,x-4,y,c) line(x+4,y,x+8,y,c) line(x,y-8,x,y-4,c) line(x,y+4,x,y+8,c) pix(x,y,c) else sprt("cur",x,y) end end function banners_draw() local S=STAGES[G.st] if G.banner>0 then G.banner=G.banner-1 if G.banner>20 or G.banner%4<2 then local y=36 rect(0,y-4,240,30,0) line(0,y-5,239,y-5,9) line(0,y+26,239,y+26,9) ocprint("STAGE "..G.st,120,y,4,0,2) ocprint(S.name,120,y+13,12,0) cprint("EARN $"..S.goal.." TO CLEAR THE TANK",120,y+21,13,1,true) end end -- stage 1 control hints if G.st==1 and G.t<900 and not SH.open then local y=FLOOR-8 local s="Z: FEED / GRAB COINS X: ZAP A: SHOP" local w=tw(s,1,true) rect(120-w//2-3,y-2,w+6,9,0) print(s,120-w//2,y,(G.t//30)%2==0 and 12 or 13,false,1,true) end if G.overT>0 then ocprint("NO FISH LEFT...",120,60,2,0) end end -- [13_main.lua] -- Game state manager: title, help, play, clear, over, victory. G={state="title",t=0,st=1,frame=0,shake=0,parts={},fish={},foes={},coins={},food={},bubbles={}, up={fq=0,fc=0,cv=0,ts=0,zp=0},money=0,earned=0,spent=0,kills=0,lost=0} TT={sel=1,stage=1} ---------------------------------------------------------------- title function title_enter() reset_world() G.st=1 G.demo=true G.t=0 tank_build(1) math.randomseed(TEST_SEED or tstamp()) fish_new("minnow",40,50,3) fish_new("minnow",190,70,2) fish_new("minnow",120,92,1) fish_new("snapper",80,96) fish_new("puffer",210,40) fish_new("seahorse",28,86) TT.sel=1 TT.stage=unlocked() AU.cur=-1 mus(MU.calm) G.state="title" G.stateT=0 end function title_update() G.t=G.t+1 G.stateT=G.stateT+1 au_update() fish_update_all() bubbles_update() parts_update() if btnp(0) or btnp(1) then TT.sel=3-TT.sel snd(SF.tick) end if TT.sel==1 then if btnp(2) and TT.stage>1 then TT.stage=TT.stage-1 snd(SF.tick) end if btnp(3) and TT.stage10 and (btnp(4) or IN.mlp) then snd(SF.buy) if TT.sel==1 then stage_start(TT.stage) else G.state="help" G.stateT=0 end end end LOGO="REEF RICHES" function title_draw() tank_draw() for _,f in ipairs(G.fish) do fish_draw(f) end parts_draw() -- logo: wavy, outlined letters local x=120-tw(LOGO,3)//2 for i=1,#LOGO do local ch=LOGO:sub(i,i) local y=14+math.floor(math.sin(G.t/14+i*0.6)*2.5) oprint(ch,x+1,y+2,0,0,3) oprint(ch,x,y,(i<=4) and 11 or 4,0,3) x=x+tw(ch,3) end ocprint("A TINY AQUARIUM TYCOON",120,36,12,0,1,true) ocprint("MADE BY DANDELION STUDIO",120,45,4,0,1,true) -- menu local y=64 panel(60,y-6,120,36,0) local c1=TT.sel==1 and 4 or 13 local c2=TT.sel==2 and 4 or 13 local s="START STAGE "..TT.stage if TT.sel==1 and unlocked()>1 then s="START < STAGE "..TT.stage.." >" end cprint(s,120,y,c1) cprint("HOW TO PLAY",120,y+12,c2) local ay=(TT.sel==1) and y or y+12 if (G.t//15)%2==0 then print(">",66,ay,4) print("<",170,ay,4) end cprint(STAGES[TT.stage].name,120,y+20,9,1,true) -- footer local f if pmem(1)>0 then f="ALL STAGES CLEARED - THE REEF IS RICH!" else f="STAGES UNLOCKED: "..unlocked().."/"..#STAGES end rect(0,HUDY,240,16,0) line(0,HUDY,239,HUDY,15) cprint(f,120,HUDY+3,13,1,true) cprint("ARROWS: MOVE Z: SELECT",120,HUDY+10,14,1,true) end ---------------------------------------------------------------- help HELP={ {c=4,t="CONTROLS"}, {c=12,t="ARROWS / MOUSE MOVE THE CURSOR"}, {c=12,t="Z / LEFT CLICK DROP FOOD, OR GRAB NEARBY COINS"}, {c=12,t="X / RIGHT CLICK ZAP (HOLD TO KEEP ZAPPING)"}, {c=12,t="A OPEN / CLOSE THE SHOP"}, {c=4,t="HOW IT WORKS"}, {c=13,t="HUNGRY FISH TURN PALE. FEED THEM OR THEY STARVE."}, {c=13,t="WELL FED MINNOWS GROW AND DROP BETTER COINS."}, {c=13,t="COINS VANISH IF YOU LEAVE THEM ON THE SAND."}, {c=13,t="PELLETS AND ZAP CHARGE REFILL OVER TIME."}, {c=13,t="ALIENS EAT FISH! ZAP THEM UNTIL THEY POP."}, {c=13,t="REACH THE GOAL MONEY TO CLEAR EACH STAGE."}, } function help_update() G.t=G.t+1 G.stateT=G.stateT+1 fish_update_all() bubbles_update() if G.stateT>10 and (btnp(4) or btnp(6) or btnp(5) or IN.mlp) then snd(SF.tick) G.state="title" G.stateT=0 end end function help_draw() tank_draw() for _,f in ipairs(G.fish) do fish_draw(f) end panel(8,6,224,124,0) local y=12 for _,l in ipairs(HELP) do if l.c==4 then if y>12 then y=y+3 end print(l.t,16,y,4) y=y+9 else print(l.t,16,y,l.c,false,1,true) y=y+8 end end if (G.t//20)%2==0 then cprint("PRESS Z TO GO BACK",120,120,11,1,true) end end ---------------------------------------------------------------- play function play_update() G.t=G.t+1 au_update() -- shop toggle (A key, or click on the SHOP button) local toggle=btnp(6) if IN.mlp and IN.my>=HUDY and IN.mx>=108 and IN.mx<146 then toggle=true IN.mlp=false end if toggle then SH.open=not SH.open snd(SF.tick) end IN.lock=SH.open if SH.open then shop_input() end -- tank actions local act=(btnp(4) and not SH.open) if IN.mlp and not (SH.open and in_rect(IN.mx,IN.my,SHX,SHY,SHW,SHH)) and IN.myTOP and IN.cy45 and in_ok() then snd(SF.tick) if G.st<#STAGES then stage_start(G.st+1) else victory_enter() end end end function clear_draw() world_draw() hud_top() rect(0,HUDY,240,16,0) local S=STAGES[G.st] panel(40,22,160,92,0) ocprint("STAGE "..G.st.." CLEAR!",120,28,4,0,2) for i=0,2 do local on=G.stateT>15+i*12 if on then sprt("ic_star",104+i*12,44) end end cprint(S.name,120,56,12) local y=66 print("MONEY EARNED",52,y,13) print("$"..G.earned,188-tw("$"..G.earned),y,4) print("FISH ALIVE",52,y+8,13) print(fish_alive(),188-tw(""..fish_alive()),y+8,12) print("ALIENS ZAPPED",52,y+16,13) print(G.kills,188-tw(""..G.kills),y+16,12) print("TIME",52,y+24,13) print(mmss(G.t),188-tw(mmss(G.t)),y+24,12) if G.st<#STAGES then local nx=STAGES[G.st+1].name local new=nil for _,it in ipairs(SHOP) do if it.st==G.st+1 then new=it.name end end cprint("NEXT: "..nx..(new and (" (NEW: "..new..")") or ""),120,y+34,11,1,true) else cprint("FINAL STAGE COMPLETE!",120,y+34,11,1,true) end if G.stateT>45 and (G.stateT//20)%2==0 then cprint("PRESS Z TO CONTINUE",120,HUDY+5,12) end end function over_update() G.stateT=G.stateT+1 au_update() parts_update() G.t=G.t+1 bubbles_update() if G.stateT>45 then if btnp(4) or IN.mlp then snd(SF.tick) stage_start(G.st) elseif btnp(6) then snd(SF.tick) title_enter() end end end function over_draw() world_draw() hud_top() panel(34,36,172,60,0) ocprint("GAME OVER",120,42,2,0,2) cprint("THE TANK IS EMPTY AND",120,60,13) cprint("THERE'S NO CASH LEFT.",120,68,13) if G.stateT>45 then cprint("Z: RETRY STAGE A: TITLE",120,82,(G.t//20)%2==0 and 12 or 11) end end function victory_enter() reset_world() G.demo=true G.t=0 tank_build(1) for i=1,4 do fish_new("minnow",rnd(20,220),rnd(30,100),3) end fish_new("snapper",60,90) fish_new("puffer",180,50) fish_new("seahorse",210,90) fish_new("minnow",100,70,2) fish_new("minnow",140,60,1) AU.cur=-1 mus(MU.calm) G.state="victory" G.stateT=0 end function victory_update() G.stateT=G.stateT+1 G.t=G.t+1 au_update() parts_update() bubbles_update() G.demo=true fish_update_all() if G.stateT%12==0 then local x,y=rnd(20,220),rnd(16,70) burst(x,y,20,({4,11,12,5,3})[math.random(5)],2) ring(x,y,12) end if G.stateT>60 and in_ok() then snd(SF.tick) title_enter() end end function victory_draw() tank_draw() for _,f in ipairs(G.fish) do fish_draw(f) end parts_draw() ocprint("YOU WIN!",120,26,4,0,3) ocprint("ALL FIVE TANKS ARE OVERFLOWING WITH TREASURE.",120,52,12,0,1,true) ocprint("THE REEF IS RICH - AND THE ALIENS WENT HOME HUNGRY.",120,60,12,0,1,true) for i=0,4 do sprt("ic_star",90+i*12,72) end ocprint("THANKS FOR PLAYING! - DANDELION STUDIO",120,108,13,0,1,true) if G.stateT>60 and (G.t//20)%2==0 then ocprint("PRESS Z FOR THE TITLE",120,92,11,0) end end STATES={ title={u=title_update,d=title_draw}, help={u=help_update,d=help_draw}, play={u=play_update,d=play_draw}, clear={u=clear_update,d=clear_draw}, over={u=over_update,d=over_draw}, victory={u=victory_update,d=victory_draw}, } function BOOT() title_enter() end function TIC() in_update() local s=STATES[G.state] s.u() s=STATES[G.state] -- update may change state s.d() shake_apply() G.frame=G.frame+1 end -- game menu (ESC): RESTART / TITLE function MENU(i) if i==0 then if G.state=="play" or G.state=="over" or G.state=="clear" then stage_start(G.st) end elseif i==1 then title_enter() end end