tilemap problem

BlitzMax Forums/BlitzMax Beginners Area/tilemap problem

Kernle 32DLL_2(Posted 2005) [#1]
i have a problem with tilemaps. i have a minimal X and a maximal X coordinate.
max_X=(map_breite*16)+scrollx 
if max_X>800 then 
max_map_X_subtraktion=max_x-800 
else 
max_map_X_subtraktion=0
endif 

max_map_X=(map_breite-(max_map_X_subtraktion/16))+scrollx/16 
if max_map_X<1 then max_map_X=0
min_X=(scrollx/16)
if min_X<0 then min_X=0

max_y=(map_hoehe*16)+scrolly
if max_y>600 then max_map_y_subtraktion=max_y-600
if max_y<=600 then max_map_y_subtraktion=0
max_map_y=(map_hoehe-(max_map_y_subtraktion/16))+scrolly/16
if max_map_y<1 then max_map_y=0
min_y=(scrolly/16)
if min_y<0 then min_y=0


so i draw my map

for mlayer=1 to layer
for map_x=min_X to max_map_x-1
for map_y=min_Y to max_map_y-1
DrawImagetiles,(map_x*16),(map_y*16),map[map_x,map_y,mlayer] 
next
next
next 


everythings is perfect, but when i draw a tile on my map ,the tile does not scroll with the map. i hope somebody will help me.

here is the complete code
[url]http://www.blitz-pasting.net/index.php?content=bp_showupload&id=174[/url]


ImaginaryHuman(Posted 2005) [#2]
Change the map data when you draw the tile, to represent the tile, then let the `draw my map` routine include it.


Tiger(Posted 2005) [#3]
I change a some in your code, test this:
SetGraphicsDriver GLMax2DDriver()
Graphics 800,600,0,90

Global map:Int[1500,1500,21]
Global map_breite:Int=1499
Global map_hoehe:Int=1499
Global map_x:Int
Global map_y:Int
Global layer:Byte=10
Global scaleX:Float=1 
'#######
Global max_X:Int
Global max_map_X:Int 
Global max_map_X_subtraktion:Int 
Global min_X:Int
'#######
Global max_y:Int
Global max_map_y:Int 
Global max_map_y_subtraktion:Int 
Global min_y:Int
'#######
Global scrollX:Int
Global scrolly:Int 
'#######
Global mx2:Int
Global my2:Int 


Global tiles=LoadAnimImage("CHIPSETS/1.png",16,16,0,18*16)

While Not KeyDown(key_escape)
Cls

frames:+1     
If MilliSecs()-timer>1000 Then
fps=frames
frames=0
timer=MilliSecs()
EndIf


map_berechnung()
auf_map_malen()
map_zeichnen()


If KeyDown(key_left) Then scrollx:-1
If KeyDown(key_right) Then scrollx:+1
If KeyDown(key_up) Then scrolly:-1
If KeyDown(key_down) Then scrolly:+1

'##################################
DrawText "fps :"+fps,0,0
'#################################
DrawText "max_x :"+max_x,0,32
DrawText "min_x :"+min_x,0,48
DrawText "scrollx :"+scrollx,0,64
DrawText "max_map_X :"+max_map_X,0,80
'##################################
DrawText "max_y :"+max_y,0,112
DrawText "min_y :"+min_y,0,128
DrawText "scrolly :"+scrolly,0,144
DrawText "max_map_x :"+max_map_Y,0,160
'##################################
DrawText "mx2 :"+mx2,0,192
DrawText "my2 :"+my2,0,208

Flip
Wend
End 

Function map_berechnung()

max_X=(map_breite*16)+scrollx 
If max_X>800 Then 
max_map_X_subtraktion=max_x-800 
Else 
max_map_X_subtraktion=0
EndIf 


max_map_X=(map_breite-(max_map_X_subtraktion/16))+scrollx/16 

If max_map_X<1 Then max_map_X=0
min_X=(scrollx/16)
If min_X<0 Then min_X=0



max_y=(map_hoehe*16)+scrolly
If max_y>600 Then max_map_y_subtraktion=max_y-600
If max_y<=600 Then max_map_y_subtraktion=0
max_map_y=(map_hoehe-(max_map_y_subtraktion/16))+scrolly/16
If max_map_y<1 Then max_map_y=0
min_y=(scrolly/16)
If min_y<0 Then min_y=0
End Function 

Function auf_map_malen()

If MouseDown(1) Then map[mx2,my2,layer]=4
mx2=(MouseX()/16)-(scrollx/16) 
my2=(MouseY()/16)-(scrolly/16) 

End Function

Function map_zeichnen()

For mlayer=1 To layer
For map_x=0 To 50
For map_y=0 To 35
DrawImage tiles,(map_x*16),(map_y*16),map[map_x+scrollx,map_y+scrolly,mlayer] 
Next
Next
Next 

End Function 



Kernle 32DLL_2(Posted 2005) [#4]
tiger your idear is great, but there are two little mistakes.The fist one is
for map_x=0 to 50
for map_y=0 to 35

so the map is everytimes biger then X=50*16 and Y=35*16 so it would be impossible to create maps with a size 20*20 for example.

The second mistake is
map[map_x+scrollx,map_y+scrolly,mlayer] 

don`t forget the borders of the array ( map[1500,1500,21])
so you have to write
map[map_x+scrollx/tile_x,map_y+scrolly/tile_y,mlayer]


and that is the rest
SetGraphicsDriver GLMax2DDriver()
Graphics 800,600,0,90

Global map:Int[1500,1500,21]
Global map_breite:Int=1120
Global map_hoehe:Int=1120
Global map_x:Int
Global map_y:Int
Global layer:Byte=10
Global scaleX:Float=1 
'#######
Global max_X:Int
Global max_map_X:Int 
Global max_map_X_subtraktion:Int 
Global min_X:Int
'#######
Global max_y:Int
Global max_map_y:Int 
Global max_map_y_subtraktion:Int 
Global min_y:Int
'#######
Global scrollX:Int
Global scrolly:Int 
'#######
Global mx2:Int
Global my2:Int 


Global tiles=LoadAnimImage("CHIPSETS/1.png",16,16,0,18*16)

While Not KeyDown(key_escape)
Cls

frames:+1     
If MilliSecs()-timer>1000 Then
fps=frames
frames=0
timer=MilliSecs()
EndIf


map_berechnung()
auf_map_malen()
map_zeichnen()


If KeyDown(key_left) Then scrollx:-16
If KeyDown(key_right) Then scrollx:+16
If KeyDown(key_up) Then scrolly:-16
If KeyDown(key_down) Then scrolly:+16

'##################################
DrawText "fps :"+fps,0,0
'#################################
DrawText "max_x :"+max_x,0,32
DrawText "min_x :"+min_x,0,48
DrawText "scrollx :"+scrollx,0,64
DrawText "max_map_X :"+max_map_X,0,80
'##################################
DrawText "max_y :"+max_y,0,112
DrawText "min_y :"+min_y,0,128
DrawText "scrolly :"+scrolly,0,144
DrawText "max_map_x :"+max_map_Y,0,160
'##################################
DrawText "mx2 :"+mx2,0,192
DrawText "my2 :"+my2,0,208

Flip
Wend
End 

Function map_berechnung()

max_X=(map_breite*16)+scrollx 
If max_X>800 Then 
max_map_X_subtraktion=max_x-800 
Else 
max_map_X_subtraktion=0
EndIf 


max_map_X=(map_breite-(max_map_X_subtraktion/16))+scrollx/16 

If max_map_X<1 Then max_map_X=0
min_X=(scrollx/16)
If min_X<0 Then min_X=0



max_y=(map_hoehe*16)+scrolly
If max_y>600 Then max_map_y_subtraktion=max_y-600
If max_y<=600 Then max_map_y_subtraktion=0
max_map_y=(map_hoehe-(max_map_y_subtraktion/16))+scrolly/16
If max_map_y<1 Then max_map_y=0
min_y=(scrolly/16)
If min_y<0 Then min_y=0
End Function 

Function auf_map_malen()

If MouseDown(1) Then map[mx2,my2,layer]=4
mx2=(MouseX()/16)-(scrollx/16) 
my2=(MouseY()/16)-(scrolly/16) 

End Function

Function map_zeichnen()

For mlayer=1 To layer
For map_x=min_X To max_map_x-1
For map_y=min_Y To max_map_y-1
DrawImage tiles,(map_x*16),(map_y*16),map[map_x-scrollx/16,map_y-scrolly/16,mlayer] 
Next
Next
Next 

End Function 


thx for your great idear!