Drawing Problems...

BlitzMax Forums/BlitzMax Beginners Area/Drawing Problems...

I've got a basic RTS map with different minerals, fog, and a minimap. I have it set up as a 100x100 grid of 32x32 tiles. The only tiles drawn are the minerals and the fog, the 'grass' is not drawn as a tile but just as a big rectangle in the background. I originally used Plot() for my minimap, but with 100 tiles this was too slow so I sorted the minerals into clusters. Basically the top-left mineral tile in each cluster is recorded as 'clustx' and 'clusty', and depending how many tiles are in the cluster, it's width and height are set to 'clustwidth' and 'clustheight'. I then draw at the top left of the screen all the clusters, where one tile is one pixel. Ignore the fact that all minerals are drawn from the start even though they havn't been found yet.
My problem is: As you move to the right of the map, it appears that the minerals clusters on the minimap are disappearing, but that are actually being drawn underneath the minerals and fog. This doesn't make sense as not all the clusters disappear, most of the ones on the right do not. Also, I am drawing the clusters in the minimap [b]after[b] drawing the minerals and fog. Why is this happening and how do I fix it?
Sorry for the lack of comments, I tried to simplify it from the version I originally had.

Rem
This test is the same as graphics_map, but with a minimap.
EndRem

SuperStrict

AppTitle="Mini Map Test"

Graphics(1024,768,32,60)

SeedRnd MilliSecs()

Local mapwidth:Int=100	'width of map
Local mapheight:Int=100	'height of map
Local tilesize:Int=32	'size of each tile

Global player:TPlayer=TPlayer.Create()
Global map:TMap=TMap.Create(mapwidth,mapheight,tilesize,Rnd(5,20))
map.CreateMinerals()

While Not KeyHit(KEY_ESCAPE)

	map.Draw()
	player.Draw()	

	Flip 1;Cls;ResetCollisions	'flip 1 for vSync if available
	
Wend

End

Type TPlayer
	
	Field scrollsp:Int,scrollthresh:Int
	Field selectx:Int,selecty:Int,sightradius:Int
	Field cursor:TImage
	
	Method Draw()		
	
		selectx=(map.offx+MouseX())/map.tilesize
		selecty=(map.offy+MouseY())/map.tilesize		
		
		For Local i:Int=0 To (sightradius*2)
			For Local j:Int=0 To (sightradius*2)
				Local x:Int=((selectx*map.tilesize)/map.tilesize)-(i-sightradius)
				Local y:Int=((selecty*map.tilesize)/map.tilesize)-(j-sightradius)
				If x>=0 And x<=map.width-1 And y>=0 And y<=map.height-1 Then map.Tiles[x,y].fogged=False
			Next
		Next
					
		SetColor(150,0,0)
	
		DrawText("offx: "+map.offx+" offy: "+map.offy,10,10)
	
		If MouseX()<scrollthresh Then map.offx:-scrollsp
		If MouseX()>GraphicsWidth()-scrollthresh Then map.offx:+scrollsp
		If MouseY()<scrollthresh Then map.offy:-scrollsp
		If MouseY()>GraphicsHeight()-scrollthresh Then map.offy:+scrollsp		
	
	End Method
	
	Function Create:TPlayer()
	
		Local p:TPlayer=New TPlayer		
		
			p.scrollsp=10
			p.scrollthresh=25
			p.sightradius=3			
		
		Return p
			
	End Function

End Type

