コード例 #1
0
def create_map():
    generate_map()
    for BLOCK_INDEX, BLOCK in enumerate(game_map):  # <- with the enumerate, I can print the indexes
        for TERRAIN_OBJECT_INDEX, TERRAIN_OBJECT in enumerate(BLOCK):  # <- with the enumerate, I can print the indexes

            label = tk.Label(frame_map, image=TERRAIN_OBJECT.actual_image, relief='sunken')
            label.grid(row=TERRAIN_OBJECT.coordinate[0], column=TERRAIN_OBJECT.coordinate[1])
            TERRAIN_OBJECT.label = label  # <-- SAVING THE LABEL ON THE TERRAIN OBJECT

            if BLOCK_INDEX == player.position[0] and TERRAIN_OBJECT_INDEX == player.position[1]:
                TERRAIN_OBJECT.label.config(relief='raised', bg='red')
    remove_fog()
コード例 #2
0
def pygame_event_loop(loop, event_queue, state):
    while True:
        if state.world_map is None:
            print("generating map ...")
            state.world_map = generate_map(1000, 1000)
        event = pygame.event.wait()
        asyncio.run_coroutine_threadsafe(event_queue.put(event), loop=loop)
コード例 #3
0
def main():
    lvlArray = generate_map()
    playerPos = [1, 1]
    draw_level(playerPos, lvlArray)
    while True:
        key = stdscr.getch()
        if key == 27:
            break
コード例 #4
0
 def return_map(self):
     n, m, l, t, tl, h, w, ot = unpack('b' * 8, self.rfile.read(8))
     rmap = map_generator.generate_map(n, m, l, t, tl, h, w, ot)
     self.wfile.write(
         pack('b', 11) + pack('b', len(rmap)) + pack('b', len(rmap[0])))
     self.wfile.write(b''.join(b''.join(map(lambda x: pack('b', x), y))
                               for y in rmap))
     print(n, m, l, t, tl, h, w, ot)
コード例 #5
0
ファイル: Map.py プロジェクト: the3dsandwich/Dominik-Game
 def __init__(self, seed=time(), size=MAP_SIZE, p_size=7):
     self.map, self.block_size, self.player_location = generate_map(
         seed, size)
     self.seed = seed
     self.size = size
     self.monsters = sum(isinstance(i, MonsterTile) for i in self.map)
     self.items = sum(isinstance(i, ItemTile) for i in self.map)
     self.p_size = p_size
コード例 #6
0
def wait_for_map_generation():
    # if not request.form.get("domain"):
    #     return render_template("failure.html")
    username = request.form.get("username")
    if "@" not in username:
        username = "******" + username
    friends_loc_list = friends_geolocator(get_user_friends(username))
    fl_map = generate_map(group_duplicates(friends_loc_list))
    return fl_map._repr_html_()
コード例 #7
0
ファイル: engine.py プロジェクト: gbouchez/roguemonsters
    def __init__(self):
        self.render_engine = RenderEngine()
        self.input_manager = InputManager()
        self.player = load_game()
        if self.player is None:
            self.player = Player()
            game_map = generate_map(1)
            game_map.take_over_monster(self.player)
        game_map = self.player.entity.game_map

        map_scene = MapScene(self.player, game_map)
        self.current_scene = map_scene
コード例 #8
0
ファイル: maps.py プロジェクト: sramsdell/Roguelike
 def reset(self):
     grid_post = [Map(generate_map(30, 30), game, 30, 30, False) for i in range(10)]
     grid = Map(["xxxxxxxxxxxx",
         "xxxxxxxxxxxx",
         "xx........xx",
         "xx........xx",
         "xx........xx",
         "xx........xx",
         "xx........xx",
         "xx........xx",
         "xx........xx",
         "xx........xx",
         "xxxxxxxxxxxx",
         "xxxxxxxxxxxx"], game, 12, 12, door_up=False, num_mobs=1, no_fog=True, items_on=False)
     grid_pre = ["maybe a warp?", grid]
     grids = grid_pre + grid_post
     self.grids = grids
コード例 #9
0
ファイル: map_scene.py プロジェクト: gbouchez/roguemonsters
 def go_downstairs(self):
     new_map = generate_map(self.game_map.depth + 1, self.player)
     self.initialize_map(new_map)
