I'm would like to build a simple modeling analysis tool, but for this question I'll put it in simple terms.

Imagine you have two round balls on the screen. I would like to find a way to have each ball control itself. Where if it hits a wall, then it bounces back accordingly.

I was thinking if there is a way I can create a single routine for a single ball, that monitors it's self in some way (sort of a AI). Then I could spawn more of these balls, and they would just keep track of them selves, rather than having a routine that cycles through all on screen balls updating each on independently.

Sorry if I'm not explaining myself correctly, I hope someone might know what I'm talking about.