import sys
import pygame
pygame.init()
screen_width, screen_height = 800, 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("少帅下飞机")
plane_image = pygame.image.load("plane.jpeg")
plane_image = pygame.transform.scale(plane_image, (200, 100))
shaoshuai_image = pygame.image.load("shaoshuai.png")
shaoshuai_image = pygame.transform.scale(shaoshuai_image, (50, 50))
guard_image = pygame.image.load("bing.png")
guard_image = pygame.transform.scale(guard_image, (60, 60))
pifeng_image = pygame.image.load("pifeng.png")
pifeng_image = pygame.transform.scale(pifeng_image, (50, 60))
plane_x, plane_y = 0, 0
target_x = (screen_width - plane_image.get_width()) // 2
target_y = (screen_height - plane_image.get_height()) // 2
shaoshuai_x = (screen_width - shaoshuai_image.get_width()) // 2
shaoshuai_y = (screen_height - shaoshuai_image.get_height()) // 2
guard_left_x = -guard_image.get_width()
guard_right_x = screen_width
guard_target_left_x = shaoshuai_x - guard_image.get_width() - 10
guard_target_right_x = shaoshuai_x + shaoshuai_image.get_width() + 10
guard_y = shaoshuai_y
speed = 1
guard_speed = 3
down_speed = 1
clock = pygame.time.Clock()
show_shaoshuai = False
move_down = False
guards_moving = True
show_pifeng = False
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screen.fill((255, 255, 255))
if not show_shaoshuai:
if plane_x < target_x:
plane_x += speed
if plane_y < target_y:
plane_y += speed
if plane_x >= target_x and plane_y >= target_y:
show_shaoshuai = True
screen.blit(plane_image, (plane_x, plane_y))
else:
screen.blit(shaoshuai_image, (shaoshuai_x, shaoshuai_y))
if guards_moving:
if guard_left_x < guard_target_left_x:
guard_left_x += guard_speed
if guard_right_x > guard_target_right_x:
guard_right_x -= guard_speed
if guard_left_x >= guard_target_left_x and guard_right_x <= guard_target_right_x:
guards_moving = False
move_down = True
show_pifeng = True
screen.blit(guard_image, (guard_left_x, guard_y))
screen.blit(guard_image, (guard_right_x, guard_y))
if show_pifeng:
pifeng_x = shaoshuai_x + (shaoshuai_image.get_width() - pifeng_image.get_width()) // 2
pifeng_y = shaoshuai_y - pifeng_image.get_height() - 10
screen.blit(pifeng_image, (pifeng_x, pifeng_y))
if move_down:
shaoshuai_y += down_speed
guard_y += down_speed
screen.blit(shaoshuai_image, (shaoshuai_x, shaoshuai_y))
screen.blit(guard_image, (guard_left_x, guard_y))
screen.blit(guard_image, (guard_right_x, guard_y))
pifeng_x = shaoshuai_x + (shaoshuai_image.get_width() - pifeng_image.get_width()) // 2
pifeng_y = shaoshuai_y - pifeng_image.get_height() - 10
screen.blit(pifeng_image, (pifeng_x, pifeng_y))
if shaoshuai_y > screen_height + 100:
move_down = False
pygame.display.flip()
clock.tick(60)