import sys
import pygame
from settings import Settings
def run_game():
#初始化游戏并创建一个屏幕对象
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))
#窗口标题
pygame.display.set_caption("Alien Invasion")
#设置背景色,红绿蓝,0~255,可创建1600万种颜色,这里设置的是浅灰色
bg_color = (230,230,230)
#开始游戏的主循环
while True:
#监视键盘和鼠标事件
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
#每次循环时都重绘屏幕
screen.fill(ai_settings.bg_color)
pygame.display.flip()
run_game()
settings.py里面的内容:
class Settings():
"""存储这个游戏的所有设置的类"""
def _init_(self):
"""初始化游戏的设置"""
#屏幕设置
self.screen_width = 1200
self.screen_height = 800
self.bg_color = (230,230,230)