コード例 #10
0
ファイル: main.py プロジェクト: Giacomo1995/NFO-DS
    sweep_curr_cost = 0
    sweep_curr_time = 0
    nearest_neighbour_curr_cost = 0
    nearest_neighbour_curr_time = 0
    nearest_neighbour_opt_curr_cost = 0
    nearest_neighbour_opt_curr_time = 0
    nearest_insertion_curr_cost = 0
    nearest_insertion_curr_time = 0
    farthest_insertion_curr_cost = 0
    farthest_insertion_curr_time = 0

    for i in range(n_means):

        print(" = Generating maps for " + str(dim) + " nodes =")
        current_map = generate_map(dim)

        # Uptating Sweep
        print("Generating sweep...")
        c, t, _ = sweep(current_map,
                        generate_costs(current_map, 0),
                        plot=False)
        sweep_curr_cost += c
        sweep_curr_time += t
        print("Sweep time: " + "{:.2f}".format(t))

        # Uptating Nearest Neighbour
        print("Generating nearest neighbour...")
        c, t, _ = kNN(generate_costs(current_map, 0), 0)
        nearest_neighbour_curr_cost += c
        nearest_neighbour_curr_time += t
コード例 #11
0
ファイル: server.py プロジェクト: meskill/GameServer
	def return_map(self):
		n, m, l, t, tl, h, w, ot = unpack('b' * 8, self.rfile.read(8))
		rmap = map_generator.generate_map(n, m, l, t, tl, h, w, ot)
		self.wfile.write(pack('b', 11) + pack('b', len(rmap)) + pack('b', len(rmap[0])))
		self.wfile.write(b''.join(b''.join(map(lambda x: pack('b', x), y)) for y in rmap))
		print(n, m, l, t, tl, h, w, ot)
コード例 #12
0
def run():
    # Initialization
    pygame.init()
    settings = Settings()
    state = Game_State()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Super Mario Bros")
    bg_color = settings.bg_color
    stats = Game_Stats(screen, settings)

    clock = pygame.time.Clock()

    mario = Mario(screen, settings, stats)

    pygame.mixer.music.load("Sounds/overworld.mp3")
    pygame.mixer.music.play(-1)

    # Groups
    map_group = Group()
    block_group = Group()
    floor_group = Group()
    pipe_group = Group()
    enemy_group = Group()
    powerup_group = Group()
    fireball_group = Group()
    dead_group = Group()

    map.generate_map(screen, settings, map_group, floor_group, pipe_group,
                     block_group, enemy_group)
    f = Flag(screen, settings, 198 * settings.block_width,
             13 * settings.block_height)
    f.add(map_group)

    pipesprites = pipe_group.sprites()

    timer = 0
    death_counter = 0

    # Game Loop
    while state.running:
        settings.reset_holders()
        clock.tick(settings.fps)

        # handle mario death
        if mario.is_dead and death_counter <= 240:
            # draw black screen
            if death_counter == 60:
                screen.fill(settings.bg_color)
                stats.lives -= 1
                if stats.lives < 0:
                    stats.init_base_values()
                    #display game over
                    game_over_label = Text(None, settings.TEXT_SIZE,
                                           "Game Over", settings.WHITE, 0, 0)
                    game_over_label.rect.center = (settings.screen_width / 2,
                                                   settings.screen_height / 2)
                    game_over_label.draw(screen)
                else:
                    # display level
                    lvl_str = "World " + str(stats.world) + "-" + str(
                        stats.level_num)
                    level_label = Text(None, settings.TEXT_SIZE, lvl_str,
                                       settings.WHITE, 0, 0)
                    level_label.rect.center = (settings.screen_width / 2,
                                               settings.screen_height / 2)
                    level_label.draw(screen)
                pygame.display.flip()
            death_counter += 1
            print(death_counter)
        elif mario.is_dead and death_counter > 240:
            # reset
            death_counter = 0
            mario.kill()
            mario = Mario(screen, settings, stats)
            map_group = Group()
            block_group = Group()
            floor_group = Group()
            pipe_group = Group()
            enemy_group = Group()
            powerup_group = Group()
            fireball_group = Group()
            dead_group = Group()
            pygame.mixer.music.play(-1)
            map.generate_map(screen, settings, map_group, floor_group,
                             pipe_group, block_group, enemy_group)
            f = Flag(screen, settings, 198 * settings.block_width,
                     13 * settings.block_height)
            f.add(map_group)
            stats.new_level()

        # victory -> change level -> use death_counter to reset
        if mario.has_won and death_counter <= 300:
            # draw black screen
            if death_counter == 100:
                stats.level_num += 1
                screen.fill(settings.bg_color)
                # display level
                lvl_str = "World " + str(stats.world) + "-" + str(
                    stats.level_num)
                level_label = Text(None, settings.TEXT_SIZE, lvl_str,
                                   settings.WHITE, 0, 0)
                level_label.rect.center = (settings.screen_width / 2,
                                           settings.screen_height / 2)
                level_label.draw(screen)
                coming_soon = Text(None, settings.TEXT_SIZE, "Coming Soon",
                                   settings.WHITE, 0, 0)
                coming_soon.rect.center = (settings.screen_width / 2,
                                           (settings.screen_height / 2) +
                                           settings.SPACER)
                coming_soon.draw(screen)
                pygame.display.flip()
            death_counter += 1
            print(death_counter)
        elif mario.has_won and death_counter > 300:
            # reset game
            death_counter = 0
            mario.kill()
            mario = Mario(screen, settings, stats)
            map_group = Group()
            block_group = Group()
            floor_group = Group()
            pipe_group = Group()
            enemy_group = Group()
            powerup_group = Group()
            fireball_group = Group()
            dead_group = Group()
            pygame.mixer.music.load("Sounds/overworld.mp3")
            pygame.mixer.music.play(-1)
            map.generate_map(screen, settings, map_group, floor_group,
                             pipe_group, block_group, enemy_group)
            f = Flag(screen, settings, 198 * settings.block_width,
                     13 * settings.block_height)
            f.add(map_group)
            stats.new_level()

        # Game Play
        gf.check_events(state, mario, screen, settings, fireball_group,
                        map_group)
        # Update here
        if not mario.is_dead and not mario.has_won:
            if timer < settings.fps:
                timer += 1
            else:
                timer = 0
                stats.decrement_time()

            gf.update(screen, settings, mario, map_group, floor_group,
                      pipe_group, block_group, enemy_group, powerup_group,
                      fireball_group, dead_group, f)

            if stats.did_time_runout():
                mario.dead()
            if stats.time == 100:
                pygame.mixer.Sound('Sounds/time_warning.wav').play()

            # update game values
            stats.add_score(settings.score_holder)
            stats.add_coin(settings.coin_holder)
            if settings.one_up:
                stats.lives += 1
                settings.one_up = False
            # Display here
            stats.update()
            gf.update_screen(screen, settings, stats, mario, map_group,
                             floor_group, pipe_group, block_group, enemy_group,
                             powerup_group, fireball_group, dead_group, f)
        # stats.draw()

    pygame.quit()
    sys.exit()
