コード例 #1
0
 def set_tile(self, point: Point, label: TileType):
     self.tile_grid[point.y, point.x] = Tile.from_label(point, label)
コード例 #2
0
ファイル: game_map.py プロジェクト: Sebastian-dm/pilferer
 def initialize_tiles(self):
     # Fill whole map with wall tiles
     tiles = [[Tile(True) for y in range(self.height)] for x in range(self.width)]
     return tiles
コード例 #3
0
    def __init__(self):

        grid = [[Tile() for _ in range(3)] for _ in range(3)]
        self.grid = list(map(list, zip(*grid)))
コード例 #4
0
    def initialize_tiles(self):
        # The below line creates a matrix of tile objects! See the 'training program' file if you need a refresher of how to create matrices.
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
コード例 #5
0
 def initialize_tiles(self):
     return np.array([[Tile(True) for x in range(self.width)]
                      for y in range(self.height)])
コード例 #6
0
 def create_h_tunnel(self, x1, x2, y):
     for x in range(min(x1, x2), max(x1, x2) + 1):
         self.tiles[x][y] = Tile(False)
コード例 #7
0
 def tile(self, point: Point) -> Tile:
     tile = Tile.empty(point)
     if self.in_bounds(point):
         tile = Tile.from_grid(point, self.grids(point))
     return tile
コード例 #8
0
ファイル: chunk.py プロジェクト: WeepingRaven/MirageRL
 def __init__(self, pos):
     self.pos = pos
     self.property = ChunkProperty.NONE
     self.discovered = False
     self.objects = []
     self.tiles = [[Tile(False, type_of=sand) for y in range(MAP_HEIGHT)] for x in range(MAP_WIDTH)]
コード例 #9
0
    def initialize_tiles(self):
        # initially mark all tiles as wall/blocked
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
コード例 #10
0
    def initialize_tiles(self):
        # All titles are blocked unless otherwise
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
コード例 #11
0
    def initialize_tiles(self):
        tiles = [[Tile(True) for y in range(self.height)] for x in range(self.width)] #True sets the default to tile = blocked, and then we choose where we can move by un-blocking

        return tiles
コード例 #12
0
 def initialize_tiles(self):
     # creates a 2d array [self.width x self.height] of Tile objects set to not block
     # effectively setting the map to empty
     self.tiles = [[Tile(False) for y in range(self.height)]
                   for x in range(self.width)]
コード例 #13
0
def main():
    screen_width = 80
    screen_height = 50

    bar_width = 20
    panel_height = 7
    panel_y = screen_height - panel_height

    message_x = bar_width + 2
    message_width = screen_width - bar_width - 2
    message_height = panel_height - 1

    map_width = 80
    map_height = 43

    room_max_size = 30
    room_min_size = 6
    max_rooms = 30

    fov_algorithm = 2
    fov_light_walls = True
    fov_radius = 10

    max_monsters_per_room = 3
    max_items_per_room = 2

    colors = {
        'dark_wall': libtcod.Color(0, 0, 100),
        'dark_ground': libtcod.Color(50, 50, 150),
        'light_wall': libtcod.Color(130, 110, 50),
        'light_ground': libtcod.Color(200, 180, 50)
    }

    til = Tile(False)

    fighter_component = Fighter(30, defense=2, power=5)

    player = Entity(0,
                    0,
                    '@',
                    libtcod.white,
                    'Player',
                    blocks=True,
                    fighter=fighter_component,
                    render_order=RenderOrder.ACTOR)
    entities = [player]

    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(screen_width, screen_height,
                              'libtcod tutorial revised', False)

    con = libtcod.console_new(screen_width, screen_height)
    panel = libtcod.console_new(screen_width, panel_height)

    map = GameMap(map_width, map_height)
    map.make_map(max_rooms, room_min_size, room_max_size, map_width,
                 map_height, player, entities, max_monsters_per_room,
                 max_items_per_room)

    fov_recompute = True

    fov_map = initialize_fov(map)

    message_log = MessageLog(message_x, message_width, message_height)

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    game_state = GameStates.PLAYERS_TURN

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if fov_recompute:
            recompute_fov(fov_map, player.x, player.y, fov_radius,
                          fov_light_walls, fov_algorithm)

        entities_in_render_order = sorted(entities,
                                          key=lambda x: x.render_order.value)

        render_all(con, panel, entities_in_render_order, player, map, fov_map,
                   fov_recompute, message_log, screen_width, screen_height,
                   bar_width, panel_height, panel_y, mouse, colors)

        fov_recompute = False

        libtcod.console_flush()

        clear_all(con, entities)

        action = handle_keys(key)

        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        player_turn_results = []

        if move and game_state == GameStates.PLAYERS_TURN:
            dx, dy = move
            destination_x = player.x + dx
            destination_y = player.y + dy
            if not map.is_blocked(destination_x, destination_y):
                target = get_blocking_entities_at_location(
                    entities, destination_x, destination_y)

                if target:
                    attack_results = player.fighter.attack(target)
                    player_turn_results.extend(attack_results)
                else:
                    player.move(dx, dy)
                    fov_recompute = True

                game_state = GameStates.ENEMY_TURN

            else:
                message_log.add_message(Message('stuck'))

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

        if exit:
            return True

        for player_turn_result in player_turn_results:
            message = player_turn_result.get('message')
            dead_entity = player_turn_result.get('dead')

            if message:
                message_log.add_message(message)

            if dead_entity:
                if dead_entity == player:
                    message, game_state = kill_player(dead_entity)
                else:
                    message = kill_monster(dead_entity)

                message_log.add_message(message)

        if game_state == GameStates.ENEMY_TURN:
            for entity in entities_in_render_order:
                if entity != player and entity.ai != None:
                    enemy_turn_results = entity.ai.take_turn(
                        fov_map, player, map, entities)

                    for enemy_turn_result in enemy_turn_results:
                        message = enemy_turn_result.get('message')
                        dead_entity = enemy_turn_result.get('dead')

                        if message:
                            message_log.add_message(message)

                        if dead_entity:
                            if dead_entity == player:
                                message, game_state = kill_player(dead_entity)
                            else:
                                message = kill_monster(dead_entity)

                        message_log.add_message(message)

                        if game_state == GameStates.PLAYER_DEAD:
                            break

            game_state = GameStates.PLAYERS_TURN
