tile scrolling in random 360 directions..

BlitzMax Forums/BlitzMax Programming/tile scrolling in random 360 directions..

Hi, i am trying to make a tile of set width and height and tileable be able to fill the screen and to be able to scroll it whichever direction i want in a 360 direction, i can do the usual 8 directions, but i was trying to make it more fluid for any direction.

this is what i Have so far.


Incbin "gfx/Kystal_BackTile001.png"

Graphics game.deskwidth, game.deskheight, 0
SetBlend ALPHABLEND
Global tang:Float

For y = -1 To Int(game.deskheight / ImageHeight(Ttile.tileimg)) + 1
	For x = -1 To Int(game.deskwidth / ImageWidth(Ttile.tileimg)) + 1
		Ttile.Create(x*ImageWidth(Ttile.tileimg),y*ImageHeight(Ttile.tileimg)) 
	Next
Next

HideMouse
Repeat
SeedRnd MilliSecs() 
game.timer = 0
game.lasttime = MilliSecs() 
	Repeat
	
		Cls
			Ttile.update()
			Ttile.draw() 
			If MouseHit(1) tang = Rand(0, 359)
		Flip
		Delay 1
	
	Until KeyHit(KEY_ESCAPE) 
	End

Until KeyHit(KEY_ESCAPE) 

End

Type Ttile

	Field x:Int, y:Int, f:Float, ang:Float, sp:Float, tw:Int, th:Int, nam:TImage
	
	Global tileimg:timage=LoadImage("incbin::gfx/Kystal_BackTile001.png")
	Global tilelist:TList=New TList
	
	Function Create(xx,yy)
		t:Ttile=New Ttile
		t.nam=tileimg
		t.tw=ImageWidth(t.nam)
		t.th=ImageHeight(t.nam)
		t.x=xx
		t.y=yy
		t.f=0
		t.ang=45
		t.sp = 4.0
		tilelist.AddLast t
	End Function
	
	Function update()
		Local mx:Int
		Local my:Int
		For t:Ttile = EachIn tilelist
			my = Int(Cos(tang) * t.sp)
			mx = Int(Sin(tang) * t.sp)
			t.x = t.x + mx
			t.y = t.y + my
			If t.x >= game.deskwidth + ImageWidth(Ttile.tileimg) Then t.x = t.x - game.deskwidth - mx - ImageWidth(Ttile.tileimg) * 2
			If t.y >= game.deskheight + ImageHeight(Ttile.tileimg) Then t.y = t.y - game.deskheight - my - ImageHeight(Ttile.tileimg) * 2

			If t.x <= (- 1 * ImageWidth(Ttile.tileimg)) Then t.x = t.x + game.deskwidth + (ImageWidth(Ttile.tileimg) * 2) + mx
			If t.y <= (- 1 * ImageHeight(Ttile.tileimg)) Then t.y = t.y + game.deskheight + (ImageHeight(Ttile.tileimg) * 2) + my
		Next
	End Function
	
	Function draw()
		For t:Ttile=EachIn tilelist
			DrawImage t.nam,t.x,t.y,t.f
		Next
	End Function
	

End Type

Type game

	Global timer:Float
	Global lasttime:Float
	Global deskwidth:Int = 1024
	Global deskheight:Int = 768
	Global game:String = ""
	Global score:Int = 0
	Global lmx:Float
	Global lmy:Float
End Type


the image "Kystal_BackTile001.png" is just a 128x128 tile, if you click left mouse it then randomly changes the move angle "tang" from 0 to 359 and moves the tiles in that direction, its just getting the map to loop perfectly for each direction, at the moment on certain directions it has gaps or overlaps the tiles.

Any ideas what i am missing here...

the basic tiles are set up with
For y = -1 To Int(game.deskheight / ImageHeight(Ttile.tileimg)) + 1
	For x = -1 To Int(game.deskwidth / ImageWidth(Ttile.tileimg)) + 1
		Ttile.Create(x*ImageWidth(Ttile.tileimg),y*ImageHeight(Ttile.tileimg)) 
	Next
Next


1 extra tile all around the screen to allow for smooth scrolling and no missing blips....

so in principle once working should work for any sized tile...

thanks..
Ian