import pygame import project_constants as const # ====================== # # === MAIN FUNCTIONS === # # ====================== # def test_blits(): display_concrete((2, 3)) display_mud((5, 6)) display_mud((5, 7)) display_grass((2, 1)) display_mine((2, 7)) display_mine((5, 7)) display_concrete((0, 0)) display_chained_mine((1, 2), (2, 3)) display_chained_mine((2, 3)) display_chained_mine((4, 8), (11, 15)) display_time_mine((1, 8), 12) display_time_mine((2, 8), 34) def blit_graphics(minefield): # background grid (fills frame with white, blits grid) const.SCREEN.fill((255, 255, 255)) const.SCREEN.blit( const.ASSET_BACKGROUND, ( const.V_SCREEN_PADDING, const.V_SCREEN_PADDING ) ) # draw tiles and mines from minefield minefield.draw(const.SCREEN) # all the tests in one place test_blits() # sapper display_sapper( minefield.agent.position, minefield.agent.direction ) # update graphics after blitting pygame.display.update() # moved here from minefield def calculate_screen_position(coords): coords = ( const.V_NUMBER_PADDING + const.V_SCREEN_PADDING + const.V_TILE_SIZE * coords[1], const.V_NUMBER_PADDING + const.V_SCREEN_PADDING + const.V_TILE_SIZE * coords[0], ) return coords # ============== # # === SAPPER === # # ============== # def display_sapper(coords, direction): sapper_screen_coords = calculate_screen_position(coords) if direction == const.Direction.UP: const.SCREEN.blit( const.ASSET_SAPPER, sapper_screen_coords ) elif direction == const.Direction.RIGHT: const.SCREEN.blit( pygame.transform.rotate(const.ASSET_SAPPER, 270), sapper_screen_coords ) elif direction == const.Direction.DOWN: const.SCREEN.blit( pygame.transform.rotate(const.ASSET_SAPPER, 180), sapper_screen_coords ) elif direction == const.Direction.LEFT: const.SCREEN.blit( pygame.transform.rotate(const.ASSET_SAPPER, 90), sapper_screen_coords ) # ============= # # === TILES === # # ============= # def display_concrete(coords): const.SCREEN.blit( const.ASSET_CONCRETE, calculate_screen_position(coords) ) def display_mud(coords): const.SCREEN.blit( const.ASSET_MUD, calculate_screen_position(coords) ) def display_grass(coords): const.SCREEN.blit( const.ASSET_GRASS, calculate_screen_position(coords) ) # ============= # # === MINES === # # ============= # def display_mine(coords): const.SCREEN.blit( const.ASSET_MINE, calculate_screen_position(coords) ) def display_chained_mine(coords, parent_coords=None): def display_number(which_coord, number): number_asset = const.ASSET_NUMBER_CHAINS_0 if number == 1: number_asset = const.ASSET_NUMBER_CHAINS_1 elif number == 3: number_asset = const.ASSET_NUMBER_CHAINS_3 elif number == 4: number_asset = const.ASSET_NUMBER_CHAINS_4 elif number == 5: number_asset = const.ASSET_NUMBER_CHAINS_5 elif number == 6: number_asset = const.ASSET_NUMBER_CHAINS_6 elif number == 7: number_asset = const.ASSET_NUMBER_CHAINS_7 elif number == 8: number_asset = const.ASSET_NUMBER_CHAINS_8 elif number == 9: number_asset = const.ASSET_NUMBER_CHAINS_9 elif number == 10: number_asset = const.ASSET_NUMBER_CHAINS_10 elif number == 11: number_asset = const.ASSET_NUMBER_CHAINS_11 elif number == 12: number_asset = const.ASSET_NUMBER_CHAINS_12 elif number == 13: number_asset = const.ASSET_NUMBER_CHAINS_13 elif number == 14: number_asset = const.ASSET_NUMBER_CHAINS_14 elif number == 15: number_asset = const.ASSET_NUMBER_CHAINS_15 mine_coords = calculate_screen_position(coords) number_coords = mine_coords if which_coord == const.Coords.X: number_coords = (mine_coords[0] + 20, mine_coords[1] + 24) elif which_coord == const.Coords.Y: number_coords = (mine_coords[0] + 34, mine_coords[1] + 24) const.SCREEN.blit( number_asset, number_coords ) display_mine(coords) if parent_coords is not None: const.SCREEN.blit( const.ASSET_CHAINS, calculate_screen_position(coords) ) display_number(const.Coords.X, parent_coords[0]) display_number(const.Coords.Y, parent_coords[1]) def display_time_mine(coords, time): def display_number(which_digit, number): number_asset = const.ASSET_NUMBER_TIME_0 if number == 1: number_asset = const.ASSET_NUMBER_TIME_1 elif number == 2: number_asset = const.ASSET_NUMBER_TIME_2 elif number == 3: number_asset = const.ASSET_NUMBER_TIME_3 elif number == 4: number_asset = const.ASSET_NUMBER_TIME_4 elif number == 5: number_asset = const.ASSET_NUMBER_TIME_5 elif number == 6: number_asset = const.ASSET_NUMBER_TIME_6 elif number == 7: number_asset = const.ASSET_NUMBER_TIME_7 elif number == 8: number_asset = const.ASSET_NUMBER_TIME_8 elif number == 9: number_asset = const.ASSET_NUMBER_TIME_9 mine_coords = calculate_screen_position(coords) number_coords = mine_coords if which_digit == const.Digit.ONES: number_coords = (mine_coords[0] + 36, mine_coords[1] + 22) elif which_digit == const.Digit.TENS: number_coords = (mine_coords[0] + 44, mine_coords[1] + 22) const.SCREEN.blit( number_asset, number_coords ) const.SCREEN.blit( const.ASSET_TIME_MINE, calculate_screen_position(coords) ) display_number(const.Digit.ONES, int(str(time)[-1])) display_number(const.Digit.TENS, int(str(time)[-2]))