Help with Tile-Based Game

Blitz3D Forums/Blitz3D Programming/Help with Tile-Based Game

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.

OK. I'm having more trouble.

Here is the code:
;..::DRILLER::..
;by Steven Campbell @ No Enemies Development
;steven@...
;Special Thanks: Sam Schoenholz

Graphics 800,600,16,2
SetBuffer BackBuffer()
AutoMidHandle False
SeedRnd MilliSecs()

;..::TYPES::..
;mineral type
Type mineral
	Field value
	Field points
	Field x, y
	Field image
	Field min_depth
	Field max_depth
	Field frame
End Type
;building type
Type building
	Field image
	Field name$
	Field x, y
End Type
;upgrade type
Type upgrade
	Field name$
	Field u_type$
	Field image
	Field index
End Type 

;..::GLOBALS::..
;main globals
Global logic$ = "game"
Global page = 0
;statistics
Global mineral_num
Global mineral_got
Global score, money, fuel, HP
Global PlayerX = 10
Global PlayerY = 10
;images
Global digger = LoadImage("images\digger.bmp")
Global tile_dirt = LoadAnimImage("images\dirt.bmp", 40, 40, 0, 2)
Global minerals  = LoadAnimImage("images\tiles.bmp", 40, 40, 0, 8)
;time
Global fueltime, fueltime2
;scrolling
Global OffsetX = 0
Global NewOffsetX = 0
Global OffsetY = 0
Global NewOffsetY = 0

;..::ARRAYS::..
;map
Dim map(2,0,0)

;..::CONSTANTS::..
;key consts.
Const KEY_UP     = 208
Const KEY_DOWN   = 200
Const KEY_LEFT   = 203
Const KEY_RIGHT  = 205
Const KEY_SPACE  = 57
Const KEY_ENTER  = 28
Const KEY_ESC    = 1

BuildLevel()

;..::MAIN LOOP::..
While Not KeyDown(KEY_ESC)
	UpdateLogic()
Wend

