H a n d s o n, p r o j e c t b a s e d


Download 4.21 Mb.
Pdf ko'rish
bet204/344
Sana31.01.2024
Hajmi4.21 Mb.
#1818553
1   ...   200   201   202   203   204   205   206   207   ...   344
Bog'liq
Python Crash Course, 2nd Edition

Adding the Ship Image
Let’s add the ship to our game. To draw the player’s ship on the screen
we’ll load an image and then use the Pygame 
blit()
method to draw the 
image.
When you’re choosing artwork for your games, be sure to pay attention to 
licensing. The safest and cheapest way to start is to use freely licensed graph­
ics that you can use and modify, from a website like https://pixabay.com/.
You can use almost any type of image file in your game, but it’s easiest 
when you use a bitmap (.bmp) file because Pygame loads bitmaps by default. 
Although you can configure Pygame to use other file types, some file types 
alien_invasion.py


A Ship that Fires Bullets
233
depend on certain image libraries that must be installed on your computer. 
Most images you’ll find are in .jpg or .png formats, but you can convert them 
to bitmaps using tools like Photoshop, GIMP, and Paint.
Pay particular attention to the background color in your chosen image. 
Try to find a file with a transparent or solid background that you can replace 
with any background color using an image editor. Your games will look 
best if the image’s background color matches your game’s background 
color. Alternatively, you can match your game’s background to the image’s 
background.
For Alien Invasion, you can use the file ship.bmp (Figure 12­1), which is 
available in the book’s resources at https://nostarch.com/pythoncrashcourse2e/
The file’s background color matches the settings we’re using in this project. 
Make a folder called images inside your main alien_invasion project folder. 
Save the file ship.bmp in the images folder.
Figure 12-1: The ship for Alien Invasion

Download 4.21 Mb.

Do'stlaringiz bilan baham:
1   ...   200   201   202   203   204   205   206   207   ...   344




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling