Oh I love this stuff.
Here, I took the time to make this large example program
for you. It's a bit complex, but if you go through it line
by line, you should learn tons.
When you run it, it looks like psychadelic popcorn.
Here, I took the time to make this large example program
for you. It's a bit complex, but if you go through it line
by line, you should learn tons.
When you run it, it looks like psychadelic popcorn.
Strict Global xScreen = 800 Global yScreen = 600 Global particleNum = 35 Graphics xScreen, yScreen Type particleType 'This is the blueprint for one particle Field x:Float 'x position Field y:Float 'y position Field x1:Float 'x velocity Field y1:Float 'y velocity Rem It's important to note that I made the variables for both velocity and <b>position</b> Float variables. If you make the position variables integers, you'll get 'chunky' movement, if any at all. EndRem Method update() x:+x1 'move the particle by how fast it's going. y:+y1 y1:+.95 'put a constant tug on the Y speed. This is gravity. x1:*.99 'this is what One Eyed Jack was walking about. This simulates air resistance. y1:*.95 Rem The following four lines of code make sure the particles stay on the screen. This is a very simple way of doing it. End Rem If x> xScreen Then x1 = -x1 If y> yScreen Then y1 = -y1 If x< 0 Then x1 = -x1 If y< 0 Then y1 = -y1 If Abs(y1)< 1 And y > 590 Then 'if they slow down too much, shoot them off somehwere fast x1= Rnd(-10,10) y1= -Rnd(40) EndIf End Method Method draw() SetColor x1,y1,200 'this will make crazy colours when they move DrawRect x,y,5,5 End Method End Type Local part:particleType[particleNum+1] 'arrange 300 memory slots for the particles Local a For a = 0 To particleNum 'This puts the blueprint inside each slot we just made... part[a] = New particleType 'it's a necessary step if you're working with Types. part[a].x = Rand(xScreen) 'put them in random starting positions part[a].y = Rand(600) Next Repeat 'this is the actual main loop For a = 0 To particleNum part[a].update part[a].draw Next Flip;Cls;FlushMem Until KeyHit(key_escape)