コード例 #14
0
 def place_room(self, room, tiles):  #Place a room object on the map
     for x in range(0, room.width - 1):
         for y in range(0, room.height - 1):
             self.tiles[x + room.x + 1][y + room.y + 1] = Tile.from_json(
                 tiles[room.grid[y][x]])
コード例 #15
0
 def create_room(self, room: Rect):
     for x in range(room.x1 + 1, room.x2):
         for y in range(room.y1 + 1, room.y2):
             # the room's rectangle includes the outer wall
             self.tiles[x][y] = Tile(False)
コード例 #16
0
 def initialize_tiles(self):
     """Initialize solid tiles based on the map size; rooms/tunnels are 'carved' out of this."""
     tiles = [[Tile(True) for y in range(self.height)]
              for x in range(self.width)]
     return tiles
コード例 #17
0
 def create_v_tunnel(self, y1, y2, x):
     for y in range(min(y1, y2), max(y1, y2) + 1):
         self.tiles[x][y] = Tile(False)
コード例 #18
0
ファイル: game_map.py プロジェクト: KirylShakh/Roguelike-ROP
 def initialize_tiles(self):
     return [[Tile(blocked=self.map_creator.default_tile_blocked) for y in range(self.height)] for x in range(self.width)]
コード例 #19
0
 def __iter__(self) -> [Point, Dict[str, int]]:
     for y in range(self.height):
         for x in range(self.width):
             point = Point(x, y)
             yield point, Tile.from_grid(point, self.grids(point))
コード例 #20
0
    def initialise_tiles(self):
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]
        # "carve out" rooms later on when generating dungeons

        return tiles
コード例 #21
0
import random
from math import sqrt
import tcod as libtcod

from components.door import Door
from components.stairs import Stairs
from components.fighter import Fighter
from components.ai import BasicMonster, astar

from entity import Entity
from map_objects.tile import Tile
from map_objects.biome import biomes

wall = Tile('wall', True)
ground = Tile('ground', False)
water = Tile('water', True, False, cost=6)
tree = Tile('tree', False, True, cost=3)

min_monsters_per_room = 0
max_monsters_per_room = 10

lair_radius = 9


class GameMap:
    def __init__(self, width, height, floor, islair=False):
        self.width = width
        self.height = height
        self.size = width * height
        self.floor = floor
        self.tiles = self.initialize_tiles()  # set in generate
コード例 #22
0
ファイル: game_map.py プロジェクト: assimil8/evolv3
 def initialize_tiles(self):
     #start with a completely walled off room, and then 'dig' out sections as we go
     tiles = [[Tile(True) for y in range(self.height)]
              for x in range(self.width)]
     return tiles
コード例 #23
0
ファイル: dungeon.py プロジェクト: Shpaackle/drag_dungeons
 def initialize_map(self):
     for y in self.dungeon.rows:
         for x in self.dungeon.columns:
             self.dungeon.place(Point(x, y),
                                Tile.wall(Point(x, y)),
                                region=-1)
コード例 #24
0
ファイル: game_map.py プロジェクト: CriminalBacon/RLpy
    def initialize_tiles(self):
        # True makes the tile un-walkable
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
コード例 #25
0
ファイル: game_map.py プロジェクト: rgarciacarmona/NeverDie
 def initialize_tiles(self):
     # Tiles are blocked by default
     tiles = [[Tile(True) for y in range(self.height)]
              for x in range(self.width)]
     return tiles
コード例 #26
0
ファイル: game_map.py プロジェクト: Nori93/DangerDagger
 def initialize_tiles(self):
     tiles = [[Tile(True, x, y) for y in range(self.map_height)]
              for x in range(self.map_width)]
     return tiles
コード例 #27
0
def create_mock_game_board(grid_size):
    grid = [[Tile() for _ in range(grid_size)] for _ in range(grid_size)]
    return list(map(
        list, zip(*grid)))  #doing this to transpose, is it needed though?
コード例 #28
0
    def initialize_tiles(self):
        # noinspection PyUnusedLocal
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
コード例 #29
0
    def initialize_tiles(self):
        tiles = [[Tile(True) for y in range(self.height)]
                 for x in range(self.width)]

        return tiles
コード例 #30
0
 def clear_dungeon(self):
     """
     Clears the dungeon data by filling the tile grid with empty tiles and region grid with -1
     """
     self.tile_grid = numpy.full(shape=self.grid_shape, fill_value=Tile.empty())
     self.region_grid = numpy.full(shape=self.grid_shape, fill_value=-1, dtype=int)