I am writting a simple map 2D and I would like make it coneccted by borders for when scroll reach end of screen, then tiles of map which appears be tiles of begin and vice-versa. So, an infinite repeated map o some like this.
I have posted and example of code to show better what I mean.
I apreciate any sugestion an example becouse I do not know the way to do this with an array still.
Thanks
Graphics 640,480,16,2
Global mapx,mapy,xp,yp
mapx = 20
mapy = 25
xp=0
yp=0
Dim map(mapx,mapy)
Global VistaGrandx1, VistaGrandy1, VistaGrandx2, VistaGrandy2 ; vista grande de graficos
Global limiteX, limitey
VistaGrandx1 = 1
VistaGrandy1 = 1
VistaGrandx2 = 600
VistaGrandy2 = 440
Color 0,250,4
;Rect VistaGrandx1-1 , VistaGrandy1-1 ,VistaGrandx2+2 , VistaGrandy2+2,1
Viewport VistaGrandx1 , VistaGrandy1 ,VistaGrandx2 , VistaGrandy2
Restore mapa
For a=1 To 20
For b=1 To 25
Read map(a,b)
Next
Next
Restore mapa
.mapa
Data 0,0,0,0,1,1,1,2,1,3, 0,0,0,1,1,2,1,0,0,0 ,0,0,0,0,0
Data 0,3,5,7,9,0,1,2,1,3, 5,7,9,0,1,2,1,3,5,7 ,9,0,1,2,5
Data 0,1,2,3,9,1,1,2,1,3, 5,7,9,1,1,2,1,3,5,7 ,9,0,1,2,0
Data 0,3,5,7,9,0,1,2,1,3, 5,7,9,0,1,2,1,3,5,7 ,9,0,1,2,0
Data 0,1,2,3,9,1,1,2,1,3, 5,7,9,1,1,2,1,3,5,7 ,9,0,1,2,0
Data 9,3,5,7,9,0,1,2,1,3, 5,7,9,0,1,2,1,3,5,7 ,9,0,1,2,0
Data 0,1,2,3,9,1,1,2,1,3, 5,7,9,1,1,2,1,3,5,7 ,9,0,1,2,1
Data 1,3,5,7,9,0,1,2,1,3, 5,7,9,0,1,2,1,3,5,7 ,9,0,1,2,1
Data 0,1,2,3,9,1,1,2,1,3, 5,7,9,1,1,2,1,3,5,7 ,9,0,1,2,1
Data 9,3,5,7,9,0,1,2,1,3, 5,7,9,0,1,2,1,3,5,7 ,9,0,1,2,1
Data 0,1,2,3,9,1,1,2,1,3, 5,7,9,1,1,2,1,3,5,7 ,9,0,1,2,1
Data 1,3,5,7,9,0,1,2,1,3, 5,7,9,0,1,2,1,3,5,7 ,9,0,1,2,1
Data 0,1,2,3,9,1,1,2,1,3, 5,7,9,1,1,2,1,3,5,7 ,9,0,1,2,1
Data 1,3,5,7,9,0,1,2,1,3, 5,7,9,0,1,2,1,3,5,7 ,9,0,1,2,1
Data 0,1,2,3,9,1,1,2,1,3, 5,7,9,1,1,2,1,3,5,7 ,9,0,1,2,1
Data 9,3,5,7,9,0,1,2,1,3, 5,7,9,0,1,2,1,3,5,7 ,9,0,1,2,1
Data 0,1,2,3,9,1,1,2,1,3, 5,7,9,1,1,2,1,3,5,7 ,9,0,1,2,1
Data 1,3,5,7,9,0,1,2,1,3, 5,7,9,0,1,2,1,3,5,7 ,9,0,1,2,1
Data 0,1,2,3,9,1,1,2,1,3, 5,7,9,1,1,2,1,3,5,7 ,9,0,3,2,1
Data 0,0,0,0,0,0,0,0,1,3, 5,7,9,0,1,2,1,3,5,7 ,9,0,1,5,1
limiteX=0
limitey=0
While Not KeyHit(1) ; As long as the user hasn't hit ESC yet ...
Cls
Viewport VistaGrandx1, VistaGrandy1, VistaGrandx2, VistaGrandy2
Color 0,250,0
Rect VistaGrandx1+1, VistaGrandy1+1, VistaGrandx2-2, VistaGrandy2-2,0
Color 255,255,255
DibujaPantalla()
; Scroll of screen up
If KeyDown(208) And limitey<0 Then
yp=yp+3
limitey=limitey+3
EndIf
; Scroll of screen down ; actually map stop when it ends, but...
If KeyDown(200) And limitey>-240 Then ; I would like change those next four conditions for some as "If data is last of array then appears in screen,
yp=yp-3 ; first data of array" So, it would be an "infinite map"
limitey=limitey-3 ; somethig as: if map(1,25) next data when screen scroll should be map(1,1) and all as this whwn scroll reach
; end of array.
EndIf
; Scroll of screen left
If KeyDown(203) And limiteX>-450 Then
xp=xp-3
limiteX=limiteX-3
EndIf
; Scroll of screen rigth
If KeyDown(205) And limiteX<0
xp=xp+3
limiteX=limiteX+3
EndIf
; Double buffer mode for smooth screen drawing
SetBuffer BackBuffer()
Flip
Wend
Function DibujaPantalla()
Local x,y,zx,zy
x=0
y=0
zx=42
zy=34
For a=1 To 20
For b=1 To 25
Select map(a,b)
Case 0
Color 120,20,120
Rect x+xp,y+yp,zx,zy
Case 1
Color 20,120,120
Rect x+xp,y+yp,zx,zy
Case 2
Color 20,220,120
Rect x+xp,y+yp,zx,zy
Case 3
Color 40,0,120
Rect x+xp,y+yp,zx,zy
Case 4
Color 20,20,120
Rect x+xp,y+yp,zx,zy
Case 5
Color 60,20,120
Rect x+xp,y+yp,zx,zy
Case 6
Color 100,20,120
Rect x+xp,y+yp,zx,zy
Case 7
Color 20,220,120
Rect x+xp,y+yp,zx,zy
Case 8
Color 20,20,10
Rect x+xp,y+yp,zx,zy
Case 9
Color 10,0,120
Rect x+xp,y+yp,zx,zy
End Select
x=x+42
Next
x=0
y=y+34
Next
Flip
End Function
|