2D Overhead scrolling maze

BlitzMax Forums/BlitzMax Beginners Area/2D Overhead scrolling maze

maybe you can find a better way to do it.
it's only an example.
use up,down,left,right to move.
'A' and 'S' to rotate

Strict

Global ScreenWidth=800
Global ScreenHeight=600

Graphics ScreenWidth,ScreenHeight,0
SetBlend ALPHABLEND
AutoMidHandle True
Local image:TImage=CreateImage(25,15)
DrawText "(X)",0,0
GrabImage(image,0,0)


SetOrigin ScreenWidth/2,ScreenHeight/2


Global Background:TBackground=New TBackground

'create random 50 blocks/sprites
For Local block:Int=0 To 50
	Local newblock:TBlock=New TBlock
	newblock.ImageRotation=Rand(360)
	'position from background center to sprite position
	newblock.Rotation=Rand(360)
	newblock.Distance=Rand(ScreenHeight)
	Background.Blocks.AddLast(newblock)
Next

Background.UpdateBlockCoords(0,0,0)
While Not KeyHit(KEY_ESCAPE) Or AppTerminate()

	Local update:Int
	'check scroll keys
	If KeyDown(KEY_UP) Then
		Background.UpdateBlockCoords(0,+5,0)
	ElseIf KeyDown(KEY_DOWN) Then
		Background.UpdateBlockCoords(0,-5,0)
	ElseIf KeyDown(KEY_LEFT) Then
		Background.UpdateBlockCoords(+5,0,0)
	ElseIf KeyDown(KEY_RIGHT) Then
		Background.UpdateBlockCoords(-5,0,0)
	EndIf
	'check rotation keys
	If KeyDown(KEY_A) Then
		Background.UpdateBlockCoords(0,0,-1)
	ElseIf KeyDown(KEY_S) Then
		Background.UpdateBlockCoords(0,0,+1)
	EndIf

	Cls
	'draw all blocks
	For Local block:TBlock=EachIn Background.Blocks
		SetRotation block.ImageRotation
		DrawImage image,block.X, block.Y
		SetRotation 0
		SetAlpha 0.3
		DrawLine 0,0,block.X,block.Y
		SetAlpha 1
	Next
	'draw player
	SetColor 255,0,0
	DrawOval -10,-10,21,21
	SetColor 255,255,255
	Flip 1
Wend


'----------------------------------------------------------------
Type TBackground

	Global Blocks:TList=CreateList()

	Method UpdateBlockCoords(x:Float,y:Float,rotation:Float)
		For Local block:TBlock=EachIn Blocks
			block.X=x+Cos(rotation+block.Rotation)*block.Distance
			block.Y=y+Sin(rotation+block.Rotation)*block.Distance
			block.Rotation=ATan2(block.y,block.x)
			block.Distance=Sqr( block.x^2 + block.y^2 )
			block.ImageRotation:+rotation
		Next
	EndMethod

EndType

Type TBlock

	Field X:Float
	Field Y:Float

	Field ImageRotation:Float

	Field Rotation:Float
	Field Distance:Float

EndType