'mapping between character num used to draw the map (rom#4) and bg source coords for meta tiles (rom#3) 'all meta tiles are 2x2 ' row count data 21 ' num, x, y data 0, 0, 0 :'empty data 2, 2, 0 :'pipe elbow bottom-right data 3, 4, 0 :'pipe horizontal with border data 4, 6, 0 :'etc, you got this idea data 5, 8, 0 data 6, 10,0 data 7, 12,0 data 8, 14,0 data 9, 16,0 data 10, 18,0 data 11, 20,0 data 12, 22,0 data 13, 24,0 data 14, 26,0 data 15, 28,0 data 63, 30,0 data 79, 32,0 data 80, 34,0 data 81, 36,0 data 82, 38,0 data 83, 40,0 dim global metax(83),metay(ubound(metax)) read count for i=0 to count-1 read num read metax(num),metay(num) next i 'user's function that actually draw cells of the world '(in) l,t = left and top position in world-cell-coords '(in) (w,h) = with and height dimension in world-cell-coords 'it will ask to draw horizontal or vertical lines from the world sub inf_world(l,t,w,h) if w=0 or h=0 then exit sub bg 3 pal 0 'drawing an horizontal line if w>h then world_y=t for i=0 to w-1 world_x=l+i gosub inf_world_draw next i exit sub 'drawing a vertical line else world_x=l for i=0 to h-1 world_y=t+i gosub inf_world_draw next i exit sub end if inf_world_draw: 'read meta tile id bg source rom(4) world_tile=mcell.c(world_x,world_y) 'draw meta tile, one at a time bg source rom(3) bg copy metax(world_tile),metay(world_tile),2,2 to world_x*2,world_y*2 return end sub 'user's function to scroll the background sub inf_scroll(x,y) scroll 3,x,y end sub 'rectangle of the whole world map 'a.k.a.: world boundaries in world-meta-cell-coords '/!\ this is not bg-layer-cell-coord infl=0 inft=0 infr=20-1 infb=40-1 'camera dimension, a.k.a.: view dimension in pixel-coords 'camera view start of the top-left corner of the device, if you want to change it, do it yourself. infw=shown.w infh=shown.h 'world cell size in pixel-coord, a.k.a.: pixel to cell conversion infs=16 'convert bg layer size 64x64 to world-meta-cell-coord infg=64/(infs\8) 'number of cells to draw out of the view to make then already drawn when the camera is panned. 'note if the number is too big it can lead to overwrite wrapped cells the are visible. 'max value=7 with infs=8 infco=0 'compute space occupied by the whole world in pixel-coords infpw=(infr-infl+1)*infs infph=(infb-inft+1)*infs 'camera position in the world in pixel-coords 'initial position point to the center of the world infx=-(infw-infpw)/2 infy=-(infh-infph)/2 gosub inf_prepare 'rectangle of what portion of the world is drawn 'a.k.a.: view drawing cursor in world-cell-coords 'initial rectangel start from the center of the view infcl=(infpl+infpr)\2 infct=(infpt+infpb)\2 infcr=infcl-1 infcb=infct-1 'need recompute position infnl=-1 do if touch and touch.change and not touch.drag and not touch.long then 'save original pan position of the world infxs=infx infys=infy else if touch.drag then 'pan the camera view onto the world infx=infxs-(touch.x-touch.px) infy=infys-(touch.y-touch.py) infnl=-1 end if if infnl then gosub inf_position gosub inf_draw 'if you want to draw faster ' gosub inf_draw ' gosub inf_draw bg 0 pal 1 'text 3,2,"window" number 3,3,infpl,4 number 3,4,infpt,4 number 3,5,infpr,4 number 3,6,infpb,4 'text 12,2,"cursor" 'number 12,3,infcl,4 'number 12,4,infct,4 'number 12,5,infcr,4 'number 12,6,infcb,4 wait vbl loop 'make sure the camera position allow to see the world and some of the out-of-bound characters around it. inf_position: infnl=0 'in x axis if infpw>infw then 'world is bigger than the view l=infl*infs r=(infr+1)*infs-infw 'prevent to past beyond if infxr then infx=r else 'world is small than the view, center it infx=-(infw-infpw)/2 end if 'in y axis if infph>infh then 'world is bigger than the view t=inft*infs b=(infb+1)*infs-infh if infyb then infy=b else 'world is small than the view, center it infy=-(infh-infph)/2 end if call inf_scroll(infx,infy) goto inf_prepare inf_prepare: 'rectangle of the view, the portion of the visible world 'a.k.a.: view position in world-cell-coords infpl=int(infx/infs)-infco infpt=int(infy/infs)-infco infpr=int((infx+infw)/infs)+infco infpb=int((infy+infh)/infs)+infco return inf_draw: 'render missing world cells at left if infplinfl then dec infcl if infcr-infcl>=infg then dec infcr call inf_world(infcl,infct,1,infcb-infct+1) end if 'render missing cells at right if infpr>infcr and infcr=infg then inc infcl call inf_world(infcr,infct,1,infcb-infct+1) end if 'render missing cells at top if infptinft then dec infct if infcb-infct>=infg then dec infcb call inf_world(infcl,infct,infcr-infcl+1,1) end if 'render missing cells at bottom if infpb>infcb and infcb=infg then inc infct call inf_world(infcl,infcb,infcr-infcl+1,1) end if return #1:MAIN PALETTES 040A0908000202000000000000000000 00000000000000000000000000000000 #2:DEFAULT CHARACTERS 00000000000000000000000000000000 FFFFFFFFFFFFFFFF0000000000000000 00003F3F3037343400003F202F2F2C2C 0000FFFF81FF00000000FF81FFFF0000 0000FCF414F434340000FC0CECEC2C2C 3434343C343434342C2C2C3C2C2C2C2C 0000003C343434340000003C2C2C2C2C 343434343C0000002C2C2C2C3C000000 00001F1F101F000000001F101F1F0000 3434F7FF10F734342C2CEF00EFEF2C2C 007EFFFF42C37E00007EC342FFFF7E00 3434373F203F00002C2C2F203F3F0000 3434F4F404FC00002C2CEC0CFCFC0000 34343434343434342C2C2C2C2C2C2C2C 0000FFFF10F734340000FF00EFEF2C2C 3434F7F700FF00002C2CEF08FFFF0000 00000003070F1F180000000304081017 000007FFFBFBFB3B000007FC040404E4 0000E0FFDFDFDFDF0000E03F20202020 000003FFFDFDFDFD000003FE02020202 0000E0FFDFDFDFD80000E03F20202027 000000C020908868000000C0E07078F8 1F1F1F1F1F1F1F181010101010101017 888888888888886878787878787878F8 00000000000000070000000000000007 00000000000000E000000000000000E0 18171F3F3834232717181020272B3C3B 68D8C8C42434FCFCF838383CFCDC3CDC 000003070D0D0D09000003060E0A0A0E 1817E8F7CFCFC0C71718F73830303F38 088807EFF1F121D1F878FF1E0E0EFE3E 0000C0FFB0B0B0B00000C07F50505050 171F3F38372F2F2F1810202728303030 D7CCC464148F8C8C3C3F3FFFFF7F7C7C E02020203FE000003FFFFFFFFFE00000 03020202FE030000FEFFFFFFFF030000 EF3F3F3837EF2F2F38F0E0E7E8F03030 D8C8C464148C8C8C38383CFCFC7C7C7C 171F3F38372F2F2F1810202728303030 D8C8C464148C8C8C38383CFCFC7C7C7C 0F1F3F38372F2F2F0810202728303030 D0C8C464148C8C8C30383CFCFC7C7C7C 36160B07000000002B1B0C0700000000 3438F0E000000000DCD830E000000000 0F0A0A0E060300000A0F0F0F07030000 DF3F38372FEF2F1F30E0E7E8F0F03010 CBC666168E8F8C883E3FFFFF7F7F7C78 F77040407FC0000048FFFFFFFFC00000 1F1F1F1F1F1F1713101010101010181C 88888BCFFDFDFDFD78787B3E02020202 1F1FFFFFDFDFDFDE1010F03020202021 8888888888880808787878787878F8F8 1F1F1F1F1F1F1F1F1010101010101010 88888888888888887878787878787878 0000E0FFCFCFC0C70000E03F30303F38 000003FFF1F121D1000003FE0E0EFE3E 1817E8F7CFCFCFCC1718F73830303033 088807EFF1F1F131F878FF1E0E0E0ECE 181738372F3F38371718272830202728 088807EFF1F121D1F878FF1E0E0EFE3E 1817E8F7CFCFC0C71718F73830303F38 088804ECF4F424D4F878FC1C0C0CFC3C 000000FFFFFFFFFF000000FF00000000 3434373F303734342C2C2F202F2F2C2C 08080403000000000F0F070300000000 03020202FE030000FEFFFFFFFF030000 E02020203FE000003FFFFFFFFFE00000 101020C000000000F0F0E0C000000000 000000000F0F0205000000000F000F0F 00000000F0F0F0F000000000F000F0F0 DF3F38372FEF2F1F30E0E7E8F0F03010 CBC666168E8F8C883E3FFFFF7F7F7C78 E02020203FE000003FFFFFFFFFE00000 03020202FE030000FEFFFFFFFF030000 2F3F38372F2F2F1F3020272830303010 CBC666168E8F8C883E3FFFFF7F7F7C78 DF3F38372FEF2F1F30E0E7E8F0F03010 CCC464148C8C8C883C3CFCFC7C7C7C78 00000000FF000000FFFFFFFFFF000000 3434F4F414F434342C2CEC0CECEC2C2C 0000FFFF00FF00000000FF00FFFF0000 0000FFFF80FF00000000FF80FFFF0000 0000FFFF01FF00000000FF01FFFF0000 0000F8F808F800000000F808F8F80000 #3:META TILES DB 00002A02000000001000110012001300 1400150016001700180019001A001B00 00001C001D001E001F001F0830003100 32003300340035003600370038003900 3A003B003C003D003E003E0012003E00 3E0013001C0800000000000020002100 22002300240025002600270028002900 2A002B0000002C002D002E002F002F08 40004100420043003400350046004700 480049004A004B004C004D004E004E00 22004E004E0023002C080000 #4:MAP 00001428010001000100010001000100 01000100010001000100010001000100 01000100010001000100010001000200 5100500052000E000E00040000000000 00000800040000000000020003000400 0000010052000C000000000008000C00 0D000B00510050005000040005000000 00000B00040005000000010001000000 00000000080052000C00000000000000 00003F000C000000000000000D000D00 00000100010000000000000000000000 000000000000000000000D0000000000 000000000D000D000000010001000000 00000000000000000000000000000000 00000B0051005000500052000C000B00 04000100010000000000000000000000 00000000000000000000020051005000 50005000500052004F00010001000000 00000000000000000000000000000000 06000D00000000000000000000000000 07000100010000000200510050005000 50005000500052004F000B0004000000 00000000000000000000010001000000 05000600060000000000000000000000 0B0003000C0000000000000000000000 00000100010000000B000F0009005300 00000000000000000000000000000000 00000000000000000000010001000000 00000000050000000000000000000000 00000000000000000000000008000400 0000010001000000000000000B005100 50005000500050005000520004000000 00000000000005000000010001000000 00000000000000000000000000000000 000000000B0051005000500052004F00 00000100010000000000000000000000 00000000000000000000000000000000 0000000000000D000000010001000000 00000000000000000000000000000000 00000000000000000000020003000C00 00000100010000000000000000000000 00000000000000000000000000000000 08000900530000000000010001000000 00000000000000000000000000000000 00000000000000000000050000000000 00000100010000000000000000000000 02005100500050005000500052000400 02000C00000000000000010001000000 00000000000000000D00000000000000 0000000002000F000C00000000000000 00000100010000000000000000000000 0D00000000000000000000000B005100 50005000500050005300010001000000 00000000000000000D00000000000000 00000000000000000000000000000000 00000100010000000000000000000000 05000000000000000000000000000000 00000000000000000000010001000000 00000000000000000D00000000000000 00000000000000000000000000000000 00000100010000000000000000000000 0D000000000000000000000000000000 00000000000000000000010001000000 00000200030004000D00000000000000 00000000000000000000000000000000 000001000100000000003F0053000B00 0C000000000000000000000000000000 00000000000000000000010001000000 00000B00510050005200040000000000 00000000000000000000000000000000 00000100010000000000000000000000 00000500000000000000000000000000 00000000000000000000010001000000 000000000000000000000B0051005200 04000000000000000000000000000000 00000100010000000000000008000300 04000000000000000500000000000000 00000000000000000000010001000000 00000000000000000B00510050005200 4F000000000000000000000000000000 00000100010000000000000000000000 00000000000000000D00000000000000 00000000000000000000010001000000 00000000000000000000000000000000 0D000000060000000000000000000000 00000100010000000000000000000000 0000000000000000050002000C000000 00000000000000000000010001000000 00000000000000000000000000000000 0B004F00000000000000000000000000 00000100010000000000000000000000 000000000000000000000D0000000000 00000000000002005100500001000000 00000000000000000000000000000000 00000D00020051005000500052000C00 00000100010000000000000000000000 000000000000000000000B000C000000 00000000000000000000010001000100 01000100010001000100010001000100 01000100010001000100010001000100 01000100