コード例 #1
0
ファイル: whereami.py プロジェクト: Alberdi/assorted
def handle_keys():
  global player_x, player_y, m, turns
  #movement keys
  if libtcod.console_is_key_pressed(libtcod.KEY_UP):
    if libtcod.map_is_walkable(m, player_x, player_y - 1):
      player_y -= 1
      turns += 1
  elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
    if libtcod.map_is_walkable(m, player_x, player_y + 1):
      player_y += 1
      turns += 1
  elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
    if libtcod.map_is_walkable(m, player_x - 1, player_y):
      player_x -= 1
      turns += 1
  elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
    if libtcod.map_is_walkable(m, player_x + 1, player_y):
      player_x += 1
      turns += 1

  key = libtcod.Key()
  mouse = libtcod.Mouse()
  libtcod.sys_check_for_event(libtcod.EVENT_ANY, key, mouse)
  if key.vk == libtcod.KEY_ENTER and key.lalt:
    #Alt+Enter: toggle fullscreen
    libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
  elif key.vk == libtcod.KEY_SPACE:
    end(player_x, player_y, mouse.cx, mouse.cy)
  elif key.vk == libtcod.KEY_ESCAPE:
    return True  #exit game
コード例 #2
0
ファイル: Engine.py プロジェクト: GuiWong/-DemonHunter-python
    def get_reachable_tile(self, unit, send=False):

        X, Y = unit.get_pos()
        radius = unit.get_AP()
        result = list()

        b = -1
        h = -1
        grow = True

        for y in range(2 * radius + 1):
            if grow:
                b += 1
                h += 2
            else:
                b -= 1
                h -= 2
            if y == radius:
                grow = False
            for x in range(h):

                tile = [X - b + x, Y - radius + y]
                if (self.get_move_cost([X, Y], tile) <= radius
                        and libtcod.map_is_walkable(self.path_map, tile[0],
                                                    tile[1])):

                    result.append(tile)

        if send:
            self.set_reachable_tiles(result)
        return result
コード例 #3
0
ファイル: snake.py プロジェクト: freevryheid/snake
def snackxy(grid, w, h):
    # snacks are not transparent but walkable
    for x in range(w):
        for y in range(h):
            if not tcod.map_is_transparent(grid, x, y) and tcod.map_is_walkable(grid, x, y):
                return True, x, y
    return False, 0, 0
コード例 #4
0
ファイル: Engine.py プロジェクト: GuiWong/-DemonHunter-python
    def place_to(self, unit, tile):

        result = False
        if libtcod.map_is_walkable(self.path_map, tile[0], tile[1]):

            unit.set_pos(tile[0], tile[1])
            result = True

        else:
            a = 0
            while a < 5:

                if libtcod.map_is_walkable(self.path_map, tile[0] + 1 + a,
                                           tile[1]):

                    unit.set_pos(tile[0] + 1 + a, tile[1])
                    result = True

                if libtcod.map_is_walkable(self.path_map, tile[0] - 1 - a,
                                           tile[1]):

                    unit.set_pos(tile[0] - 1 - a, tile[1])
                    result = True

                if libtcod.map_is_walkable(self.path_map, tile[0],
                                           tile[1] + 1 + a):

                    unit.set_pos(tile[0], tile[1] + 1 + a)
                    result = True

                if libtcod.map_is_walkable(self.path_map, tile[0],
                                           tile[1] - 1 - a):

                    unit.set_pos(tile[0], tile[1] - 1 - a)
                    result = True

                else:
                    pass

                a += 1
                if result:
                    break

        self.path_place_unit()

        return result
コード例 #5
0
ファイル: main.py プロジェクト: fiddlerwoaroof/normal_map
	def get_color(self, level,x,y, color):
		fovmap = self.get_fovmap(level)
		if libtcod.map_is_in_fov(fovmap, x,y) and libtcod.map_is_walkable(fovmap,x,y):
			#print 'cell in fov', level,x,y, libtcod.map_get_width(fovmap), libtcod.map_get_height(fovmap)
			color = [x/255 for x in color]
			h,s,v = colorsys.rgb_to_hsv(*color)
			r,g,b = [int(x*255) for x in colorsys.hsv_to_rgb(h,s, v+0.15)]
			color = libtcod.Color(r,g,b)
		return color
