def runGame(): 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) ship = Ship(ai_settings, screen) alien = Alien(ai_settings, screen) bullets = Group() aliens = Group() gf.create_fleet(ai_settings, screen, ship, aliens) 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, screen, ship, sb, aliens, bullets) gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def run_game(): pygame.init() setting = Setting() screen = pygame.display.set_mode( (setting.screen_width, setting.screen_heigth)) screen.fill(setting.screen_bg_color) pygame.display.set_caption("Aliens fight with ship(%s)" % time.ctime()) play_button = Button(screen, setting, "START") ship = Ship(screen, setting) bullets = Group() aliens = Group() stats = Gamestats(setting) scoreB = ScoreBoard(screen, setting, stats) high_score = HighScore(screen, setting, stats) gamefunction.alien_fleet_creat(screen, setting, ship, aliens) while True: # for event in pygame.event.get(): # if event.type == pygame.QUIT: # sys.exit() gamefunction.check_key(setting, screen, stats, ship, bullets, play_button) pygame.display.set_caption("Aliens fight with ship(%s)" % time.ctime()) if stats.game_active: ship.update() gamefunction.update_bullets(screen, setting, ship, bullets, aliens, stats, scoreB) gamefunction.update_aliens(screen, setting, stats, scoreB, ship, bullets, aliens) gamefunction.update_screen(screen, setting, stats, ship, bullets, aliens, play_button, scoreB, high_score)
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') #创建Play按钮 play__button = Button(ai_settings, screen, 'Play') #创建一个用于存储游戏统计信息的实例,并创建记分牌 stats = Gamestats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) #创建一艘飞船,一个子弹编组和一个外星人编组 ship = Ship(ai_settings, screen) bullets = Group() aliens = Group() #创建外星人群 gf.create_fleet(ai_settings, screen, ship, aliens) #开始游戏主循环 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)
def run_game(): #初始化游戏并创建一个游戏对象 pygame.init() #初始化背景设置 pygame.display.set_caption('alien_invasion') #创建标题 ai_set = Settings() #设置的类 screen = pygame.display.set_mode( (ai_set.screen_width, ai_set.screen_height)) #设置游戏窗口的大小 play_button = Button(ai_set, screen, 'Play') #创建一个按钮 ship = Ship(screen, ai_set) #创建一个飞船 bullets = Group() #创建一个子弹组 aliens = Group() #创建外星人组 stats = Gamestats(ai_set) gf.create_fleet(screen, ai_set, aliens, ship) #创建外星人群 #开始游戏主循环 while True: #监视键盘和鼠标事件 gf.check_event(ship, ai_set, bullets, screen, stats, play_button, aliens) if stats.game_active: ship.moving() #飞船的移动 gf.update_bullet(bullets) #子弹的移动 gf.update_aliens(aliens, ai_set) #外星人的移动 gf.collision_event(screen, bullets, aliens, ship, ai_set, stats) #屏幕刷新 gf.update_screen(ai_set, screen, ship, bullets, aliens, play_button, stats)
def play(self): self.screen.fill((0, 0, 0)) stats = Gamestats(self.screen) maze = Maze(self.screen, 'images/maze2.txt', stats, self.Clock) anim = maze.create_menu() while True: if stats.game_status == 0: maze.show_menu(anim) if stats.game_status == 1: maze.update() self.Clock.tick(stats.game_speed) pygame.display.flip()
def main(): #starting the game and setting up variables for classes imported to main pygame.init() ai_settings=Settings() screen=pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height)) ironman=Ironman(ai_settings,screen) ultron=Ultron(ai_settings, screen,ironman) stats = Gamestats(ai_settings) sb=Scoreboard(ai_settings,screen,stats) # play music as long as the game is being played music=Music("theme.mp3.mp3",7,0) #setting up the group bullets=Group() ultrons=Group() missiles=Group() #naming the game pygame.display.set_caption("ultron invasion") #displaying background image and drawing it on screen background=pygame.transform.scale(pygame.image.load("background.bmp"),(ai_settings.screen_width,ai_settings.screen_height)) bgrect=background.get_rect() #drawing the start button for the game play_button = Button(ai_settings, screen, "suit-up") #keeping the game looping and running using the while loop while True: gf.check_events(ai_settings,screen,stats,sb,play_button,ironman,ultrons,bullets,music) if stats.game_active: #update the screen ironman.update() bullets.update() gf.update_ultrons(ai_settings,screen,stats,sb,ironman,ultrons,bullets,missiles) gf.update_missiles_ironman_collison(ai_settings,screen,stats,sb,ironman,ultrons,bullets,missiles) gf.update_bullets(ai_settings,screen,stats,sb,ironman,ultrons,bullets) gf.update_missile(ai_settings,screen,stats,sb,ironman,ultrons,missiles) gf.update_screen(ai_settings, screen, stats,sb,ironman,ultrons,background,bgrect,bullets,play_button,missiles)
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("Fish") fish = Fish(ai_settings, screen) mines = Mines(ai_settings, screen) stats = Gamestats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) miness = Group() gf.create_fleet(ai_settings, screen, miness) play_button = Button(ai_settings, screen, "Play") pygame.mouse.set_visible(True) while True: gf.check_events(ai_settings, screen, stats, sb, play_button, fish, miness) gf.update_screen(ai_settings, screen, stats, sb, fish, mines, miness, play_button) if stats.game_active: fish.update() gf.update_miness(ai_settings, stats, sb, screen, fish, miness)
def run_game(): pygame.init() ssettings=Settings() screen=pygame.display.set_mode((ssettings.screen_width,ssettings.screen_height)) stat=Gamestats(ssettings) body=[] body.append(Snake(screen)) play_button=Button(screen,ssettings,"Play!") foods=Group() pygame.display.set_caption("Snake") while True: screen.fill(ssettings.bgcolor) if not stat.game_active: play_button.draw_button() reset(body,screen) check_events(body,stat,play_button,screen) update_screen(body,stat,ssettings,screen,foods)
def runGame(): pygame.init() settings = Settings() screen = pygame.display.set_mode( (settings.screenWidth, settings.screenHegiht)) pygame.display.set_caption(settings.gameName) interval = 1.0 / (settings.frame * 2) nextTime = time.time() + interval #创建开始按钮 playButton = Button(settings, screen, "Play") gs = Gamestats(settings) #创建贪吃蛇 snake = Snake(settings, screen) #食物管理器 foodManager = FoodManager(settings, screen) while True: if time.time() < nextTime: continue nextTime = time.time() + interval gf.checkEvent(settings, screen, gs, snake, foodManager, playButton) #游戏进行中 if gs.gameActive: snake.update() gf.updateFoods(settings, snake, foodManager) else: pass gf.updateScreen(settings, screen, gs, snake, foodManager, playButton)