Code not working :-(

Blitz3D Forums/Blitz3D Programming/Code not working :-(

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.

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