コード例 #6
0
def test_map():
    map = libtcodpy.map_new(16, 16)
    assert libtcodpy.map_get_width(map) == 16
    assert libtcodpy.map_get_height(map) == 16
    libtcodpy.map_copy(map, map)
    libtcodpy.map_clear(map)
    libtcodpy.map_set_properties(map, 0, 0, True, True)
    assert libtcodpy.map_is_transparent(map, 0, 0)
    assert libtcodpy.map_is_walkable(map, 0, 0)
    libtcodpy.map_is_in_fov(map, 0, 0)
    libtcodpy.map_delete(map)
コード例 #7
0
 def print_walkable_map(self):
     """
     Prints a map of where this entity is allowed to walk.
     """
     for y in range(libtcod.map_get_height(self.dungeon_map)):
         line = ""
         for x in range(libtcod.map_get_width(self.dungeon_map)):
             if libtcod.map_is_walkable(self.dungeon_map, x, y):
                 line += " "
             else:
                 line += "#"
         print(line)
コード例 #8
0
ファイル: dungeonmask.py プロジェクト: co/TheLastRogue
 def print_walkable_map(self):
     """
     Prints a map of where this entity is allowed to walk.
     """
     for y in range(libtcod.map_get_height(self.dungeon_map)):
         line = ""
         for x in range(libtcod.map_get_width(self.dungeon_map)):
             if libtcod.map_is_walkable(self.dungeon_map, x, y):
                 line += " "
             else:
                 line += "#"
         print(line)
コード例 #9
0
ファイル: Engine.py プロジェクト: GuiWong/-DemonHunter-python
    def select(self):

        assert self.selected_tile
        x, y = self.selected_tile
        unit = self.get_tile_occupant(x, y)
        if unit:
            if self.is_targetable(unit):
                self.select_target(unit)
            elif self.is_selectable(unit):
                self.select_unit(unit)
        else:
            if self.selected_unit and self.can_reach(
            ) and self.selected_action == 0:
                if libtcod.map_is_walkable(self.path_map, x, y):
                    self.select_target(self.selected_tile)
コード例 #10
0
ファイル: whereami.py プロジェクト: Alberdi/assorted
def draw_map(m, width, height):
  global player_x, player_y
  key = libtcod.Key()
  mouse = libtcod.Mouse()
  libtcod.sys_check_for_event(libtcod.EVENT_ANY, key, mouse)
  libtcod.map_compute_fov(m, player_x, player_y)
  for x in range(width):
    for y in range(height):
      if libtcod.map_is_in_fov(m, x, y):
        if libtcod.map_is_walkable(m, x, y):
          char = '.'
        else:
          char = '#'
      else:
        char = ' '
      if (mouse.cx, mouse.cy) == (x, y):
        bg = libtcod.blue
      else:
        bg = libtcod.black
      libtcod.console_put_char_ex(0, x, y, char, libtcod.white, bg)
コード例 #11
0
ファイル: myfirstrl.py プロジェクト: tutoringsteve/firstrl
def cast_magic_map():
    global fov_recompute
    # magic mapping marks the map as revealed, as if you had been to all the squares before.
    message("Your mind's eye opens wide, and the surroundings feel somehow familiar to you.", color=libtcod.white)
    libtcod.map_compute_fov(fov_map, player.x, player.y, 9999, FOV_LIGHT_WALLS, FOV_ALGO)
    for y in xrange(MAP_HEIGHT):
        for x in xrange(MAP_WIDTH):
            if libtcod.map_is_walkable(fov_map, x, y):
                # flagging adjacent tiles so that the walls are also visible
                tile_map[x - 1][y - 1].explored = True
                tile_map[x - 1][y].explored = True
                tile_map[x - 1][y + 1].explored = True
                tile_map[x][y - 1].explored = True
                tile_map[x][y].explored = True
                tile_map[x][y + 1].explored = True
                tile_map[x + 1][y - 1].explored = True
                tile_map[x + 1][y].explored = True
                tile_map[x + 1][y + 1].explored = True
    fov_recompute = True
    draw_map_panel()
    libtcod.console_flush()
