After I typed all the codes from the Session 2 Chapter 'Game project – Alien invasion', I tried to run the program but the Python Shell alerted me that couldn't open the image 'images/ship.bmp'. Could you check what's wrong with my program? Thanks for your help! (The situation and the ship.py is as per attached doc. )
error
.docx
Download DOCX • 260KB
As the main program cannot find the file "ship.bmp". You should place all the related game programs and a folder named "images" in a same folder for running the program. Please try again.
I have tried to put them in a same file. However, the game is still not working. I just noticed a folder called "__pycache__" appeared automatically and there were two files which are named as "Settings.cpython-37" and "ship.cpython-37". Am I on the right direction? Thanks for your help!
The folder "__pycache__" is created by Python itself for compiling python program. Python will created some files with extension pyc on that folder. It is a normal process. Please post the error messages here when you run the program for my reference.
The error messages are:
Traceback (most recent call last):
File "C:\Users\Law\Desktop\Pygame\main.py", line 42, in <module>
run_game()
File "C:\Users\Law\Desktop\Pygame\main.py", line 19, in run_game
ship = Ship(screen)
File "C:\Users\Law\Desktop\Pygame\ship.py", line 10, in __init__
self.image = pygame.image.load('images/ship.bmp')
pygame.error: Couldn't open images/ship.bmp
Please place all python programs in the same folder. Then create a folder named "images" under the same folder, save the image file named ship.bmp there. The provided materials include the image folder and the ship.bmp.