Please help with this code
BlitzPlus Forums/BlitzPlus Programming/Please help with this code
| ||
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 |
| ||
;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 ; <<< CHANGED (count not needed) Dim map(map_width,map_height) ; <<< Changed (from 2 single arrays to one) 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) ; <<< CHANGED map(map_x,map_y)=1 EndIf End Function Function update_map() ; <<< CHANGED For y=0 To map_height For x=0 To map_width If map(x,y) = 1 Rect x*tile_w,y*tile_h,tile_w,tile_h EndIf Next Next End Function Hope this helps |
| ||
In the original code just change this function:Function update_map() For c = 0 To count-1 Rect mapx(c),mapy(c),32,32 Next End Function |
| ||
eh, oh yeah :blush: mind you my way is still better ;), as it allows you store image handles in the array for each tile. |
| ||
Thanks so much guys, you've noth helped me out a great deal. Thanks again BLUE |