16 Feb Aurora Saturday 13:00 Python Practice 02.13.
Modify the program we made in the class to:
- Create Missile class
- Add one missile to your program
- missile will automatically move from your spaceship to the top of the screen
- once missile reach the top of the screen, it will re-appear from the location of your fighter
- speed has two values in the (), the first value is how fast it could move horizontally while the second value is how fast it could move vertically. Think: Does missile move horizontally?
- Think: how to move missile vertically and test if it reaches out the top of the screen?
- exam the code of move method in the Enemy class and find out the logic of its movement. It does not need any extra arguments since the movement of the enemy is automatically base on the x,y speed. But once missile reach the top of the screen, it will re-appear from the location of your fighter. So the move method of Missile class may need a argument tell the location of the fighter and you can assign the fighter’s location to the the missile’s location like this:
self.rect = location (when the missile reach out the top of the screen)
- so far we could consider xxxxx.rect represents for the location, such as myFighter.rect is the location of object myFighter. We could pass the value of myFighter.rect as arguments into to the move method of Missile class.
You can download all the necessary images from below: