How to initialize CLASS by it's own function?

The method Drop::reachedBottom3() returns a Drop object but you don’t do anything with it.

BtW, the method can be shortened to 1 return statement:

Drop reachedBottom3(final Drop self) {
  return y > height + r? new Drop() : self;
}

You need to reassign the returned Drop object back to the array:
drops[i] = drops[i].reachedBottom3(drops[i]);

However that’s pretty awkward b/c the Drop object should be able to restart by its own w/o the caller having to do anything.

Instead you should define a method that respawn() the Drop’s fields back to their constructor values.

Basically you move anything inside Drop’s constructor to that separate method and invoke it inside the constructor instead.

And within method move() check whether field y has reached the bottom and invoke respawn() if so.

Here’s the refactoring I did to your sketch. Check it out:

Another similar sketch called “Raining Cloud”:
http://Studio.ProcessingTogether.com/sp/pad/export/ro.9l84$2z--gWui

2 Likes