Code not working :-(
Blitz3D Forums/Blitz3D Programming/Code not working :-(
| ||
For some reason my code isn't working. Only 1 item in the array has the value 1 when the space is pressed, but for some reason it is drawing the whole grid of items. I would be very grateful if someone could help :) here is my code (The problem lies in the draw_world function) Just copy and paste it then run it. Graphics 800,600 SetBuffer BackBuffer() Global world_x = 0 Global world_y = 0 Global world_width = 800 Global world_height = 600 Global grid_x = 0 Global grid_y = 0 Global grid_width = 9 Global grid_height = 9 Global tile_size = 50 Global cursor_x = 0 Global cursor_y = 0 Dim world(world_width-1,world_height-1) For x=0 To world_width-1 For y=0 To world_height-1 world(x,y)=0 Next Next While Not KeyHit(1) Cls user_control draw_world draw_grid Flip Wend Function draw_grid() For x=0 To grid_width For y=0 To grid_height Rect grid_x+x*tile_size,grid_y+y*tile_size,tile_size,tile_size,0 Next Next Color 0,0,255 Rect grid_x+cursor_x*tile_size,grid_y+cursor_y*tile_size,tile_size,tile_size,0 Color 255,255,255 End Function Function draw_world() For x1=0 To grid_width For y1=0 To grid_height For x2=0 To 10 For y2=0 To 10 If world(x2,y2)=1 Then Oval grid_x+x1*tile_size,grid_y+y1*tile_size,5,5 EndIf Next Next Next Next End Function Function user_control() If KeyHit(205) And cursor_x<grid_width Then cursor_x = cursor_x + 1 If KeyHit(203) And cursor_x>0 Then cursor_x = cursor_x - 1 If KeyHit(200) And cursor_y>0 Then cursor_y = cursor_y - 1 If KeyHit(208) And cursor_y<grid_height Then cursor_y = cursor_y + 1 If KeyHit(57) Then world(0,0)=1 End Function Thanks |
| ||
I'm think you want this?Graphics 800,600 SetBuffer BackBuffer() Global world_x = 0 Global world_y = 0 Global world_width = 800 Global world_height = 600 Global grid_x = 0 Global grid_y = 0 Global grid_width = 9 Global grid_height = 9 Global tile_size = 50 Global cursor_x = 0 Global cursor_y = 0 Dim world(world_width-1,world_height-1) For x=0 To world_width-1 For y=0 To world_height-1 world(x,y)=0 Next Next While Not KeyHit(1) Cls user_control draw_world draw_grid Flip Wend Function draw_grid() For x=0 To grid_width For y=0 To grid_height Rect grid_x+x*tile_size,grid_y+y*tile_size,tile_size,tile_size,0 Next Next Color 0,0,255 Rect grid_x+cursor_x*tile_size,grid_y+cursor_y*tile_size,tile_size,tile_size,0 Color 255,255,255 End Function Function draw_world() For x1=0 To grid_width For y1=0 To grid_height ;For x2=0 To 10 ;For y2=0 To 10 If world(x1,y1)=1 Then Oval grid_x+x1*tile_size,grid_y+y1*tile_size,5,5 EndIf ;Next ;Next Next Next End Function Function user_control() If KeyHit(205) And cursor_x<grid_width Then cursor_x = cursor_x + 1 If KeyHit(203) And cursor_x>0 Then cursor_x = cursor_x - 1 If KeyHit(200) And cursor_y>0 Then cursor_y = cursor_y - 1 If KeyHit(208) And cursor_y<grid_height Then cursor_y = cursor_y + 1 If KeyHit(57) Then world(cursor_x,cursor_y)=1 End Function |
| ||
Thanks Luke :) How do i get it to scroll as well please? Thanks |
| ||
hey goldwing :o) How do you mean scroll? What are you wanting to scroll? |
| ||
Hey Ross :) Well, i have the visible grid which is 10 tiles in length. Then you have the actual world width and length which are not visible. When you move along each tile, i want the world_x to increase by 1. When you get to the end of the grid, i want it to scroll and keep increasing the world_x whilst drawing the contents of that area when scrolling :) |
| ||
A quick bit of messy code, By the way what are you making? Graphics 800,600 SetBuffer BackBuffer() Global world_x = 0 Global world_y = 0 Global world_width = 800 Global world_height = 600 Global grid_x = 0 ;? Global grid_y = 0 ;? Global grid_width = 20 Global grid_height = 20 Global tile_size = 50 Global cursor_x = 0 Global cursor_y = 0 Dim world(world_width-1,world_height-1) For x=0 To world_width-1 For y=0 To world_height-1 world(x,y)=0 Next Next While Not KeyHit(1) Cls user_control draw_world draw_grid Flip Wend Function draw_grid() Origin -world_x,-world_y For x=0 To grid_width For y=0 To grid_height Rect grid_x+x*tile_size,grid_y+y*tile_size,tile_size,tile_size,0 Next Next Color 0,0,255 Rect grid_x+cursor_x*tile_size,grid_y+cursor_y*tile_size,tile_size,tile_size,0 Color 255,255,255 End Function Function draw_world() Origin -world_x,-world_y For x=0 To grid_width For y=0 To grid_height If world(x,y)=1 Then Oval grid_x+x*tile_size,grid_y+y*tile_size,5,5 EndIf Next Next End Function Function user_control() Origin 0,0 If KeyHit(205) And cursor_x<grid_width Then cursor_x = cursor_x + 1 If KeyHit(203) And cursor_x>0 Then cursor_x = cursor_x - 1 If KeyHit(200) And cursor_y>0 Then cursor_y = cursor_y - 1 If KeyHit(208) And cursor_y<grid_height Then cursor_y = cursor_y + 1 If KeyHit(57) Then world(cursor_x,cursor_y)=1 ;---Scrolling--- If (cursor_x*tile_size)+tile_size-world_x > world_width-70 Then world_x=world_x+4 End If If (cursor_x*tile_size)-world_x < 70 Then world_x=world_x-4 End If If (cursor_y*tile_size)+tile_size-world_y > world_height-70 Then world_y=world_y+4 End If If (cursor_y*tile_size)-world_y < 70 Then world_y=world_y-4 End If End Function |
| ||
Thanks Luke :) I am just trying to make an editor at the moment. After that, i hope to start working on a platform game thereafter :) Thanks again |