; Big Map demo (Blitz Basic 1.36) ; By Tom Stevenson (wargamer) ; 1/23/2001 ; This program demonstrates how a large map can be created/updated from many image screens ; It would be simpler just to create one giant image to update the screen from ; but many video cards can't handle this. (Direct X limitation) ;screen constants, map size constants Const ScrnW=800, ScrnH=600 ,Xscrns=3, Yscrns=3, nScreens=Xscrns*Yscrns ;Upper left coordinates of map section on screen Global mapX, mapY ;maxim values for MapX and MapY Global MaxMapX = ScrnW * (Xscrns-1)+100 ;(hardwire 50 pixel margins) Global MaxMapY = ScrnH * (Yscrns-1)+100 ;(hardwire 50 pixel margins) ;hexagon dimensions Global cellsizeX=44, cellsizeY=50, aHex=7 ;structure for holding screen information Type ScreenInfo Field hand,x,y End Type ;Initiate map screens Graphics ScrnW,ScrnH Dim scrn.ScreenInfo (nScreens) For x=0 To XScrns-1 For y=0 To YScrns-1 i=i+1 scrn.ScreenInfo (i) =New ScreenInfo scrn(i)\x= x * ScrnW ;X offset of screen relative to map origin 0,0 scrn(i)\y= y * ScrnH ;Y offset of screen relative to map origin 0,0 scrn(i)\hand=CreateImage(scrnW, scrnH) ;create a blank screen drawscreen(scrn(i)) ;fill the screens once Next Next ;draw initial screen SetBuffer BackBuffer() Cls Mapdraw() ;main control loop Repeat If KeyDown(1) Then done=True ;esc If KeyDown(203) Then mapX=mapX-10 ;left arrow If KeyDown(205) Then mapX=mapX+10 ;right arrow If KeyDown(200) Then mapY=mapY-10 ;up arrow If KeyDown(208) Then mapY=mapY+10 ;down arrow If KeyDown(201) Then mapY=mapY-100 ;page up If KeyDown(209) Then mapY=mapY+100 ;page down If KeyDown(199) Then mapY=0:mapX=0 ;home If KeyDown(207) Then ;end mapY=MaxMapY: mapX=MaxMapX EndIf ;make sure map coordinates or in bounds If MapX<0 Then MapX=0 If MapY<0 Then MapY=0 If MapX>MaxMapX Then MapX=MaxMapX If MapY>MaxMapY Then MapY=MaxMapY If MapX<>MapX2 Or MapY<>MapY2 ;redraw map only if necessary MapX2 = MapX MapY2 = MapY Mapdraw() EndIf Until done WaitKey End Function drawScreen(map.ScreenInfo) ;creates initial screens If map\hand=0 Then Stop End Else drawbuf=ImageBuffer (map\hand) EndIf SetBuffer drawbuf Viewport 0,0,ScrnW,ScrnH Cls ;here is the key Origin -map\x,-map\y ;draw some stuff that extends across screens Color 255,0,0 Rect 600,400,400,400 Rect 0,0,800,200 Color 0,250,0 Oval 800,600,400,300 Rect 800,200,800,200 Color 0,255,255 Rect 600,1000,1000,200 Color 255,255,0 ;draw a small square in the bottom right corner Rect ScrnW * (Xscrns)-20, ScrnH * (Yscrns)-20,20,20 Rect 0,0,20,20 ;draw hexes Origin 0,0 Color 255,255,255 Xoff=map\X Mod cellsizeX Yoff=map\Y Mod cellsizeY For my = 0 To 12 For mx = -1 To 17 hX1 = mX * cellsizeX -Xoff hy1 = mY * cellsizeY - ((mX+1) Mod 2) * cellsizeY / 2 -Yoff For side = 1 To 3 hx2 = hx1 + cellsizeX Select side Case 1 rx1 = hx1 + aHex rx2 = hx2 - aHex ry1 = hy1 ry2 = hy1 Case 2 rx1 = hx2 - aHex rx2 = hx2 + aHex ry1 = hy1 ry2 = hy1 + cellsizeY / 2 Case 3 rx1 = hx2 + aHex rx2 = hx2 - aHex ry1 = hy1 + cellsizeY / 2 ry2 = hy1 + cellsizeY End Select Line rx1, ry1, rx2, ry2 Next Next Next SetBuffer BackBuffer() End Function Function Mapdraw() SetBuffer BackBuffer() Cls m=50 ;margin Viewport m,m,ScrnW-m-m, ScrnH-m-m ;This is key Origin m-MapX,m-MapY ;copy image blocks to back buffer For i=1 To nScreens DrawBlockRect scrn(i)\hand, scrn(i)\X, scrn(i)\Y, 0, 0, scrnW,ScrnH Next Viewport 0,0,ScrnW,ScrnH Origin 0,0 Text 20,20,"Map Coordinates: "+Str$(mapX) +" " + Str$(mapY) Text ScrnW-160,20, "Esc Key = Quit" Text 20,ScrnH-20,"Use Up, Down, PageUp, PageDown, Home, and End keys to scroll" Flip ;swap front and back buffers End Function While Not KeyDown(1) Wend End