赞
踩
alien_invasion.py的代码 import sys import pygame from settings import Settings from ship import Ship from bullet import Bullet class AlienInvasion: '''管理游戏资源并创建游戏资源''' def __init__(self): pygame.init() self.settings = Settings() self.screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN) self.settings.screen_width = self.screen.get_rect().width self.settings.screen_height = self.screen.get_rect().height pygame.display.set_caption("Alien INVASION") self.ship = Ship(self) self.bullets = pygame.sprite.Group() def run_game(self): '''开始游戏的主循环''' while True: self._check_events() self.ship.update() self.bullets.update() self._update_screen() #监视键盘和鼠标事件 for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() self.screen.fill(self.settings.bg_color) self.ship.blitme() #让最近绘制的屏幕可见 pygame.display.flip() def _check_events(self): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。