Dec-07-2020, 12:02 PM
Hi I'm trying to make a basic alien invasion game but when I try to load a ship image into the midbottom of the game screen I get an error. Here is the code I'm using to create the ship:
class Ship: """A class to manage the ship.""" def __init__(self, ai_game): """Initialise the ship and its starting position.""" self.screen = ai_game.screen self.screen_rect = ai_game.screen.get_rect() # Load the ship image and get its rect. self.image = pygame.image.load(r'C:\Users\djwil\Documents\python\python crash course\Projects\Alien invasion\Images\ship.bmp') self.rect = self.image.get_rect # Start each new ship at the bottom of the screen. self.rect.midbottom = self.screen_rect.midbottom def blitme(self): """Draw the ship at its current location.""" self.screen.blit(self.image, self.rect)I'm then getting this error
Error: File "c:\Users\djwil\Documents\python\python crash course\Projects\Alien invasion\alien_invasion.py", line 41, in <module>
ai = AlienInvasion()
File "c:\Users\djwil\Documents\python\python crash course\Projects\Alien invasion\alien_invasion.py", line 22, in __init__
self.ship = Ship(self)
File "c:\Users\djwil\Documents\python\python crash course\Projects\Alien invasion\ship.py", line 15, in __init__
self.rect.midbottom = self.screen_rect.midbottom
AttributeError: 'builtin_function_or_method' object has no attribute 'midbottom'
But when I looked online at pygame tutorials it says that midbottom should be a built in attribute. Can someone help me with this please?