Hi guys, i was wondering if anyone could help me. I'm trying to create a 2d tile map editor but i'm having problems with the code. You'll probably have to run the code to see what problem i'm talking about. Please if anyone can help me, i'd be most grateful. By the way, you have to press SPACE to lay a tile down.
Heres the code:
;Tile map editor
Graphics 800,600
SetBuffer BackBuffer()
Global tile_w=32:Global tile_h=32
Global curs_x=0:Global curs_y=0
Global map_x=0:Global map_y=0
Global map_width=GraphicsWidth()/tile_w
Global map_height=GraphicsHeight()/tile_h
Global count=0
Dim mapx(map_width),mapy(map_height)
While Not KeyHit(1)
Cls
control
update_map
draw_cursor
Text 0,0,"X:"+map_x+" Y:"+map_y
Flip
Wend
End
Function draw_cursor()
Rect curs_x,curs_y,tile_w,tile_h,False
End Function
Function control()
If KeyHit(203)
If map_x>0
curs_x=curs_x-tile_w
map_x=map_x-1
EndIf
EndIf
If KeyHit(205)
If map_x<map_width-1
curs_x=curs_x+tile_w
map_x=map_x+1
EndIf
EndIf
If KeyHit(200)
If map_y>0
curs_y=curs_y-tile_h
map_y=map_y-1
EndIf
EndIf
If KeyHit(208)
If map_y<map_height-1
curs_y=curs_y+tile_h
map_y=map_y+1
EndIf
EndIf
If KeyHit(57)
mapx(count)=curs_x
mapy(count)=curs_y
count=count+1
EndIf
End Function
Function update_map()
If count>0
For y=0 To count-1
For x=0 To count-1
Rect mapx(x),mapy(y),32,32
Next
Next
EndIf
End Function
Thanks guys
BLUE
Heres the code:
;Tile map editor
Graphics 800,600
SetBuffer BackBuffer()
Global tile_w=32:Global tile_h=32
Global curs_x=0:Global curs_y=0
Global map_x=0:Global map_y=0
Global map_width=GraphicsWidth()/tile_w
Global map_height=GraphicsHeight()/tile_h
Global count=0
Dim mapx(map_width),mapy(map_height)
While Not KeyHit(1)
Cls
control
update_map
draw_cursor
Text 0,0,"X:"+map_x+" Y:"+map_y
Flip
Wend
End
Function draw_cursor()
Rect curs_x,curs_y,tile_w,tile_h,False
End Function
Function control()
If KeyHit(203)
If map_x>0
curs_x=curs_x-tile_w
map_x=map_x-1
EndIf
EndIf
If KeyHit(205)
If map_x<map_width-1
curs_x=curs_x+tile_w
map_x=map_x+1
EndIf
EndIf
If KeyHit(200)
If map_y>0
curs_y=curs_y-tile_h
map_y=map_y-1
EndIf
EndIf
If KeyHit(208)
If map_y<map_height-1
curs_y=curs_y+tile_h
map_y=map_y+1
EndIf
EndIf
If KeyHit(57)
mapx(count)=curs_x
mapy(count)=curs_y
count=count+1
EndIf
End Function
Function update_map()
If count>0
For y=0 To count-1
For x=0 To count-1
Rect mapx(x),mapy(y),32,32
Next
Next
EndIf
End Function
Thanks guys
BLUE