need help at Eachin :-(

BlitzMax Forums/BlitzMax Beginners Area/need help at Eachin :-(

Jolly(Posted 2007) [#1]
hello,

finaly i found some time to test bmax.
before i used b+, but as i must see lots changed.

so here some code that doesn't work as i thought it would.

Incbin "player1.png"
Incbin "player2.png"

Graphics 640,480,,2

Global Anim1 = LoadAnimImage("incbin::player1.png",48,64,0,10)
Global Anim2 = LoadAnimImage("incbin::player2.png",48,64,0,10)

Type AniFig
Field Frame
Field X
Field Y
Field Speed
Field GFX
Field Timer1
Field Name$
Field RandomCase
Field Direction
Field Steps
Field PathX1
Field PathY1
Field PathX2
Field PathY2
End Type

Global Fig:AniFig

Fig = New Anifig
Fig.X = 150
Fig.Y = 370
Fig.Frame = 0
Fig.Speed = 50
Fig.GFX = Anim1
Fig.Timer1 = MilliSecs()
Fig.Name$ = "Heidi"
'SeedRnd MilliSecs()
Fig.RandomCase = Rnd(0,10000)
Fig.Direction = 1
Fig.Steps = 0
MidHandleImage Fig.GFX
Fig.PathX1=100
Fig.PathY1=32+Fig.Y
Fig.PathX2=400
Fig.PathY2=32+Fig.Y
'Delay 235

Fig = New Anifig
Fig.X = 350
Fig.Y = 290
Fig.Frame = 0
Fig.Speed = 100
Fig.GFX = Anim2
Fig.Timer1 = MilliSecs()
Fig.Name$ = "Jolly"
SeedRnd MilliSecs()
Fig.RandomCase = Rnd(0,10000)
Fig.Direction = 1
Fig.Steps = 0
MidHandleImage Fig.GFX
Fig.PathX1=200
Fig.PathY1=32+Fig.Y
Fig.PathX2=600
Fig.PathY2=32+Fig.Y

MainLoop()

Function MainLoop()
SetClsColor 255,200,10
While Not KeyHit(27)
Cls
Animate()
Flip
Wend
End Function

Function Animate()
For Fig:Anifig = EachIn AniFig
SetColor 0,0,0

DrawText Fig.Name,Fig.X,Fig.Y - 33

SetColor 255,0,0
DrawLine Fig.PathX1,Fig.PathY1,Fig.PathX1,Fig.PathY2-30
DrawLine Fig.PathX2,Fig.PathY1,Fig.PathX2,Fig.PathY2-30
DrawLine Fig.PathX1,Fig.PathY1,Fig.PathX2,Fig.PathY2
SetColor 255,255,255

If fig.Direction = 1 Then SetScale(1,1)
If fig.Direction = 0 Then SetScale(-1,1)

'SetRotation(180)
DrawImage(Fig.GFX,Fig.X,Fig.Y,Fig.Frame)
SetRotation(0)
SetScale(1,1)

If Fig.Frame = 7 Then Fig.Frame = 0
If MilliSecs() > Fig.Timer1 + Fig.Speed Then
If Fig.X >= Fig.PathX2-12 Then
Fig.Direction = 0
End If
If Fig.X <= Fig.PathX1+12 Then
Fig.Direction = 1
End If
If Fig.Direction = 1 Then
Fig.X = Fig.X + 5
End If
If Fig.Direction = 0 Then
Fig.X = Fig.X - 5
End If
Fig.Steps = Fig.Steps +1
Fig.Frame = Fig.Frame +1
If Fig.Frame = 4 Then Fig.Frame = 5
Fig.Timer1 = MilliSecs()
End If
Next
End Function

can someone tell me please whats wrong in the line

For Fig:Anifig = EachIn AniFig

thanks


rdodson41(Posted 2007) [#2]
In BlitzMax user-defined types don't have they're own hidden list to keep track of them, you have to make one yourself. So what you can do is somewhere near the top create a list to use to keep track of all your objects:

Global anifig_list:TList = CreateList()


Then, whenever you create a new AniFig, you just add it to the list:

Local Fig:AniFig = New AniFig
ListAddLast(anifig_list, Fig)


To cycle through each AniFig you use EachIn on the list:

For Local Fig:AniFig = EachIn anifig_list


And there you go! Hope it helps!


Jolly(Posted 2007) [#3]
thank you so much...
now i got it ... well this one ... :-))


Perturbatio(Posted 2007) [#4]
can I suggest holding the list inside the type?
And maybe moving the animate function inside it as well.



You can then instantiate a AniFig type with
Global fig1:AnimFig = AniFig.Create(350, 290, 50, Anim1, "Heidi", 100, 32, 400 ,32) 

And it will have all the default fields set for it.

To animate:
Anifig.Animate()

And to loop through the type list (if you haven't spotted it in the animate function).

For Local fig:Anifig = Eachin AniFig.list


Note that the above code is untested, but the principle is there.


Jolly(Posted 2007) [#5]
thank you, i was busy the last time. i will test it as soon as possible.

i thought that blitz max would be es easy as blitz plus...but there is a long way for me to find out how i can use it :-))


Beaker(Posted 2007) [#6]
Look here:
http://www.blitzbasic.com/Community/posts.php?topic=50285