Now position that ‘placemat’ rectangle. The y position is the up/down vertical and the x position is the left/right horizontal.
self.rect.bottom = y
self.rect.centerx = x
When we code the speed of the projectiles, we have to keep direction in mind. In Python, when a sprite moves from the top of the screen to the bottom, it is a positive value. Since our hero aims the projectiles upward (from bottom to top) we must use anegative value.
self.speedy = -10
Our game should update whenever our projectiles move positions during gameplay so they look like they’re moving in real time.
self.rect.y += self.speedy
We should also let the game know when a projectile misses an enemy and continues offscreen by using anif conditional statement. To get rid ofobjectsin Python we use afunctioncalled kill(). This will delete the projectiles that veer offscreen.
if self.rect.bottom < 0:
Conditionals are ‘if’ statements that compare two values to see if it’s true. If statements always have a : at the end.
Functionsare packets of code that do a certain task and are always followed by ( ). The function we use here is self.kill() used to remove projectiles from the screen.