Steering behaviours and line between function

Finally, I learnt a behavioural function called ‘lineBetween’ which works with if statements and executes a visual behaviour if the class instance does a certain thing.

‘line between’ literally does what it says on the tin. It creates a line between the class instances. It goes with in the ‘void run’ function and then you create its own ‘void lineBetween’ where this section of code goes

for (int i = 0; i <ballCollection.size(); i++) {
Ball other = (Ball) ballCollection.get(i);
float distance = loc.distanceTo(other.loc);
if (distance > 0 && distance < 80) {
 line(loc.x, loc.y, other.loc.x, other.loc.y);

This part of the code states that if the distance between the instances of the class are more than 0 and less than 80 connect them with a white line that has a weight of 0.4.

Which looks like this –

I played around with colours and speeds and changing the distance of when the lines will appear.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s