I was going to start another thread but I'm
going to use this one for simple questions,
anyone is welcome to do the same here...
Ok, I'm trying to get the bm language,
I made this simple code, you can run it,
Strict
Graphics 640,480,0
HideMouse
'-----------------------------------------------------------
'-----------------------------------------------------------
'rectangles objects
Global listall:TList=CreateList()
Type rects
Field px,py,red,green,blue,lifetime,velx,vely
Field alpha#
Field sizeX,sizeY
Function create_rect()
Local r:rects=New rects
r.px=MouseX()+Rand(-640,640)
r.py=MouseY()+Rand(-480,480)
r.sizeX=Rand(150,300)
r.sizeY=Rand(150,300)
r.velx=Rand(-2,2)
r.vely=Rand(-2,2)
r.red=Rand(20,255)
r.green=Rand(20,255)
r.blue=Rand(20,255)
r.alpha=Rnd(.25,.9)
r.lifetime=Rand(30,120)
ListAddLast listall,r
End Function
Function update_each()
Local alpha#
Local mouse_tendX,mouse_tendY
SetBlend alphaBlend
For Local r:rects=EachIn listall
r.alpha:-.01
SetAlpha r.alpha
SetColor r.red,r.green,r.blue
r.px:+r.velx
r.py:+r.vely
r.sizeX:+(-r.sizeX)/20
r.sizeY:+(-r.sizeY)/20
mouse_tendX=(MouseX()-r.px)/20
r.px:+mouse_tendX
mouse_tendY=(MouseY()-r.py)/20
r.py:+mouse_tendY
DrawRect r.px,r.py,r.sizeX,r.sizeY
r.lifetime:-1
If r.lifetime<1
ListRemove listall,r
'?????
EndIf
Next
SetBlend solidBlend
SetAlpha 1
End Function
End Type
'-----------------------------------------------------------
'-----------------------------------------------------------
While Not KeyDown(key_escape)
Cls
If KeyDown(key_space)
rects.create_rect()
EndIf
rects.update_each()
SetColor 0,0,255
DrawOval MouseX()-3,MouseY()-3,6,6
SetColor 255,255,255
DrawText "hold Space and move the mouse",10,10
DrawText MemUsage()+":mem usage | "+CountList(listall)+":elements",10,30
FlushMem;Flip
Wend
EndGraphics()
End
1) As you can see, there is a global list ("listall")
Is it there any way to scan all the elements without
having a list? and in case there is not, how could I
eliminate that global variable? Can I have a variable holding
a list inside the Type itself?
2)When the field "lifetime" is cero, I want to delete the object,
I want to completely free it and I can't find how (it was the
"Delete" command in B3D)
Thanks!
Paolo.