コード例 #13
0
    def __init__(self, seed, size, volume):
        # Константы генерации карты
        self.SEED = 15
        self.SIZE = int(1024 * size)
        self.H_MAX = 20
        self.SHARP = 2
        self.DEPTH = 100
        self.PROBABILITY = 1/2
        self.H_0 = 12
        self.LAKES_NUMBER = int(10*size)
        
        # Инициализируем пайгейм
        pygame.init()
        self.screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN)
        pygame.display.update()
        self.clock = pygame.time.Clock()
        
        # Константы игры
        self.FPS = 20    
        self.finished = False
        self.BLOCK_SIZE = 20
        self.DO_RADIUS = 140
        self.inventory_bool = False
        self.volume = volume
        
        # Размеры окна
        self.WINDOW_X, self.WINDOW_Y = pygame.display.get_surface().get_size()
        self.ORIGINAL_WINDOW_X = 1920
        self.ORIGINAL_WINDOW_Y = 1080
        self.RATIO_X = self.WINDOW_X/self.ORIGINAL_WINDOW_X
        self.RATIO_Y = self.WINDOW_Y/self.ORIGINAL_WINDOW_Y        
        
        # Подгружаем текстуры карты
        self.dirt_grass = pygame.image.load('resources/map/dirt_grass.png')

        self.blocks = [[pygame.image.load('resources/map/dirt.png'), 
                        pygame.image.load('resources/map/stone.png')],
                       [pygame.image.load('resources/map/snow.png'), 
                        pygame.image.load('resources/map/ice.png')]]

        self.water = [pygame.image.load('resources/map/water.png'), 
                      pygame.image.load('resources/map/ice_water.png')]
        
        # Подгружаем текстуры персонажа
        self.player_animation = [pygame.image.load('resources/player_animation/player_right.png'), 
                    pygame.image.load('resources/player_animation/move_right_1.png'),
                    pygame.image.load('resources/player_animation/move_right_2.png'),
                    pygame.image.load('resources/player_animation/player_left.png'), 
                    pygame.image.load('resources/player_animation/move_left_1.png'),
                    pygame.image.load('resources/player_animation/move_left_2.png')]
        
        # Подгружаем бэкграунд
        self.bg = pygame.image.load('resources/bg.png')
        self.bg = pygame.transform.scale(self.bg, (self.WINDOW_X, self.WINDOW_Y))
        
        # Подгружаем текстуры инвентаря
        self.inventory_image = pygame.image.load('resources/inventory/inventory.png')
        self.INVENTORY_IMAGE_SIZE_X = int(1000*self.RATIO_X)
        self.INVENTORY_IMAGE_SIZE_Y = int(100*self.RATIO_Y)
        self.inventory_image = pygame.transform.scale(self.inventory_image, (self.INVENTORY_IMAGE_SIZE_X, self.INVENTORY_IMAGE_SIZE_Y))
        
        self.tools_invent = [pygame.image.load('resources/inventory/inventory_image/dirt.png'),
                             pygame.image.load('resources/inventory/inventory_image/stone.png')]
        self.TOOLS_INVENT_SIZE_X = int(100*self.RATIO_X)
        self.TOOLS_INVENT_SIZE_Y = int(100*self.RATIO_Y)
        for i in range(0, len(self.tools_invent)):
            self.tools_invent[i] = pygame.transform.scale(self.tools_invent[i], (self.TOOLS_INVENT_SIZE_X, self.TOOLS_INVENT_SIZE_Y))                           

        self.cell = pygame.image.load('resources/inventory/cell.png')
        self.CELL_SIZE_X = int(100*self.RATIO_X)
        self.CELL_SIZE_Y = int(120*self.RATIO_Y)
        self.cell = pygame.transform.scale(self.cell, (self.CELL_SIZE_X, self.CELL_SIZE_Y))
        
        # Подгружаем текстуры инструментов
        self.tools_images = [[pygame.image.load('resources/tools/shovel.png'),
                         pygame.image.load('resources/tools/pick.png')],
                        [pygame.image.load('resources/tools/shovel_right.png'),
                         pygame.image.load('resources/tools/pick_right.png')],     
                        [pygame.image.load('resources/tools/shovel_right_1.png'), 
                         pygame.image.load('resources/tools/pick_right_1.png')],
                        [pygame.image.load('resources/tools/shovel_right_2.png'), 
                         pygame.image.load('resources/tools/pick_right_2.png')],
                        [pygame.image.load('resources/tools/shovel_left.png'),
                         pygame.image.load('resources/tools/pick_left.png')],
                        [pygame.image.load('resources/tools/shovel_left_1.png'),
                         pygame.image.load('resources/tools/pick_left_1.png')],
                        [pygame.image.load('resources/tools/shovel_left_2.png'),
                         pygame.image.load('resources/tools/pick_left_2.png')]]
        for i in range(0, 2):
            self.tools_images[0][i] = pygame.transform.scale(self.tools_images[0][i], (self.TOOLS_INVENT_SIZE_X, self.TOOLS_INVENT_SIZE_Y))  
            
        self.check = pygame.image.load('resources/tools/check.png')
        self.check = pygame.transform.scale(self.check, (self.TOOLS_INVENT_SIZE_X, self.TOOLS_INVENT_SIZE_Y))
        
        # Создаем карту
        self.map = generate_map(self.SEED, self.SIZE, self.H_MAX, self.SHARP, self.DEPTH, self.PROBABILITY) 
        self.biome_map, map = biome_generator(self.SEED, self.DEPTH, self.SIZE, self.map, self.LAKES_NUMBER)
        
        # Создаем персонажа и его рюкзак
        self.player = Player(self.SIZE/2, self.H_0, self.DEPTH, self.SIZE, self.WINDOW_X, self.BLOCK_SIZE)
        self.player.y_calculation(self.map, self.H_MAX)
        self.backpack = Backpack()
        
        # Загружаем музыку
        pygame.mixer.music.load('sounds/background_music.wav')
        
        #Загружаем шрифт
        pygame.font.init()
        self.font_1 = pygame.font.Font(None, 36)
コード例 #14
0
from map_generator import generate_map;

generate_map();
コード例 #15
0
from utils import find_column


def generate_initial_waterfall(x, y, amount, map):
    # Find initial water position
    list_of_water_states = []
    initial_state = map[:, :]
    position = find_column(initial_state, x, y)

    # Add new dimension for water level
    initial_state = np.vstack([initial_state, np.zeros(len(initial_state[0]))])
    initial_state[3, position] = amount

    list_of_water_states.append(initial_state)
    return list_of_water_states


if __name__ == '__main__':
    # mpirun -hostfile hostfile -np 1 python watefall.py
    # response = map_generator.request_osm_api()
    response = map_generator.load_request_from_file("samples/poland_s.json")
    print(str(response))
    positions = map_generator.get_osm_positions_dict(response)
    map_array = map_generator.generate_map(positions)

    l_water = generate_initial_waterfall(48.0, 18.0, 1000, map_array)

    l_water = start(l_water)

    visualizer.save_animation(map_array, l_water, 'animation.mp4')