When I run the code my image doesn't show up. It doesn't give any error, but when i hover in the new page that i created from taskbar I can see the blink of image for a second and then it doesn't stay in the main page again. What is wrong? Please help me.
import pygame
class Ship:
"""A class to manage the ship."""
def __init__(self,ai_game):
"""Initialize the ship and set 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('images/ship.bmp')
self.rect = self.image.get_rect
#Start each new ship at the bottom center of the screen.
self.rect.midbottom = self.screen_rect.midbottom
def blitme(self):
"""Draw the ship at it's current location."""
self.screen.blit(self.image,self.rect)
my main file:
import sys
import pygame
from setting import Settings
from ship import Ship
class AlienInvasion:
"""Overall class to manage game assets and behaviour."""
def __init__(self):
"""Initialize the game, and create game resources."""
pygame.init()
self.screen = Settings()
self.screen = pygame.display.set_mode(self.settings.screen_width,self.settings.screen_height)
pygame.display.set_caption("Alien Invasion")
self.ship = Ship(self)
#set the background color.
self.bg_color = (230,230,230)
def run_game(self):
"""Start the main loop for the game."""
while True:
#watch for keyboard and mouse events.
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
#Redraw the screen during each pass through the loop.
self.screen.fill(self.settings.bg_color)
self.ship.blitme()
#make the most recently drawn screen visible.
pygame.display.flip()
if __name__ == '__main__':
#make a game instance,and run the game.
ai = AlienInvasion()
ai.run_game()
I have checked my directory and files they are in the right place everything seems to be right to me but still code doesn't work.
My directories looks like;
PycharmProjects:
alien invasion:
images:
ship.bmp
alien_invasion.py
setting.py
ship.py