;..::]] FUNCTIONS [[::..

;MAIN FUNCTIONS

;UpdateLogic() - updates the game
Function UpdateLogic()
	
	Select logic$
		
		Case "game"
			
			UpdateGame()
		
		Case "menu"
			
			UpdateMenu()
		
		Case "ingame"
			
			;update ingame menu
		
		Case "credits"
			
			;update credits
		
		Case "intro"
			
			;update intro
		
		Case "fuelstation"
			
			;update fuel station
		
		Case "upgradeshop"
			
			;update upgrade shop
		
		Case "repairshop"
			
			;update repair shop
		
		Case "deposit"
			
			;update mineral deposit
		
	End Select
	
End Function

;BuildLevel() - creates the level
Function BuildLevel()
	
	For i = 1 To 20
		
		newMineral.mineral = New mineral
		newMineral\image = CopyImage(minerals)
		
		v = Rand(0, 8)
		
		If v = 1
			newMineral\value = 50
			newMineral\min_depth = 0
			newMineral\max_depth = 2000
			newMineral\frame = 0
		ElseIf v = 2
			newMineral\value = 100
			newMineral\min_depth = 10
			newMineral\max_depth = 2000
			newMineral\frame = 1
		ElseIf v = 3
			newMineral\value = 250
			newMineral\min_depth = 50
			newMineral\max_depth = 2000
			newMineral\frame = 2
		ElseIf v = 4
			newMineral\value = 500
			newMineral\min_depth = 100
			newMineral\max_depth = 2000
			newMineral\frame = 3
		ElseIf v = 5
			newMineral\value = 1000
			newMineral\min_depth = 500
			newMineral\max_depth = 2000
			newMineral\frame = 4
		ElseIf v = 6
			newMineral\value = 5000
			newMineral\min_depth = 750
			newMineral\max_depth = 2000
			newMineral\frame = 5
		ElseIf v = 7
			newMineral\value = 20000
			newMineral\min_depth = 1000
			newMineral\max_depth = 2000
			newMineral\frame = 6
		ElseIf v = 8
			newMineral\value = 100000
			newMineral\min_depth = 1750
			newMineral\max_depth = 2000
			newMineral\frame = 7
		EndIf 
			
		
		newMineral\x = Rand(-20, 20)*40
		newMineral\y = Rand(newMineral\min_depth, newMineral\max_depth)*40
	
	Next 
	
End Function 	

;GAME FUNCTIONS

;UpdateGame() - main updating function
Function UpdateGame()
	
	UpdateScrolling()
	UpdateMinerals()
	DrawLevel()
	UpdateMovement()
	
	Flip
	Cls
	
End Function 

;UpdateScrolling() - update the map scrolling
Function UpdateScrolling()

	If PlayerX>OffsetX+760 Then NewOffsetX = NewOffsetX + 100
	If PlayerX<OffsetX+40 And OffsetX > 0 Then NewOffsetX = NewOffsetX - 100
		While NewOffsetX-OffsetX>0
			Cls
			OffsetX = OffsetX + 2
			Origin -OffsetX,0
			DrawImage digger,PlayerX,PlayerY
			Flip 
		Wend
		;Preform Tweening
		While NewOffsetX-OffsetX<0 
			Cls 
			OffsetX = OffsetX - 2
			Origin -OffsetX,0
			DrawImage digger,PlayerX,PlayerY
			Flip
		Wend
	
	If PlayerY>OffsetY+560 Then NewOffsetY = NewOffsetY + 100
	If PlayerY<OffsetY+40 And OffsetY > 0 Then NewOffsetY = NewOffsetY - 100
		While NewOffsetY-OffsetY>0
			Cls
			OffsetY = OffsetY + 2
			Origin -OffsetY,0
			DrawImage digger,PlayerX,PlayerY,PlayerAnimation
			Flip
		Wend
		;Preform Tweening
		While NewOffsetY-OffsetY<0 
			Cls 
			OffsetY = OffsetY - 2
			Origin -OffsetY,0
			DrawImage digger,PlayerX,PlayerY,PlayerAnimation
			Flip
		Wend


End Function

;UpdateMovement() - update player movement
Function UpdateMovement()
	
	If KeyHit(KEY_LEFT)
		PlayerX = PlayerX - 40
	EndIf
	
	If KeyHit(KEY_RIGHT)
		PlayerX = PlayerX + 40
	EndIf
	
	If KeyHit(KEY_UP)
		PlayerY = PlayerY - 40
	EndIf
	
	If KeyHit(KEY_DOWN)
		PlayerY = PlayerY + 40
	EndIf
	
End Function

;UpdateMinerals() - updates all the minerals
Function UpdateMinerals()
	
	mineral_num = 0
	
	For u.mineral = Each mineral
		
		mineral_num = 0
		
		If ImagesCollide(digger, PlayerX, PlayerY, 0, u\image, u\x, u\y, u\frame)
			score = score + u\points
			money = money + u\value
			mineral_got = mineral_got + 1
			FreeImage u\image
			Delete u
		EndIf
		
	Next

End Function  

;DrawLevel() - draws the current level
Function DrawLevel()

	For x = 0 To 40*40
		For y = 0 To 2000
		
			DrawImage tile_dirt, x, y, 0
			
		Next
	Next
	
	For m.mineral = Each mineral
		
		DrawImage m\image, m\x, m\y, m\frame
		
	Next 	

End Function

;MENU FUNCTIONS

;UpdateMenu() - updates the main menu
Function UpdateMenu()
	
	Text 400,300, "PRESS [SPACE] TO START",1,1
	Text 400,320, "PRESS [ESC] TO EXIT",1,1
	
	If KeyHit(57)
		BuildLevel()
		logic$ = "game"
	EndIf 
	
	Flip
	Cls
	
End Function

For some reason, when I run it, it won't draw all of the map. What is supposed to happen is that the entire screen is covered with a brownish-color, and that there are scattered circles on it. And there is also supposed to be a yellow smiley face, controlled by the arrow keys. For some reason, when you run it, you get a blank screen.

Any ideas on how to draw the level? Or suggestions on how to get started?

PS: You can just replace the images if you want.