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 War") 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() f.create_fleet(ai_settings, screen, ship, aliens) # Назначение цвета фона bg_color = (100, 100, 100) alien = Alien(ai_settings, screen) while True: f.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() f.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets) f.update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets) f.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def run_game(): pygame.init() ai_settings = Settings screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) alien = Alien(ai_settings, screen) pygame.display.set_caption("Invasion2.0") 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) # main loop while True: gf.check_events(ai_settings, screen, stats, play_button, ship, aliens, bullets) if stats.game_active: ship.update() gf.update_bullets(ai_settings, screen, ship, aliens, bullets, stats) gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets) gf.update_screen(ai_settings, screen, stats, ship, aliens, bullets, play_button, sb)
def game(): pygame.init() game_settings = settings.Settings() screen = pygame.display.set_mode( (game_settings.width, game_settings.height)) pygame.display.set_caption("Space Invaders") play_button = play.Button(settings, screen, "Play") stats = statistics.GameStats(game_settings) scoreboard = score.Score(game_settings, screen, stats) player_render = ship.Ship(screen, game_settings) bullets = pygame.sprite.Group() alien_group = pygame.sprite.Group() functions.alien_fleet(game_settings, screen, alien_group) while True: functions.check_events(game_settings, screen, player_render, bullets, play_button, stats, alien_group, scoreboard) if stats.game_active: player_render.update() functions.update_bullets(alien_group, bullets, screen, game_settings, scoreboard, stats) functions.update_aliens(game_settings, stats, player_render, alien_group, screen, bullets, scoreboard) functions.update_screen(game_settings, screen, player_render, alien_group, bullets, play_button, stats, scoreboard)
def update(self): self.player.update() functs.update_bullets(self.bullets) functs.update_bullets(self.bullets_enemy) functs.update_enemies(self.enemies) reward = 0 done = False enemies_collision = \ pygame.sprite.groupcollide(self.enemies, self.bullets, True, True) for enemy in enemies_collision: reward += enemy.level player_collision = \ pygame.sprite.spritecollide(self.player, self.bullets_enemy, False) if len(player_collision) > 0: reward -= 100 done = True self.cycle += 1 if self.cycle == 300: self.level += 1 self.cycle = 0 if len(self.enemies) < self.level \ and self.leftColdDownTime <= 0: functs.create_enemy(self.settings, self.screen, self.enemies, self.level, self.bullets_enemy) self.leftColdDownTime = self.coldDownTime - self.level self.leftColdDownTime -= 1 return reward, done
def run(): pygame.init() game_settings = Settings() screen = pygame.display.set_mode( (game_settings.screen_width, game_settings.screen_height)) pygame.display.set_caption("Alien Invasion") play_button = Button(game_settings, screen, "Play") stats = GameStats(game_settings) sb = Scoreboard(game_settings, screen, stats) ship = Ship(game_settings, screen) bullets = Group() aliens = Group() f.create_fleet(game_settings, screen, ship, aliens) while True: f.check_events(game_settings, screen, stats, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() f.update_bullets(game_settings, screen, stats, sb, play_button, ship, aliens, bullets) f.update_aliens(game_settings, stats, sb, screen, ship, aliens, bullets) f.update_screen(game_settings, screen, stats, sb, ship, aliens, bullets, play_button)
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") 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, ship, bullets) ship.update() #bullets.update() gf.update_bullets(bullets) gf.update_aliens(ai_settings, aliens) for bullet in bullets.copy(): if bullet.rect.bottom <= 0: bullets.remove(bullet) #print(len(bullets)) gf.update_screen(ai_settings, screen, ship, aliens, bullets)
def run_game(): """Engine of the game""" # Initialize game and create a screen object. pygame.init() game_set = Settings() screen = pygame.display.set_mode( (game_set.screen_width, game_set.screen_height)) # Setting caption pygame.display.set_caption("Alien Invasion") # An instance to store game statistics and create a scoreboard. stats = GameStats(game_set) sb = Scoreboard(game_set, screen, stats) # Make a ship, a group of bullets, and a group of aliens. ship = Ship(game_set, screen) flag = 0 # Create the fleet of aliens. Timer(0.0, gf.create_alien, [game_set, screen]).start() Timer(8.0, gf.delete_alien, [game_set, screen, ship]).start() # Start the main loop for the game. while True: # Watch for keyboard events. flag = gf.check_events(game_set, screen, ship, stats, flag) # End game check if flag == 1: break # Update condition of bullets and ship ship.update() Bullet_Norm.bullets.update() Bullet_Wait.bullets.update() # Get rid of bullets that have disappeared. gf.update_bullets(game_set, screen, stats, sb, ship) gf.update_screen(game_set, screen, stats, sb, ship) print("Counter : " + (str)(stats.score)) os._exit(0)
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("邓明星大战外星人!") bg_color = ai_settings.bg_color ship = Ship(ai_settings, screen) aliens = Group() bullets = Group() # 创建外星人群 gf.creat_fleet(ai_settings, screen, ship, aliens) # 主循环开始 while True: gf.check_events(ai_settings, screen, ship, bullets) ship.update() gf.update_bullets(ai_settings, screen, ship, aliens, bullets) gf.update_aliens(ai_settings, aliens) gf.update_screen(ai_settings, screen, ship, aliens, bullets)
def run_game(): pygame.init() ai_settings = settings.Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) #screen=pygame.display.set_mode((1200,800)) #bg_color=(200,200,222) pygame.display.set_caption("alien invasion") ship = Ship(ai_settings, screen) play_button = Button(ai_settings, screen, "play") stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) #存储子弹 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, bullets, aliens) if stats.game_active: ship.update() gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets) gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets) #每次循环都重绘屏幕 gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def run_game(): pygame.init() settings = Settings() screen = pygame.display.set_mode( (settings.screen_width, settings.screen_height)) pygame.display.set_caption("Sideways Shooter") shooter = Shooter(settings, screen) bullets = Group() while True: f.check_events_bullet(settings, screen, shooter, bullets) shooter.update() f.update_bullets(bullets, settings) f.update_screen_sprite(settings, screen, shooter, bullets)
def main(): pygame.init() ai_settings = Settings() screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height)) bullets = Group() enemies = Group() enemybullets = Group() enemy = Enemy(ai_settings, screen) stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) play_button = Button(ai_settings, screen, "Play") pygame.display.set_caption("Space Battle") player = Player(ai_settings, screen) bground = pygame.image.load('images/wallhaven-41034.bmp') x = 0 #main loop while True: gf.check_events(ai_settings, screen, stats,sb, play_button, player,enemies, bullets) if stats.game_active: player.update() gf.update_bullets(ai_settings, screen, stats, sb, player, enemies,bullets) gf.update_enemy(ai_settings, screen, stats,sb, player,enemies, bullets) gf.update_screen(ai_settings, screen, stats, sb, player, enemies, bullets, play_button) #moving background screen.fill((0,0,0)) rel_x = x % bground.get_rect().width screen.blit(bground, (rel_x - bground.get_rect().width,0)) if rel_x < ai_settings.screen_width: screen.blit(bground, (rel_x,0)) x -= 3
def run_game(): pygame.init() # Initialize game and create a screen object. game_settings = Settings() # Make it constructor.Make an instance. screen = pygame.display.set_mode( (game_settings.screen_width, game_settings.screen_height)) # Set screen size alien = Alien(game_settings, screen) # Make Alien. pygame.display.set_caption("Alien Shooter") # Make the Play button. play_button = Button(game_settings, screen, "Play") # Make Button. ship = Ship(screen, game_settings) # Make a a ship. stats = GameStats( game_settings) # Create an instance to store game statistics. sb = ScoreBoard(game_settings, screen, stats) bullets = Group() # Make a group of bullets. aliens = Group() # # Make a group of aliens. # Create the fleet of aliens. gf.create_fleet(game_settings, screen, aliens, ship) # Start main loop for the game. while True: # Watch Keyboard and Mouse events. gf.check_events(ship, game_settings, screen, bullets, play_button, stats, aliens, sb) if stats.game_active: ship.update() gf.update_bullets(bullets, aliens, game_settings, screen, ship, stats, sb) # Updating bullets. gf.update_aliens(game_settings, aliens, ship, stats, screen, bullets, sb) # Update aliens. # Updating or loading the screen. gf.update_screen(game_settings, screen, ship, bullets, aliens, play_button, stats, sb)
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_button = Button(screen, "Play", ai_settings.screen_width / 2, 300, 200, 50) reset_button = Button(screen, "Reset", ai_settings.screen_width / 2, 400, 200, 50) high_score_button = Button(screen, "High Score", ai_settings.screen_width / 2, 500, 200, 50) pause_button = Button(screen, "Pause", 160, 30, 100, 40) back_button = Button(screen, "Back", 160, 30, 100, 40) ship = Ship(ai_settings, screen) Alien(ai_settings, screen) bullets = Group() alien_bullets = Group() arches = Group() # Explode(ai_settings, screen) explosio = Group() aliens = Group() # Alien(ai_settings, screen) stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) gf.create_fleet(ai_settings, screen, ship, aliens, arches) while True: gf.check_events(ai_settings, screen, stats, sb, play_button, pause_button, high_score_button, reset_button, back_button, ship, aliens, bullets, arches) if stats.game_active: ship.update() gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets, alien_bullets, explosio, arches) gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets, alien_bullets, arches) gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, alien_bullets, play_button, pause_button, high_score_button, reset_button, back_button, explosio, arches)
def run_game(): # init game and create display object pygame.init() game_settings = Settings() screen = pygame.display.set_mode( (game_settings.screen_width, game_settings.screen_height)) pygame.display.set_caption("Example Game") # create ship ship = Ship(game_settings, screen) bullets = Group() #Create alien group aliens = Group() gf.create_fleet(game_settings, screen, aliens) while True: gf.check_events(game_settings, screen, ship, bullets) ship.update() gf.update_bullets(bullets) #gf.update_aliens(game_settings, alien) gf.update_screen(game_settings, screen, ship, aliens, bullets)
def run_game(): #Initialze and create a screen object pygame.init() ai_set = Settings() screen = pygame.display.set_mode( (ai_set.screen_width, ai_set.screen_height)) pygame.display.set_caption("Alien Invasion") #create the Ship ship = Ship(ai_set, screen) bullets = Group() # setting background color bg_color = (26, 48, 85) while True: fu.check_events(ai_set, screen, ship, bullets) ship.update() fu.update_bullets(bullets, screen) #Redraw screen during each pass of loop fu.update_screen(ai_set, screen, ship, bullets)
def run_game(): # 初始化游戏并创建一个屏幕对象 pygame.init() # 获取配置对象 ai_settings = Settings(); screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height)) print(screen) pygame.display.set_caption(ai_settings.title) # 创建飞船 ship = Ship(ai_settings, screen) # 创建外星人 # alien = Alien(ai_settings, screen) # 创建一个用于存储子弹的组 bullets = Group() aliens = Group() # 创建外星人群 funcs.create_alien_fleet(ai_settings, screen, aliens) #开始游戏主体 while True: funcs.check_events(ai_settings, screen, ship, bullets) # 更新飞船绘制 ship.update() funcs.update_bullets(bullets, aliens) funcs.update_aliens(ai_settings, aliens) # 绘制屏幕 funcs.update_screen(ai_settings, screen, ship, bullets, aliens)
def run_game(): """ Initialize game and create a 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") #Make a ship ship = Ship(ai_settings, screen) #Make a group to store bullets in bullets = Group() aliens = Group() #Make an alien gf.create_fleet(ai_settings, screen, ship, aliens) # Start the main loop for the game. while True: # Watch for keyboard and mouse events. gf.check_events(ai_settings, screen, ship, bullets) ship.update() gf.update_bullets(bullets) gf.update_aliens(ai_settings, aliens) gf.update_screen(ai_settings, screen, ship, aliens, bullets)
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按钮 play_button = Button(ai_settings, screen, "play") # 创建外星人 alien = Alien(ai_settings, screen) # 创建一艘飞船 ship = Ship(ai_settings, screen) bullets = Group() aliens = Group() # 创建用于储存数据的实例 stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) # 创建外星人群 fun.create_fleet(ai_settings, screen, ship, aliens) # 开始游戏的主循环 while True: fun.check_events(ai_settings, screen, stats, play_button, ship, aliens, bullets) if stats.game: ship.update() fun.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets) fun.update_aliens(ai_settings, stats, screen, ship, aliens, bullets) fun.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def run_game(): #Initialize and create screen project pygame.init() game_settings = Settings() # screen = pygame.display.set_mode((1200,800)) screen = pygame.display.set_mode( (game_settings.screen_width, game_settings.screen_height)) pygame.display.set_caption("Rocket game") # make a rocket rocket = Rocket(game_settings, screen) # Make a group to store bullets in. bullets = Group() aliens = Group() fn.create_fleet(game_settings, screen, rocket, aliens) # Main loop while True: # Watch for keyboard and mouse events fn.check_events(game_settings, screen, rocket, bullets) rocket.update() fn.update_bullets(bullets) fn.update_screen(game_settings, screen, rocket, aliens, bullets)
def run_game(): #Initialze and create a screen object pygame.init() ai_set = Settings() screen = pygame.display.set_mode((ai_set.screen_width, ai_set.screen_height)) pygame.display.set_caption("Alien Invasion") #play button play_button = Button(ai_set, screen, "PLAY") #create game stats stats = GameStats(ai_set) sb = Scoreboard(ai_set, screen, stats) #create the Ship ship = Ship(ai_set, screen) bullets = Group() #alien group aliens = Group() # setting background color bg_color = (26, 48, 85) #make an alien # alien = Alien(ai_set, screen) #make fleet of aliens fu.create_fleet(ai_set, screen, ship, aliens) while True: fu.check_events(ai_set, screen, stats, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() fu.update_bullets(ai_set, screen, stats, sb, ship, aliens, bullets) fu.update_aliens(ai_set, stats, screen, sb, ship, aliens, bullets) #Redraw screen during each pass of loop fu.update_screen(ai_set, screen, stats, sb, ship, aliens, bullets, play_button)
def game_run(): file = r'activation.mp3' # Initialize pygame.mixer.init() # Load the file pf music pygame.mixer.music.load(file) pygame.mixer.music.play() # Initialize and create screen. pygame.init() setting = Setting() screen = pygame.display.set_mode( (setting.screen_width, setting.screen_height)) pygame.display.set_caption("Aircraft war") # Create play button play_button = Button(setting, screen, 'Play', 200) help_button = Button(setting, screen, 'Help', 400) # Draw a rocket. rocket = Rocket(setting, screen) # Set a Group for bullets. bullets = Group() # Set a Group for alien bullets. alien_bullets = Group() # Set a Group for aliens. aliens = Group() # Create aliens. functions.create_aliens(setting, screen, rocket, aliens, alien_bullets) # Create States. states = States(setting) # Create Scoreboard. scoreboard = Scoreboard(setting, screen, states) # Create Textbox. textbox = Textbox(setting, screen) # Create Incidents. incidents = Group() # Create Background. BackGround = Background('background.jpg', [0, 0]) # Main loop. while True: functions.respond_events(setting, screen, states, scoreboard, rocket, aliens, bullets, alien_bullets, play_button, help_button, textbox, incidents) if states.game_active: rocket.update_rocket() bullets.update(rocket) alien_bullets.update(setting) incidents.update(states) functions.update_bullets(setting, screen, states, scoreboard, rocket, aliens, bullets, alien_bullets) functions.update_aliens(setting, screen, states, scoreboard, rocket, aliens, bullets, alien_bullets, incidents) functions.update_alien_bullets(setting, screen, states, scoreboard, rocket, aliens, bullets, alien_bullets, incidents) functions.update_incidents(setting, screen, states, scoreboard, rocket, aliens, bullets, alien_bullets, incidents) functions.screen_update(setting, screen, states, scoreboard, rocket, aliens, bullets, alien_bullets, play_button, help_button, textbox, incidents) screen.fill([255, 255, 255]) screen.blit(BackGround.image, BackGround.rect)