pygame复习,用pygame画一个白色背景,里面放一个以白色为背景的飞机

#ship.py
import pygame

class Ship():
    def __init__(self,screen):
        self.image = pygame.image.load('ship4.bmp')
        self.rect = self.image.get_rect()
        self.screen = screen
        self.screen_rect = screen.get_rect()

        self.rect.centerx = self.screen_rect.centerx
        self.rect.bottom  = self.screen_rect.bottom

    def blitme(self):
        self.screen.blit(self.image,self.rect)
#settings.py
class Settings():
    def __init__(self):
        self.color = (255,255,255)
        self.caption = "alien ship"
        self.width = 1000
        self.height =800
#game_functions.py
import pygame
import sys
def check_events():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
'''
def update(screen,ship,settings):
    screen.fill(settings.color)
    screen.blit(ship.image,ship.rect)
    pygame.display.flip()
'''
def update(screen,ship,settings):
    screen.fill(settings.color)
    ship.blitme()
    pygame.display.flip()

#game.py
import pygame
from settings import Settings
from ship     import Ship
import game_functions as up
def run_game():
    my_set = Settings()
    pygame.init()
    screen = pygame.display.set_mode((my_set.width,my_set.height))
    my_ship = Ship(screen)
    pygame.display.set_caption(my_set.caption)
    while True:
        up.check_events()
        up.update(screen,my_ship,my_set)

run_game()

白色背景飞机网上不难找到,再转换成位图(.bmp后缀的图)即可。

ubuntu 20.04下执行,

python3 game.py

运行结果: 

pygame复习,用pygame画一个白色背景,里面放一个以白色为背景的飞机_第1张图片

 

你可能感兴趣的:(python3)