- 代码
import pygame
import sys
import random# 初始化Pygame
pygame.init()# 设置屏幕尺寸
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("飞行射击游戏")# 定义颜色
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)# 加载飞机图像(你需要自己准备一个飞机图像文件,比如plane.png)
player_image = pygame.image.load('plane.png').convert_alpha()
player_rect = player_image.get_rect()
player_rect.centerx = SCREEN_WIDTH // 2
player_rect.bottom = SCREEN_HEIGHT - 10
player_speed_x = 0# 定义敌人类
class Enemy(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = pygame.Surface([50, 50])
self.image.fill(RED)