def game(): global fade_on, level_swap, loop, game_level, is_pause, animation, screen, HEIGHT, camera_on, music, dt """ font_y_type = True font_y = 0 """ pixel_font = pygame.freetype.Font("data/Fipps-Regular.otf", 1) num_level = 1 change_level = False player_type = 0 animation_solo = False dialog_anim = False win = False cont = 0 coop_mode = False end_coop = 0 end_cont = 0 sound_cont = 0 projectile_list = [] clock = pygame.time.Clock() music_lobby = False music_level1 = False music_gameover = False conn = Connection() while loop: screen.fill((0, 0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: loop = False if event.type == pygame.KEYDOWN: if not dialog.have_letters and fade_num == 0 and not is_pause and not dialog.choose \ and not dialog.mini_game and not animation and not animation_solo and game_level == 'lobby': if event.key == pygame.K_d: player.right = True player.last_dir = '' player.moved = True player.anim_right = True if event.key == pygame.K_a: player.left = True player.last_dir = '' player.moved = True player.anim_left = True if event.key == pygame.K_s: player.down = True player.last_dir = '' player.moved = True player.anim_down = True if event.key == pygame.K_w: player.up = True player.last_dir = '' player.moved = True player.anim_up = True if dialog.mini_game: if event.key == pygame.K_s: stealing.down = True if event.key == pygame.K_w: stealing.up = True if event.key == pygame.K_f: if dialog.have_letters: dialog.page += 1 dialog.font_y = 0 if game_level == 'credit': if dialog.page > 2: dialog.page = 2 if game_level == 'cutscene': fade_on = True dialog.page = 0 if dialog.choose: dialog.message = True if event.key == pygame.K_e: if press_on and not (dialog.mini_game or dialog.message or is_pause or animation_solo or fade_on): dialog.choose = True if event.key == pygame.K_r: if dialog.choose and not ( object_list[num - 1] in stealing.stealing_artifacts or player.rect.colliderect(farao.rect)): dialog.mini_game = True if level_swap: dialog_anim = True if event.key == pygame.K_ESCAPE: dialog.choose = False dialog.message = False if event.type == pygame.KEYUP: if not animation and not dialog.mini_game: if event.key == pygame.K_d: player.right = False player.last_dir = 'idle_right' player.anim_right = False if event.key == pygame.K_a: player.left = False player.last_dir = 'idle_left' player.anim_left = False if event.key == pygame.K_s: player.down = False player.last_dir = 'idle_down' player.anim_down = False if event.key == pygame.K_w: player.up = False player.last_dir = 'idle_up' player.anim_up = False if dialog.mini_game: if event.key == pygame.K_s: stealing.down = False if event.key == pygame.K_w: stealing.up = False if game_level == 'game_over' or game_level == 'coop' or game_level == 'credit' or is_pause: if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: menu.click = True if game_level == 'lobby': camera_function() if dialog.text_moving: dialog.text_y() if not player.right and not player.left and not player.up and not player.down: player.moved = False if game_level == 'lobby': music = 'Cutscenes.mid' if music_lobby: music_2.play(-1) if not win: door_sound.play() music_lobby = False pygame.mouse.set_visible(0) create_map(game_map1) stop_render = False if invert_depth: player.render(screen, game_level) stop_render = True objects_render(object_list) gate.rect = pygame.Rect(gate.x - camera[0], gate.y - camera[1], gate.width, 95) gate_down.rect = pygame.Rect(gate_down.x - camera[0], gate_down.y - camera[1], gate_down.width, gate_down.height) gate_side.rect = pygame.Rect(gate_side.x - camera[0], gate_side.y - camera[1], gate_side.width, gate_side.height) tile_rects.append(gate_side.rect) tile_rects.append(gate_down.rect) tile_rects.append(gate.rect) gate.render(screen) gate_down.render(screen) gate_side.render(screen) objects_interaction(pixel_font) if not stop_render: player.render(screen, game_level) if animation: if not win: animated_1() else: animated_2() else: if win: change_level = True fade_on = True if player.rect.colliderect(farao.rect): dialog.dialog_type(1, 6, True, screen, HEIGHT) dialog.expression = 'desejo' if dialog.text not in dialog.used_texts: animation_solo = True else: animation_solo = False if dialog_anim: dialog.choose = False if dialog.page == 0: dialog.expression = 'medo' elif dialog.page == 1: dialog.expression = 'raiva' dialog.dialog_type(2, 7, True, screen, HEIGHT) if dialog.text in dialog.used_texts: change_level = True fade_on = True dialog_anim = False move() player.rect = pygame.Rect( int(player.x + 50) - camera[0], int(player.y + 10) - camera[1], 62, 93) if player.moved: if sound_cont < 25: sound_cont += 1 if sound_cont == 25: walk_sound.play() sound_cont = 0 if stealing.failed == 3: change_level = True fade_on = True if not change_level: fade_options(WIDTH, HEIGHT, 2) else: fade_options(WIDTH, HEIGHT, 1) enemy.life = 20 player2.life = 25 player2.x = 320 player2.y = 450 enemy.max_cont = 45 enemy.x = 600 enemy.y = 100 projectile.cooldown_counter = 0 projectile.horus_cont = 0 projectile.del_cont = 0 enemy.cont = 0 enemy.last_decision = 0 if fade_num >= 255: music_2.stop() cont = 0 dialog.choose = False if stealing.failed == 3: music_gameover = True game_level = 'game_over' elif win: game_level = 'end' else: music_level1 = True game_level = f'level{num_level}' fade_on = True change_level = False if not animation: dialog.tutorial = True dialog.dialog_type(1, 3, True, screen, HEIGHT) if dialog.text in dialog.used_texts: dialog.tutorial = False if stealing.exit: dialog.tutorial = True dialog.dialog_type(1, 5, True, screen, HEIGHT) if dialog.text in dialog.used_texts: dialog.tutorial = False stealing.exit = False stealing.hud(dialog, screen) if game_level == 'level1': camera[0], camera[1] = 0, 0 create_map(game_map2) pygame.mouse.set_visible(0) if music_level1: music_3.play(-1) music_level1 = False if not is_pause: if not fade_on: player2.render(screen, game_level) if not coop_mode: dialog.dialog_type(1, 8, True, screen, HEIGHT) dialog.tutorial = True else: dialog.used_texts.append(dialog.text) if dialog.text in dialog.used_texts: dialog.tutorial = False if cont < 50: cont += 1 if cont == 50: mx, my = pygame.mouse.get_pos() player2.x += (mx - player2.x) / 5 player2.y += (my - player2.y) / 5 if player2.x + 61 >= WIDTH: player2.x = WIDTH - 61 if player2.x <= 0: player2.x = 0 if player2.y <= 100: player2.y = 100 if player2.y + 93 >= HEIGHT: player2.y = HEIGHT - 93 projectile.shoot_delay() enemy.movement() if projectile.cooldown_counter == 0: projectile_sound.play() projects = Projectile(0, 0) projectile_list.append(projects) projects.horus_position() projectile.cooldown_counter = 1 player2.rect = pygame.Rect( int(player2.x) - camera[0], int(player2.y) - camera[1], 62, 93) if player2.rect.colliderect(enemy.rect): if not enemy.cooldown: if not enemy.damaged: enemy.life -= 1 enemy.damaged = True horus_damage_sound.play() enemy.cooldown = True enemy.moving = True if enemy.life <= 0: enemy.life = 0 win = True stealing.stealing_artifacts.append(farao) change_level = True fade_on = True player.x = 4400 player.y = 880 animation = True player_rect_horus = pygame.Rect( int(player2.x) - 200, int(player2.y) - 150, 461, 393) enemy.render(screen) for i in projectile_list: i.rect = pygame.Rect(i.rect.x, i.rect.y, 10, 10) if not win: if player2.rect.colliderect(i.rect): if sound_cont == 0: player_damage_sound.play() if sound_cont <= 10: sound_cont += 1 else: sound_cont = 0 if not player2.damaged: player2.damaged = True player2.life -= 1 i.horus(HEIGHT, WIDTH, projectile_list) if enemy.life <= 10: pygame.draw.rect(screen, (0, 255, 0), player_rect_horus, 1) enemy.max_cont = 35 i.vel_y = 5 i.vel_x = 5 if not projectile.horus_cont == 1: projectile.horus_cont = 0 if projectile.horus_cont == 0: projectile.horus_hability = True projectile.horus_cont = 1 if projectile.horus_hability: Horus_sound.play() projectile.horus_hability = False if player_rect_horus.colliderect(i.rect): i.render(screen) else: i.render(screen) player2.hud(screen) if player2.life <= 0: player2.life = 0 change_level = True fade_on = True if player_type == 1: conn.player1(player2, enemy) elif player_type == 2: conn.player2(player2, enemy) if not change_level: fade_options(WIDTH, HEIGHT, 2) else: fade_options(WIDTH, HEIGHT, 1) if fade_num >= 255: music_3.stop() projectile_list.clear() if coop_mode: rect = pygame.Rect(0, 0, WIDTH, HEIGHT) pygame.draw.rect(screen, (0, 0, 0), rect) if end_coop <= 50: if win: dialog.font1.render_to(screen, (300, 200), 'Vocês Venceram', (255, 255, 255)) else: dialog.font1.render_to(screen, (300, 200), 'Vocês Perderam', (255, 255, 255)) elif end_coop <= 80: if player_type == 2: dialog.font1.render_to( screen, (150, 200), 'Você foi sacrificado para seu parceiro continuar', (255, 255, 255)) if player_type == 1: dialog.font1.render_to( screen, (200, 200), 'Você foi escolhido para sobreviver', (255, 255, 255)) else: if player_type == 1: end_coop = 0 main_menu() end_coop += 1 else: if not win: music_gameover = True game_level = 'game_over' else: music_lobby = True game_level = 'lobby' fade_on = True change_level = False else: end_coop = False if game_level == 'cutscene': pygame.mouse.set_visible(0) if dialog.page < len(cutscene): for i in range(len(cutscene[dialog.page])): dialog.render_multi(15, 25, screen, i, cutscene, HEIGHT) else: dialog.have_letters = False dialog.text_moving = False dialog.message = False dialog.page = 0 dialog.line = 0 fade_options(WIDTH, HEIGHT, 1) if fade_num >= 255: game_level = 'lobby' music_1.stop() win = False player.last_dir = '' player.flip = False player.player_action = 'walk_side' dialog.tutorial = False camera_on = True music_lobby = True fade_on = True animation = True if game_level == 'game_over': if music_gameover: gameover_music.play() music_gameover = False pygame.mouse.set_visible(100) if stealing.failed == 3: menu.draw_text('Você Foi Presa', menu.font, (255, 0, 0), screen, 250, 200) else: menu.draw_text('Você Morreu', menu.font, (255, 0, 0), screen, 280, 200) mx, my = pygame.mouse.get_pos() button_again = pygame.Rect(50, 400, 260, 50) button_exit = pygame.Rect(450, 400, 210, 50) if button_again.collidepoint((mx, my)): if menu.click: fade_on = True change_level = True if button_exit.collidepoint((mx, my)): if menu.click: main_menu() menu.click = False dialog.font1.render_to(screen, (70, 420), 'Tentar Novamente', (255, 255, 255)) dialog.font1.render_to(screen, (470, 420), 'Voltar ao Menu', (255, 255, 255)) if not change_level: fade_options(WIDTH, HEIGHT, 2) else: fade_options(WIDTH, HEIGHT, 1) if fade_num >= 255: if stealing.failed == 3: stealing.failed = 0 stealing.money = 0 stealing.stealing_artifacts.clear() player.x = 4650 player.y = 2000 stealing.bad_endind = 0 music_lobby = True game_level = 'lobby' fade_on = True change_level = False if game_level == 'coop': mx, my = pygame.mouse.get_pos() if not coop_mode: menu.draw_text('Escolha o Jogador', menu.font, (255, 255, 255), screen, 220, 100) button_player1 = pygame.Rect(150, 300, 110, 50) button_player2 = pygame.Rect(500, 300, 110, 50) button_back = pygame.Rect(50, 530, 150, 50) pygame.draw.rect(screen, (255, 255, 255), button_back) if button_back.collidepoint((mx, my)): if menu.click: main_menu() if button_player1.collidepoint((mx, my)): if menu.click: conn.connection1() player_type = 1 game_level = 'level1' coop_mode = True if button_player2.collidepoint((mx, my)): if menu.click: conn.connection2() player_type = 2 game_level = 'level1' coop_mode = True menu.click = False dialog.font4.render_to(screen, (70, 540), 'Voltar', (0, 0, 0)) dialog.font1.render_to(screen, (160, 320), 'Player1', (255, 255, 255)) dialog.font1.render_to(screen, (510, 320), 'Player2', (255, 255, 255)) if game_level == 'end': screen.blit(end_message_img, (0, 0)) fade_options(WIDTH, HEIGHT, 2) if end_cont <= 350: end_cont += 1 else: loop = False if game_level == 'credit': pygame.mouse.set_visible(100) menu.draw_text('Créditos', menu.font, (255, 255, 255), screen, 280, 25) if dialog.page < len(credit): for i in range(len(credit[dialog.page])): dialog.font1.render_to( screen, (15, (95 + 2 * dialog.font_size * i) + dialog.font_y), credit[dialog.page][i], (255, 255, 255)) mx, my = pygame.mouse.get_pos() button_back = pygame.Rect(50, 530, 150, 50) pygame.draw.rect(screen, (255, 255, 255), button_back) if button_back.collidepoint((mx, my)): if menu.click: main_menu() menu.click = False dialog.font4.render_to(screen, (70, 540), 'Voltar', (0, 0, 0)) if dialog.page < 2: dialog.font1.render_to(screen, (600, HEIGHT - 40), 'Aperte "F"', (255, 255, 255)) pygame.display.update() clock.tick(60)