Type TMap

	Field Tiles:TTile[,],width:Int,height:Int,offx:Int,offy:Int,tilesize:Int
	Field image:TImage,background:TImage
	Field clustamount:Int
	
	Method Draw()
	
		SetColor(0,100,0)
		DrawRect(0,0,GraphicsWidth(),GraphicsHeight())				
	
		For Local x:Int=0 To width-1
			For Local y:Int=0 To height-1
				If x>=offx/tilesize And x<=(offx+GraphicsWidth())/tilesize Then
					If y>=offy/tilesize And y<=(offy+GraphicsHeight())/tilesize Then
						If x<width And y<height Then Tiles[x,y].Draw(x,y,tilesize)
					EndIf
				EndIf	
				Tiles[x,y].DrawCluster(x,y)							
			Next							
		Next
		
		If offx<0 Then offx=0
		If offx>width*tilesize-GraphicsWidth() Then offx=(width*tilesize)-GraphicsWidth()
		If offy<0 Then offy=0
		If offy>height*tilesize-GraphicsHeight() Then offy=(height*tilesize)-GraphicsHeight()
	
	End Method
	
	Method CreateMinerals()
	
		Local i:Int,max1:Int,max2:Int,posx:Int,posy:Int		
		
		For Local j:Int=0 To clustamount-1
		
			i=Rnd(0,65)
			posx=Rnd(0,width)
			posy=Rnd(0,height)
			
			Select True
			
				Case i>=0 And i<=30	'metal
					max1=Rnd(1,20)
					max2=Rnd(1,20)									
					For Local x:Int=0 To max1
						For Local y:Int=0 To max2
							If x+posx>=0 And x+posx<=width-1 And y+posy>=0 And y+posy<=height-1 Then 
								Tiles[x+posx,y+posy].kind=1
								Tiles[x+posx,y+posy].name="Nickel"
								Tiles[x+posx,y+posy].amount=Rnd(100,500)
								If x=0 And y=0 Then 
									Tiles[x+posx,y+posy].clustx=posx
									Tiles[x+posx,y+posy].clusty=posy
									Tiles[x+posx,y+posy].clustwidth=max1
									Tiles[x+posx,y+posy].clustheight=max2
								EndIf
							EndIf
						Next
					Next
				
				Case i>30 And i<=50	'oil
					max1=Rnd(5,20)
					max2=Rnd(5,20)									
					For Local x:Int=0 To max1
						For Local y:Int=0 To max2
							If x+posx>=0 And x+posx<=width-1 And y+posy>=0 And y+posy<=height-1 Then 
								Tiles[x+posx,y+posy].kind=2
								Tiles[x+posx,y+posy].name="Oil"
								Tiles[x+posx,y+posy].amount=Rnd(100,500)
								If x=0 And y=0 Then 
									Tiles[x+posx,y+posy].clustx=posx
									Tiles[x+posx,y+posy].clusty=posy
									Tiles[x+posx,y+posy].clustwidth=max1
									Tiles[x+posx,y+posy].clustheight=max2
								EndIf								
							EndIf
						Next
					Next
				
				Case i>50 And i<=60	'gems
					max1=Rnd(1,6)
					max2=Rnd(1,6)									
					For Local x:Int=0 To max1
						For Local y:Int=0 To max2
							If x+posx>=0 And x+posx<=width-1 And y+posy>=0 And y+posy<=height-1 Then 
								Tiles[x+posx,y+posy].kind=3
								Tiles[x+posx,y+posy].name="Gems"
								Tiles[x+posx,y+posy].amount=Rnd(100,500)
								If x=0 And y=0 Then 
									Tiles[x+posx,y+posy].clustx=posx
									Tiles[x+posx,y+posy].clusty=posy
									Tiles[x+posx,y+posy].clustwidth=max1
									Tiles[x+posx,y+posy].clustheight=max2
								EndIf								
							EndIf
						Next
					Next
				
				Case i>60 And i<=65	'diamonds
					max1=Rnd(1,4)
					max2=Rnd(1,4)									
					For Local x:Int=0 To max1
						For Local y:Int=0 To max2
							If x+posx>=0 And x+posx<=width-1 And y+posy>=0 And y+posy<=height-1 Then 
								Tiles[x+posx,y+posy].kind=4
								Tiles[x+posx,y+posy].name="Diamond"
								Tiles[x+posx,y+posy].amount=Rnd(100,500)
								If x=0 And y=0 Then 
									Tiles[x+posx,y+posy].clustx=posx
									Tiles[x+posx,y+posy].clusty=posy
									Tiles[x+posx,y+posy].clustwidth=max1
									Tiles[x+posx,y+posy].clustheight=max2
								EndIf								
							EndIf
						Next
					Next
					
			End Select
		
		Next
	
	End Method
	
	Function Create:TMap(width:Int,height:Int,tilesize:Int,clustamount:Int)
	
		Local m:TMap=New TMap
						
			m.Tiles=New TTile[width,height]
			
			m.width=width
			m.height=height
			m.offx=0
			m.offy=0
			m.tilesize=tilesize				
			m.clustamount=clustamount
			
			For Local i:Int=0 To width-1
				For Local j:Int=0 To height-1
					m.Tiles[i,j]=New TTile
				Next
			Next
		
		Return m
	
	End Function

End Type

Type TTile

	Field fogged:Int=True,kind:Int=0,amount:Int=0,name$=""
	Field clustx:Int,clusty:Int,clustwidth:Int,clustheight:Int
	
	Method Draw(x:Int,y:Int,size:Int)
	
		x=(x*map.tilesize)-map.offx
		y=(y*map.tilesize)-map.offy	
		
		SetColor(255,255,255)	
		SetBlend(ALPHABLEND)
	
		Select kind
			Case 1
				SetColor(150,150,150)
			Case 2
				SetAlpha(0.3)
				SetColor(0,0,0)
			Case 3
				SetColor(200,0,0)	
			Case 4
				SetColor(255,255,255)			
		End Select
							
		'draw minerals
		If kind<>0 And fogged=False And amount>0 Then
			DrawRect(x,y,size,size)			
		EndIf
		
		SetAlpha(1)	
			
		'draw fog
		If fogged=True Then					
			SetColor(0,0,0)
			DrawRect(x,y,size,size)						
		EndIf
	
	End Method
	
	Method DrawCluster(x:Int,y:Int)		
	
		If x=clustx And y=clusty Then
			SetColor(255,0,0)
			DrawRect(clustx,clusty,clustwidth,clustheight)
		EndIf
	
	End Method

End Type


-Thanks

you are giving the answer to your problem. What you need to do is draw the minimap separate after everything else is drawn not while drawing other parts of the maze. I modified your draw routine to draw the map first then the minimap:
	Method Draw()
	
		SetColor(0,100,0)
		DrawRect(0,0,GraphicsWidth(),GraphicsHeight())				
	
		For Local x:Int=0 To width-1
			For Local y:Int=0 To height-1
				If x>=offx/tilesize And x<=(offx+GraphicsWidth())/tilesize Then
					If y>=offy/tilesize And y<=(offy+GraphicsHeight())/tilesize Then
						If x<width And y<height Then Tiles[x,y].Draw(x,y,tilesize)
					EndIf
				EndIf	
											
			Next							
		Next
		For Local x:Int = 0 To width-1
			For Local y:Int=0 To height-1
				tiles[x,y].drawcluster(x,y)
			Next 
		Next
		If offx<0 Then offx=0
		If offx>width*tilesize-GraphicsWidth() Then offx=(width*tilesize)-GraphicsWidth()
		If offy<0 Then offy=0
		If offy>height*tilesize-GraphicsHeight() Then offy=(height*tilesize)-GraphicsHeight()
	
	End Method


Ahhh... That was dumb of me. That's how I originally had it but I thought it was too slow.. But I'm getting mixed up.
Thanks :)