tilemap problem

BlitzMax Forums/BlitzMax Beginners Area/tilemap problem

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

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!