parent
67ea90cd6e
commit
d9a6e36284
@ -0,0 +1,61 @@
|
|||||||
|
import pygame
|
||||||
|
from pygame.sprite import Group
|
||||||
|
|
||||||
|
from settings import Settings
|
||||||
|
from game_stats import GameStats
|
||||||
|
from scoreboard import Scoreboard
|
||||||
|
from button import Button
|
||||||
|
from man import Man
|
||||||
|
import game_functions as gf
|
||||||
|
|
||||||
|
def run_game():
|
||||||
|
# 初始化 pygame, settings, and screen object.
|
||||||
|
pygame.init()
|
||||||
|
ai_settings = Settings()
|
||||||
|
screen = pygame.display.set_mode(
|
||||||
|
(ai_settings.screen_width, ai_settings.screen_height))
|
||||||
|
pygame.display.set_caption("Alien Invasion")
|
||||||
|
|
||||||
|
# 制作开始游戏按钮
|
||||||
|
play_button = Button(ai_settings, screen, "Play")
|
||||||
|
|
||||||
|
# 创建一个实例来存储游戏统计信息和记分板。
|
||||||
|
stats = GameStats(ai_settings)
|
||||||
|
sb = Scoreboard(ai_settings, screen, stats)
|
||||||
|
|
||||||
|
# 设置背景颜色
|
||||||
|
bg_color = (230, 230, 230)
|
||||||
|
|
||||||
|
# Make a ship, a group of bullets, and a group of aliens.
|
||||||
|
man = Man(ai_settings, screen)
|
||||||
|
bullets = Group()
|
||||||
|
bazis = Group()
|
||||||
|
|
||||||
|
# 创造靶子队列
|
||||||
|
gf.create_fleet(ai_settings, screen, man, bazis)
|
||||||
|
|
||||||
|
# 开始游戏的主循环
|
||||||
|
while True:
|
||||||
|
gf.check_events(ai_settings, screen, stats, sb, play_button, man,
|
||||||
|
bazis, bullets)
|
||||||
|
|
||||||
|
if stats.game_active:
|
||||||
|
man.update()
|
||||||
|
gf.update_bullets(ai_settings, screen, stats, sb, man, bazis,
|
||||||
|
bullets)
|
||||||
|
gf.update_bazis(ai_settings, screen, stats, sb, man, bazis,
|
||||||
|
bullets)
|
||||||
|
|
||||||
|
gf.update_screen(ai_settings, screen, stats, sb, man, bazis,
|
||||||
|
bullets, play_button)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
run_game()
|
||||||
|
except SystemExit:
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
# traceback.print_exc()
|
||||||
|
pygame.quit()
|
||||||
|
input()
|
Loading…
Reference in new issue