コード例 #12
0
def cast_magic_map():
    global fov_recompute
    # magic mapping marks the map as revealed, as if you had been to all the squares before.
    message(
        "Your mind's eye opens wide, and the surroundings feel somehow familiar to you.",
        color=libtcod.white)
    libtcod.map_compute_fov(fov_map, player.x, player.y, 9999, FOV_LIGHT_WALLS,
                            FOV_ALGO)
    for y in xrange(MAP_HEIGHT):
        for x in xrange(MAP_WIDTH):
            if libtcod.map_is_walkable(fov_map, x, y):
                # flagging adjacent tiles so that the walls are also visible
                tile_map[x - 1][y - 1].explored = True
                tile_map[x - 1][y].explored = True
                tile_map[x - 1][y + 1].explored = True
                tile_map[x][y - 1].explored = True
                tile_map[x][y].explored = True
                tile_map[x][y + 1].explored = True
                tile_map[x + 1][y - 1].explored = True
                tile_map[x + 1][y].explored = True
                tile_map[x + 1][y + 1].explored = True
    fov_recompute = True
    draw_map_panel()
    libtcod.console_flush()
コード例 #13
0
ファイル: snake.py プロジェクト: freevryheid/snake
     if tcod.path_compute(path, snake[0].x, snake[0].y, pathx, pathy):
         #x, y = tcod.path_get(path, 0)
         x, y = tcod.path_walk(path, False)
         if x is not None:
             speed = [x - snake[0].x, y - snake[0].y]
         else:
             found = False
     # no path
     else:
         # you're f****d
         found = False
 if not found:
     # no snack on grid (yet?)
     x = snake[0].x + speed[0]
     y = snake[0].y + speed[1]
     if not tcod.map_is_walkable(grid, x, y):
         # try up
         speed = [0, -1]
         x = snake[0].x + speed[0]
         y = snake[0].y + speed[1]
         if not tcod.map_is_walkable(grid, x, y):
             # try down
             speed = [0, 1]
             x = snake[0].x + speed[0]
             y = snake[0].y + speed[1]
             if not tcod.map_is_walkable(grid, x, y):
                 # try left
                 speed = [-1, 0]
                 x = snake[0].x + speed[0]
                 y = snake[0].y + speed[1]
                 if not tcod.map_is_walkable(grid, x, y):
コード例 #14
0
 def callback(ox, oy, dx, dy, user_data):
     if libtcodpy.map_is_walkable(map_, dx, dy):
         return 1
     return 0
コード例 #15
0
ファイル: FovOLD.py プロジェクト: joekane/DeepFriedSuperNova
def is_blocked(pos):
    return not libtcod.map_is_walkable(fov_map, pos[0], pos[1])
コード例 #16
0
 def checkWalkable(self, x, y):
     return libtcod.map_is_walkable(self.map, x, y)
コード例 #17
0
ファイル: map.py プロジェクト: fiddlerwoaroof/new_rl
	def is_passable(self, coord):
		return tc.map_is_walkable(self.base_map, *coord)
コード例 #18
0
ファイル: main.py プロジェクト: fiddlerwoaroof/normal_map
	def get_walkable(self, level, x,y):
		fovmap = self.get_fovmap(level)
		return libtcod.map_is_walkable(fovmap,x,y)
コード例 #19
0
ファイル: game.py プロジェクト: bope/libtcod-test
 def is_walkable(self, x, y):
     return tcod.map_is_walkable(self.fov, x, y)