def run_game(): #Initializes the settings needed for pygame to run properly pygame.init() aiSettings = Settings() #Display mode called 'screen' is made, with 1200 x 800 dimensions #Screen is where the game elements are shown screen = pygame.display.set_mode( (aiSettings.screen_width,aiSettings.screen_height)) pygame.display.set_caption("Alien Invasion") #Sets background colour stats = GameStats(aiSettings) #Makes a ship on screen ship = Ship(aiSettings,screen) #Bullets! - make a group called bullets bullets = Group() #Aliens are made aliens = Group() #Calls on the createFleet function gf.createFleet(aiSettings, screen, ship, aliens) while True: gf.check_events(aiSettings,screen,ship,bullets) if stats.game_active: ship.update() gf.updateBullets(aiSettings, screen, ship, aliens, bullets) gf.updateAliens(aiSettings, stats, screen, ship, aliens, bullets) gf.update_screen(aiSettings, screen, ship, aliens, bullets)
def runGame(): pygame.init() setting = Settings() screen = pygame.display.set_mode( (setting.screenWidth, setting.screenHeight)) pygame.display.set_caption("IS ALIEN INVASION") playButton = Button(setting, screen, "PLAY") ship = SpaceShip(setting.shipSpeed, screen) stats = GameStats(setting) sb = Scoreboard(setting, screen, stats) bigbullets = Group() bullets = Group() aliens = Group() gf.createFleet(setting, screen, ship, aliens) pygame.mixer.music.load(".\\images\\Yee.mp3") while True: gf.check_events(setting, screen, stats, sb, playButton, ship, aliens, bullets, bigbullets) if stats.gameActive: ship.update() gf.updateBullets(setting, screen, stats, sb, ship, aliens, bullets) gf.updatebigBullets(setting, screen, stats, sb, ship, aliens, bigbullets) gf.increaseLevel(stats, sb, aliens) gf.updateAliens(setting, stats, sb, screen, ship, aliens, bullets) gf.update_screen(setting, screen, stats, sb, ship, aliens, bullets, bigbullets, playButton)
def run_game(): pygame.init() clock = pygame.time.Clock() last = pygame.time.get_ticks() cooldown = 2000 aiSettings = Settings() screen = pygame.display.set_mode( (aiSettings.screenWidth, aiSettings.screenHeight)) pygame.display.set_caption("Asteroids") menu = Menu(aiSettings, screen) stats = GameStats(aiSettings) sb = Scoreboard(aiSettings, screen, stats) ship = Ship(aiSettings, screen) bullets = Group() asteroids = Group() while True: clock.tick(60) gf.checkEvents(aiSettings, screen, ship, bullets, asteroids, stats, sb, menu) if stats.game_active: ship.update() gf.updateBullets(bullets, asteroids, aiSettings, sb, stats) now = pygame.time.get_ticks() if now - last >= cooldown: last = now gf.create_asteroid(aiSettings, screen, asteroids) gf.update_asteroid(asteroids, aiSettings, stats, ship, bullets, sb) gf.updateScreen(aiSettings, screen, ship, bullets, asteroids, sb, stats, menu)
def run_game(): #Initializes the settings needed for pygame to run properly pygame.init() aiSettings = Settings() #Display mode called 'screen' is made, with 1200 x 800 dimensions #Screen is where the game elements are shown screen = pygame.display.set_mode( (aiSettings.screen_width,aiSettings.screen_height)) pygame.display.set_caption("Alien Invasion") #Sets background colour stats = GameStats(aiSettings) sb = Scoreboard(aiSettings, screen, stats) #Makes a ship on screen ship = Ship(aiSettings,screen) #Bullets! - make a group called bullets bullets = Group() #Aliens are made aliens = Group() #Calls on the createFleet function gf.createFleet(aiSettings, screen, ship, aliens) playButton = Button(aiSettings, screen, "Click to Play") while True: gf.check_events(aiSettings, screen, stats, sb, playButton, ship, aliens, bullets) sb.showScore() if stats.game_active: ship.update() gf.updateBullets(aiSettings, screen, stats, sb, ship, aliens, bullets) gf.updateAliens(aiSettings, stats, screen, ship, sb, aliens, bullets) gf.update_screen(aiSettings, screen, stats, sb, ship, aliens, bullets, playButton)
def run_game(): #Cria bullet group bullets = Group() #Cria enemy group enemies = Group() #Cira enemy bullet group ebullets = Group() bbullets = Group() explosions = Group() gSettings.resetDificulty() gf.clearScore() bg = Background(gSettings, screen, trueScreen, 0) clouds = Group() for i in range(3): new_cloud = Background(gSettings, screen, trueScreen, 1) clouds.add(new_cloud) new_cloud = Background(gSettings, screen, trueScreen, 2) clouds.add(new_cloud) #Cria jogador p1 = Player(gSettings, screen, enemies, soundController, trueScreen, explosions, ebullets, bbullets) level = Level(screen, gSettings, enemies, p1, trueScreen) gf.initGUI(gSettings, screen) gf.getHighScore() soundController.playMusic(0) #Inicia o loop principal do jogo. level.generateSpawn() boss = Boss(gSettings, screen, 347, 100, p1, soundController) bossCount = 0 bossSpawned = False first = 0 while True: clock.tick(fps) gf.checkEvents(p1, gSettings, screen, bullets, boss, bossSpawned) gf.updateScreen(gSettings, screen, p1, bullets, enemies, ebullets, bg, clouds, explosions, boss, bbullets, bossSpawned) gf.updateBg(bg, clouds) p1.update(bullets) gf.updateBullets(bullets, enemies, soundController, screen, explosions, boss) gf.updateExplosions(explosions) gf.updateEBullets(ebullets, p1) gf.updateBBullets(bbullets, p1) gf.updateEnemies(enemies, p1, ebullets) gf.updateBoss(boss, bbullets, p1, bossSpawned) gf.updateScore() if len(enemies) == 0: if bossCount >= 20: bossCount = 0 if first == 1: gSettings.bossIncrease() boss = Boss(gSettings, screen, 347, 100, p1, soundController) bossSpawned = True soundController.stopMusic() soundController.playMusic(1) else: if not bossSpawned: gSettings.difficultyIncrease() level.generateSpawn() bossCount += 1 else: if boss.hp <= 0: bossSpawned = False boss.alive = False soundController.stopMusic() soundController.playMusic(0) gf.addBScore(p1) first = 1 soundController.playSound(6) new_explosion = new_explosion = Explosion( screen, boss.rect.centerx, boss.rect.centery, 200, 10, 0) explosions.add(new_explosion) if p1.dead and not pygame.mixer.get_busy(): telaBotoes("Game Over", "Novamente", "Sair")