《Python编程:从入门到实践》里的打飞机小游戏。
Python做游戏比预想中要简单。
不太完善,不过也算是不错的模板。
主程序
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("外星人入侵")
play_button = Button(ai_settings, screen, "Play")
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
gf.create_fleet(ai_settings, screen, ship, aliens)
stats = GameStats(ai_settings)
sb = Scoreboard(ai_settings, screen, stats)
while True:
gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)
if stats.game_active:
ship.update()
gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)
gf.update_aliens(ai_settings, stats, sb, screen, ship, aliens, bullets)
gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
Commits
https://github.com/prufeng/alien-invasion
- Show ship left
- Show level
- Show high score
- Show score
- Add Speed Level
- Add Play Button
- Quit the game
- Shoot aliens
- Move aliens
- Add a group of aliens
- Add alien
- Add bullet and fire bullet
- Add ship and move right/left
- Create alien_invasion.py
- Initial commit
|