Skip to content
Advertisement

Is there a way to make a object follow another object?

So, I have been working on a project for a very basic Space Invaders. But, I can’t seem to get the Bullet (see code) class to follow the Jet class(see code):

JavaScript

I have already searched some websites (and yours, too) and couldn’t find anything. Do I have any way to make the classes follow each other?

Advertisement

Answer

You could do it by changing Bullet.draw() to accept an x argument, and pass it the jet object’s x in the loop.

Note I also modified your code so it follows the PEP 8 – Style Guide for Python Code to make it more readable. Strongly suggest you read and start following it.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement