Board Thread:Program Announcements/@comment-24860891-20150508132309/@comment-24860891-20150511015830

My system is much faster.

It has an array that is the size of the screen, which is used when you need to check if there is a particle under something, or next to something, for example.

In the array, each number stands for a unique particle ID.

There are 3 more arrays (currently), Particle type, X, and Y.

For example:

main array (pretend the screen is 3x3):

001

023

000

type array (1=powder, 2=solid):

1

2

2

X and Y

2, 0

1, 1

2, 1

So, particle #1 is a powder, and is located at 2,0

This may seem overcomplicated, but it is actually a lot faster, since you don't need to check every spot on the screen, only the ones listed in the type list array.

For example, here's how the code is layed out:

@mainloop

For particle=1 to 8

if type(particle)==1 then gosub @powder

if type(particle)==2 then gosub @solid

next

goto @mainloop

@powder

If !main(x(particle),y(particle)+1) then main(x(particle),y(particle))=0:main(x(particle),y(particle)+1)=1:y(particle)=y(particle)+1 'If the space under is empty, move the particle down 1 space and update the main array and x and y lists

return

(of course, the code is actually a lot more complex than this!)

The advantages:

Less huge arrays

Much faster (each particle is 1x1 pixel, and the simulation area fills the whole screen. for low amounts of particles, it runs really fast)

When a particle moves, it is still the "same" particle (same position in the list)

Disadvantages:

longer code

harder to program (can get confusing at times)