TORONTO KIDS COMPUTER CLUB | Aurora Monday 18:30 Python Homework 21.07.12.
19714
post-template-default,single,single-post,postid-19714,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Aurora Monday 18:30 Python Homework 21.07.12.

16 Jul Aurora Monday 18:30 Python Homework 21.07.12.

Question:
Modify the program we made in the class to:

  • Create Missile class
  • Add missiles group to your program
  • Missile object will be created when you click the mouse and added into the missiles group
  • Each missile will move from your spaceship to the top of the screen
  • In the update() method of Missile class, once missile reach the top of the screen, use self.kill() to automatically remove the missile from the missiles group

Hint:

  • When you click the the mouse, you could create a missile object and add it into the missiles group, however you may need a counter to make sure it will not be created too fast.(otherwise it may create 30 missiles per second)
  • You can use True in pygame.mouse.get_pressed()  to check if you click down the mouse
  • When you create the missile object, you need the location for the missile object. It will be the fighter.rect.centerx and fighter.rect.top location
  • 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 update 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 use self.kill() to delete and remove the missile from the missiles group.
No Comments

Sorry, the comment form is closed at this time.