viewtopic.php?f=15&p=243529#p243529
"Note: I don't fancy, the use of "shared" var's., unless absolutely required."
Although I haven't written many OO programs it seems to me that a programmer should at least know how to do OOP and as far as I know it helps remove shared variables?
This is an attempt at a "particle" object. However I am unsure as to how to implement new to create particles when say the left mouse button is down and delete particles when they have "lived" a certain length of time or some other end of life event occurs?
Code: Select all
const SCRW = 640
const SCRH = 480
const MAXP = 100 'number of particles
screenres SCRW,SCRH,32
color rgb(0,0,0),rgb(255,255,255):cls
type PARTICLE
Public:
as integer x
as integer y
as integer xd
as integer yd
as ulong c
as integer alive
Public:
declare sub drawParticle()
declare sub moveParticle()
Declare Constructor()
Declare Constructor(x As Integer, y As Integer, xd as integer, yd as integer, c As ulong)
end type
sub PARTICLE.drawParticle()
if this.alive > 0 then
circle (this.x,this.y),3,this.c,,,,f
end if
end sub
sub PARTICLE.moveParticle()
this.x = this.x + this.xd
this.y = this.y + this.yd
' if this.x < 0 or this.x > SCRW then this.xd = -this.xd
' if this.y < 0 or this.y > SCRH then this.yd = -this.yd
if this.x < 0 or this.x > SCRW then this.alive = 0
if this.y < 0 or this.y > SCRH then this.alive = 0
end sub
Constructor PARTICLE ()
End Constructor
Constructor PARTICLE (xx As Integer, yy As Integer, xd as integer, yd as integer, cc As ulong)
this.x = xx
this.y = yy
this.xd = xd
this.yd = yd
this.c = cc
this.alive = 255
End Constructor
dim shared as PARTICLE p(1 to MAXP) 'create particle array list
'initialize values
for i as integer = 1 to MAXP
p(i) = Particle( int(rnd(1)*SCRW), int(rnd(1)*SCRH), int(rnd(1)*3)-1, int(rnd(1)*3)-1,_
rgb( int(rnd(1)*256), int(rnd(1)*256), int(rnd(1)*256) ) )
next i
sub update()
screenlock
cls
for i as integer = 1 to MAXP
p(i).drawParticle
p(i).moveParticle
next i
screenunlock
end sub
do
update()
sleep 2
loop until multikey(&H01)