Ejemplo n.º 1
0
class Player():
    MOVE_OFFSET = {
        Direction.North: Vector2D(0, 1),
        Direction.East: Vector2D(1, 0),
        Direction.South: Vector2D(0, -1),
        Direction.West: Vector2D(-1, 0) }

    def __init__(self, world):
        width, height = world.get_map_size()
        self.position = Vector2D(width // 2, height // 2)
        self.icon = "@"

        self.hp = 10
        self.max_hp = 10

        self.power = 10
        self.max_power = 10

    def display_stats(self):
        view.putcln("{bm}hp{}:" + "\t{}/{}".format(self.hp, self.max_hp))
        view.putcln("{by}power{}:" + "\t{}/{}".format(self.power, self.max_power))

    # This function is meant to scan the environment and use up a bit of power.
    def full_scan(self):
        pass
        self.power -= 10

    def weak_scan(self, level=1):
        pass
        self.power -= level

    def move(self, direction):
        self.position += Player.MOVE_OFFSET[direction]
        print(self.position)
Ejemplo n.º 2
0
 def get_area(self, pos, size):
     map_buf = Buffer2D(size)
     bot, top = pos.y - size.y // 2, pos.y + size.y // 2
     left, right = pos.x - size.x // 2, pos.x + size.x // 2
     for y in range(bot, top):
         for x in range(left, right):
             detail = TileDetail.Map[self.detail_grid.get_else(
                 Vector2D(x, y), TileDetail.Void)]
             tile_txt = detail
             map_buf.set(Vector2D(x - left, y - bot),
                         tile_txt)  # normalized coordinates
     return map_buf
Ejemplo n.º 3
0
 def get_area_color(self, pos, size):
     map_buf = Buffer2D(size)
     bot, top = pos.y - size.y // 2, pos.y + size.y // 2
     left, right = pos.x - size.x // 2, pos.x + size.x // 2
     for y in range(bot, top):
         for x in range(left, right):
             material = TileMaterial.Map[self.mat_grid.get_else(
                 Vector2D(x, y), "none")]
             detail = TileDetail.Map[self.detail_grid.get_else(
                 Vector2D(x, y), TileDetail.Void)]
             tile_txt = view.color(detail, material)
             map_buf.set(Vector2D(x - left, y - bot), tile_txt)
     return map_buf
Ejemplo n.º 4
0
    def display_scanned_map(self):
        view.putln("Displaying Scanned Map: ")

        map_buf = self.terrain.get_area_color(self.player.position, view.Size)

        center = Vector2D(view.Size.x // 2, view.Size.y // 2)
        map_buf.set(center, self.player.icon)
        view.put(map_buf)
Ejemplo n.º 5
0
    def __init__(self, world):
        width, height = world.get_map_size()
        self.position = Vector2D(width // 2, height // 2)
        self.icon = "@"

        self.hp = 10
        self.max_hp = 10

        self.power = 10
        self.max_power = 10
Ejemplo n.º 6
0
    def _generate_map(self, size):
        height_list = [1 for _ in range(size.x * size.y)]
        self.height_grid = Matrix2D.from_list(size, height_list)

        detail_list = [
            TileDetail.Rock if randint(0, 10) > 8 else TileDetail.Ground
            for _ in range(size.x * size.y)
        ]
        self.detail_grid = Matrix2D.from_list(size, detail_list)

        self.mat_grid = Matrix2D(size, TileMaterial.MoonRock)

        # 1 vent for each 10sq meters +- 2 ~ TODO: update to 100 sq meters or larger.
        geothermal_vent_dispersion_area = 10 * 10
        num_geothermal_vents = randint_around(
            size.x * size.y // geothermal_vent_dispersion_area, 2)
        for _ in range(0, num_geothermal_vents):
            x, y = randint(0, size.x - 1), randint(0, size.y - 1)
            self.mat_grid.set(Vector2D(x, y), TileMaterial.GeothermalVent)

        pass
Ejemplo n.º 7
0
 def display(self):
     width, height = self.grid.size
     for y in range(0, height):
         for x in range(0, width):
             view.put(self.get_tile(Vector2D(x, y)), end=" ")
         view.newline()
Ejemplo n.º 8
0
 def __init__(self):
     self.SIZE = Vector2D(100, 100)
     self._generate_map(self.SIZE)
Ejemplo n.º 9
0
    "_y",
    "_b",
    "_m",
    "_c",
    "_w",
    "_bk",
    "_br",
    "_bg",
    "_by",
    "_bb",
    "_bm",
    "_bc",
    "_bw",
}

Size = Vector2D(20, 10)

# ----------- Local Variables ----------- #

_VALID_COLOURS = "|".join(CURSES_COLOUR_CODES.keys())
_colour_pattern = r'(\{(?:' + _VALID_COLOURS + r')\})'
_colour_pattern = re.compile(_colour_pattern)

# ----------- Colour functions ----------- #


# parses a color tokens in a string and puts it all on the same line
def putcolor(window, txt):
    token_list = re.split(_colour_pattern, txt)
    state = []
    for token in token_list[1:-1]: