def mainloop(tetro, field, next, points=0, level=1): """ Prints the field and the currently active tetromino to its given position. While ingame, you can control it with UP-DOWN-LEFT-RIGHT as in Tetris. Pause the loop with the ESC key, if you choose continue, the current loop ends, and is called again with the current parameters. """ game_sec = time.time() draw.screen(tetro, field, next, points, level) ingame = (True, 0) with pyconio.rawkeys(): while ingame[0]: current_sec = time.time() # Control mechanism if pyconio.kbhit(): ingame = control.ingame(tetro, field) points += ingame[1] * level draw.screen(tetro, field, next, points, level) # Fall mechanism if round(current_sec, min(level, 2)) >= round( game_sec, min(level, 2)): if control.move_valid(control.post_move(tetro, "down"), field): if control.hit(control.post_move(tetro, "down"), field): if tetro.pos[1] >= 1: last = tetro next.pos = [5, 0] tetro = next next = control.store_regen(last, field, next) # Game over if tetro hits another one, while Y pos is <1 else: ingame = (False, points) pyconio.clrscr() draw.logo("game_over.txt") time.sleep(1) # Add to top scores if needed scores = menu.get_scores() # If highscores.txt exists, is valid and not empty if scores not in (None, -1, []): if points > scores[-1].points: scorechoice = menu.add_score(points) if scorechoice is not None: menu.write_score(scorechoice) # If invalid elif scores == -1: pyconio.gotoxy(12, 25) pyconio.write("Hibás dicsőséglista!", end="\n") pyconio.gotoxy(8, 26) pyconio.write("Ellenőrizd a highscores.txt-t!") pyconio.flush() time.sleep(2.5) # If doesn't exist yet or empty else: scorechoice = menu.add_score(points) if scorechoice is not None: menu.write_score(scorechoice) return main() else: tetro.pos[1] += 1 # When hit, save tetro and generate new one. else: last = tetro next.pos = [len(field) // 4, 0] tetro = next next = control.store_regen(last, field, next) # Game ticks game_sec += control.speed_sec(level) draw.screen(tetro, field, next, points, level) # Line clear if control.line_full(field): points += control.delete_full(field) * level draw.screen(tetro, field, next, points, level) # Level up if points >= level**2 * 1000: level += 1 draw.screen(tetro, field, next, points, level) # Pause pausechoice = menu.pause() if pausechoice == "save": control.save_game(tetro, field, next, points, level) pausechoice = menu.save_menu() if pausechoice == "continue": return mainloop(tetro, field, next, points, level) elif pausechoice is None: return main()
def _handle_keyboard_event(event): """ Handles keyboard event Args: event (Event): Keyboard event to handle """ # Movement if event.key == pygame.K_a: update_creatures(config.GAME_DATA.creature_data, -1, 0) elif event.key == pygame.K_d: update_creatures(config.GAME_DATA.creature_data, 1, 0) elif event.key == pygame.K_w: update_creatures(config.GAME_DATA.creature_data, 0, -1) elif event.key == pygame.K_q: update_creatures(config.GAME_DATA.creature_data, -1, -1) elif event.key == pygame.K_e: update_creatures(config.GAME_DATA.creature_data, 1, -1) elif event.key == pygame.K_z: update_creatures(config.GAME_DATA.creature_data, -1, 1) elif event.key == pygame.K_c: update_creatures(config.GAME_DATA.creature_data, 1, 1) elif event.key == pygame.K_s: update_creatures(config.GAME_DATA.creature_data, 0, 1) elif event.key == pygame.K_x: update_creatures(config.GAME_DATA.creature_data, 0, 0) # Mini_map elif event.key == pygame.K_m: toggle_minimap() # Pickup/Drop Item elif event.key == pygame.K_t: objects_at_player = map_items_at_coord(config.GAME_DATA.item_data, config.PLAYER.x, config.PLAYER.y) for obj in objects_at_player: if obj.item: obj.item.pick_up(config.PLAYER) update_creatures(config.GAME_DATA.creature_data, 0, 0) elif event.key == pygame.K_F12: _toggle_wallhack() elif event.key == pygame.K_TAB: _toggle_camera() # Auto move elif event.key == pygame.K_v: auto_path(config.PATHFINDING) # Menu Buttons elif event.key == pygame.K_p: menu.pause() elif event.key == pygame.K_i: menu.inventory_menu() # Use magic elif event.key == pygame.K_SPACE: menu.magic_select_menu() # Returns to previous level elif event.key == pygame.K_1: if config.MAP_INFO.tile_array[config.PLAYER.y][ config.PLAYER.x].type == UPSTAIR: config.CURRENT_FLOOR -= 1 config.GAME_DATA.transition_previous_level() # Goes to next level elif event.key == pygame.K_2: if config.CURRENT_FLOOR < NUM_OF_FLOOR and \ config.MAP_INFO.tile_array[config.PLAYER.y][config.PLAYER.x].type == DOWNSTAIR: config.CURRENT_FLOOR += 1 config.GAME_DATA.transition_next_level() elif event.key == pygame.K_F2: save_game() elif event.key == pygame.K_F3: load_game()
''' Installer for File Analysis Tool Developed by M.Anish Installs thirdparty tools requied for this tool. ''' import menu as m import platform import os if platform.system().lower()!='linux': print('Platform not supported!') m.pause() flag=0 def detect(tool,cmd): print('\n\nDetecting '+tool+' ...\n') x=os.system(cmd) if x!=0: print('\nInstalling '+tool) global flag if flag==0: os.system('sudo apt-get update') flag=1 x=os.system('sudo apt-get install '+tool) if x==0: print(tool+' installed successfully') def detect_mat2(): detect('mat2','mat2 -v')
test_arg = False if len(sys.argv) > 1: if sys.argv[1] == 'test': print('Test mode') test_arg = True #global settings #pygame.mixer.pre_init (44100, -16, 1, 2512) #pygame.mixer.init() pygame.key.set_repeat(100, 100) pygame.key.get_repeat() menu.pause() #main function if test_arg == False: menu.menu_loop() #menu.intro_loop() menu.experiment_loop( 'В начале сотворил Бог небо и землю... Земля же была безвидна и пуста, и тьма над бездною, и Дух Божий носился над водою. И сказал Бог: да будет свет. И стал свет. И увидел Бог свет, что он хорош, и отделил Бог свет от тьмы.', 'images/intro/3.png', pic_x=0, pic_y=40, time_scroll=200) menu.experiment_loop( 'И упал с неба денница, сын зари! разбился о землю, попиравший народы. Низвержен он ныне в ад, в глубины преисподней. Тот, который говорил: "взойду на небо, выше звезд Божиих вознесу престол мой... взойду на высоты облачные, буду подобен Всевышнему".', 'images/intro/DL2.png',
def main(): background_music.set_volume(0) game = Game(Map(), Hero((WIDTH // 2, HEIGHT // 2)), Camera()) running = True while running: for event in pygame.event.get(): # комната открывается ("зачищается" при нажатии ПКМ) if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: game.hero.attack() elif event.button == 3 and not game.in_room: x, y = game.hero.rect.center for potion in potions: if pygame.mouse.get_pressed(3)[2] and get_length( potion.rect.center[0] - x, potion.rect.center[1] - y) < 50: potion.use(game.hero) break if event.type == OPEN_DOORS_EVENT.type: game.open_doors() game.score += 1 if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: menu.pause() if game.in_room and event.type == ENEMY_EVENT_TYPE: hero = game.hero for enemy in current_enemies: enemy.action(hero) if game.in_room and event.type == ENEMY_EVENT_TYPE: hero = game.hero for enemy in current_enemies: enemy.action(hero) if event.type == HERO_GET_ARMOR: game.hero.add_armor(1) if event.type == HERO_GET_MANA: game.hero.add_mana(5) if event.type == GAME_OVER_EVENT.type: return # menu.menu() if event.type == pygame.QUIT: if classes.current_score > result['record-score']: result['record-score'] = classes.current_score with open(os.path.join('data', 'statistics.txt'), 'w') as f: f.write(f'last-score={classes.current_score}\n') f.write(f'record-score={result["record-score"]}\n') f.write(f'total-kills={classes.total_kills}') sys.exit() screen.fill(pygame.Color('black')) game.render(screen) if pygame.mouse.get_focused(): # применение изменённого курсора screen.blit(change_cursor(main_cursor), pygame.mouse.get_pos()) pygame.display.flip() clock.tick(FPS) pygame.quit()
def handle_keys(): '''Handles player input ''' # get player input key_list = pygame.key.get_pressed() events_list = pygame.event.get() MOD_KEY = (key_list[pygame.K_LCTRL]) # process input for event in events_list: # loop through all events that have happened if event.type == pygame.QUIT: #If close window, close closegame() if event.type == pygame.KEYDOWN: # Move up if event.key == pygame.K_UP or event.key == pygame.K_w: globalvars.PLAYER.creature.move(0, -1) globalvars.FOV_CALCULATE = True # Move down if event.key == pygame.K_DOWN or event.key == pygame.K_s: globalvars.PLAYER.creature.move(0, 1) globalvars.FOV_CALCULATE = True # Move left if event.key == pygame.K_LEFT or event.key == pygame.K_a: globalvars.PLAYER.creature.move(-1, 0) globalvars.FOV_CALCULATE = True # Move right if event.key == pygame.K_RIGHT or event.key == pygame.K_d: globalvars.PLAYER.creature.move(1, 0) globalvars.FOV_CALCULATE = True # key 'e' -> pick up objects if event.key == pygame.K_e: objects_at_player = maps.objects_at_coords( globalvars.PLAYER.x, globalvars.PLAYER.y) for obj in objects_at_player: if obj.item: obj.item.pick_up(globalvars.PLAYER) if event.key == pygame.K_f: list_of_objs = maps.objects_at_coords(globalvars.PLAYER.x, globalvars.PLAYER.y) for obj in list_of_objs: if obj.stairs: obj.stairs.use() if obj.exitportal: obj.exitportal.use() # key 'q' -> drop object from inventory if event.key == pygame.K_q: if len(globalvars.PLAYER.container.inventory) > 0: globalvars.PLAYER.container.inventory[-1].item.drop( globalvars.PLAYER.x, globalvars.PLAYER.y) # key 'p' -> pause the game if event.key == pygame.K_ESCAPE: menu.pause() # key 'TAB' -> open inventory menu if event.key == pygame.K_TAB: menu.inventory()
def main(win, player): locked_pos = {} grid = create_grid(locked_pos) change_piece = False current_piece = get_shape() next_piece = get_shape() clock = pygame.time.Clock() fall_time = 0 hardcore_time = 0 time_elapsed = 0 board = Board(WIDTH, HEIGHT, BLOCK_SIZE, BOX_WIDTH, BOX_HEIGHT) player.restart_stats() run = True while run: grid = create_grid(locked_pos) fall_time += clock.get_rawtime() time_elapsed += clock.get_rawtime() if mode == 2: hardcore_time += clock.get_rawtime() clock.tick() if time_elapsed / 1000 > 1: time_elapsed = 0 player.timer += 1 if hardcore_time / 1000 > 5: hardcore_time = 0 if player.fall_speed > 0.1: player.fall_speed -= 0.005 player.speed_level += 1 if fall_time / 1000 > player.fall_speed: fall_time = 0 current_piece.y += 1 if not (valid_space(current_piece, grid, convert_shape_format)) and current_piece.y > 0: current_piece.y -= 1 change_piece = True for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() run = False sys.exit() # Key handling if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: current_piece.x -= 1 if not (valid_space(current_piece, grid, convert_shape_format)): current_piece.x += 1 elif event.key == pygame.K_RIGHT: current_piece.x += 1 if not (valid_space(current_piece, grid, convert_shape_format)): current_piece.x -= 1 elif event.key == pygame.K_DOWN: current_piece.y += 1 if not (valid_space(current_piece, grid, convert_shape_format)): current_piece.y -= 1 elif event.key == pygame.K_UP: current_piece.rotation += 1 if not (valid_space(current_piece, grid, convert_shape_format)): current_piece.rotation -= 1 elif event.key == pygame.K_RETURN: for i in range(20): current_piece.y += 1 if not (valid_space(current_piece, grid, convert_shape_format)): current_piece.y -= 1 elif event.key == pygame.K_ESCAPE: pause(win, active, WIDTH, HEIGHT, player.restart_stats, main, main_menu, get_leaderboard, player) shape_pos = convert_shape_format(current_piece) # draw square within the block for i in range(len(shape_pos)): x, y = shape_pos[i] if y > -1: grid[y][x] = current_piece.color if change_piece: for pos in shape_pos: p = (pos[0], pos[1]) locked_pos[p] = current_piece.color current_piece = next_piece next_piece = get_shape() change_piece = False player.score += clear_rows(grid, locked_pos, player) * player.get_score_factor() board.draw_window(win, grid, draw_grid) board.draw_next_shape(next_piece, win, player.score, player.get_max_score, player.format_timer, player.speed_level, player.combo, player.max_combo) pygame.display.update() if check_lost(locked_pos): draw_name(win, player) pygame.display.quit()
def main(player, surface): time_elapsed = 0 board = Board(WIDTH, HEIGHT) game = Game(WIDTH, HEIGHT, 30, 20) game.draw_letters(player) clock = pygame.time.Clock() run = True while run: time_elapsed += clock.get_rawtime() clock.tick() if time_elapsed / 1000 > 1: time_elapsed = 0 player.timer += 1 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: pause(WIN, WIDTH, HEIGHT, main, main_menu, get_leaderboard, player) elif event.unicode.isalpha(): for letter in game.letters: x, y, ltr, visible, clicked = letter if ltr == event.unicode.upper(): letter[4] = True board.draw(surface, player, game, board) pygame.time.delay(200) letter[3] = False game.guessed.append(ltr) if ltr not in game.word: player.lives -= 1 if player.lives == 0: board.draw(surface, player, game, board) pygame.time.delay(1000) board.draw_name(surface, player, board, main, game.word, 'Lost') break elif event.type == pygame.MOUSEBUTTONDOWN: mouse_x, mouse_y = pygame.mouse.get_pos() for letter in game.letters: x, y, ltr, visible, clicked = letter if visible: dist = sqrt((x - mouse_x) ** 2 + (y - mouse_y) ** 2) if dist < game.radius: letter[4] = True board.draw(surface, player, game, board) pygame.time.delay(500) letter[3] = False game.guessed.append(ltr) if ltr not in game.word: player.lives -= 1 if player.lives == 0: board.draw(surface, player, game, board) pygame.time.delay(500) board.draw_name(surface, player, board, main, game.word, 'Lost') break board.draw(surface, player, game, board) won = True for letter in game.word: if letter not in game.guessed: won = False break if won: player.score += 10 * len(game.word) board.draw(surface, player, game, board) pygame.time.delay(500) board.draw_name(surface, player, board, main, game.word, 'Won') break pygame.quit() sys.exit()