예제 #1
0
    def remember_terrain(self, hunter):
        vd = self.hunter.vision_distance[hunter.engine.time_of_day]
        vision_map = vsmap.circle(vd)
        x_start = self.hunter.x - vd
        x_end = self.hunter.x + vd
        y_start = self.hunter.y - vd
        y_end = self.hunter.y + vd

        for y in range(y_start, y_end + 1):
            for x in range(x_start, x_end + 1):
                # This is confusing. Basic idea is to apply the vision map to the hunter's memory and the game map, but only
                # set "explored" to True, never to False i.e. don't let the corners of a circular vision map "unexplore" tiles.
                # And clamp everything so we dont accidentally affect the opposite side of the map.
                clamp_width = self.hunter.engine.game_map.width - 1
                clamp_height = self.hunter.engine.game_map.height - 1
                rel_x = math.clamp(x - x_start, 0, clamp_width)
                rel_y = math.clamp(y - y_start, 0, clamp_height)
                clmp_x = math.clamp(x, 0, clamp_width)
                clmp_y = math.clamp(y, 0, clamp_height)
                prev_visible = f"{clmp_x},{clmp_y}" in self.hunter.memory.map[
                    "explored-terrain"].keys() and self.hunter.memory.map[
                        "explored-terrain"][f"{clmp_x},{clmp_y}"]
                curr_visible = vision_map[rel_y][rel_x].visible
                self.hunter.memory.map["explored-terrain"][
                    f"{clmp_x},{clmp_y}"] = curr_visible or prev_visible

                if curr_visible or prev_visible:
                    self.hunter.engine.game_map.tiles[clmp_y][clmp_x].reveal()
예제 #2
0
    def clamp_coord(self, x, y):
        max_x = self.width - 1
        max_y = self.height - 1
        dest = Coord()
        dest.x = math.clamp(x, 0, max_x)
        dest.y = math.clamp(y, 0, max_y)

        return dest
예제 #3
0
    def curr_energy(self, curr_energy):
        self.__curr_energy = math.clamp(curr_energy, self.min_energy,
                                        self.max_energy)

        if self.curr_energy <= 0:
            self.apply_se_once(stfx.SleepDeprivation)
        elif self.curr_energy > 0:
            self.remove_se(stfx.SleepDeprivation)
예제 #4
0
    def curr_hunger(self, curr_hunger):
        self.__curr_hunger = math.clamp(curr_hunger, self.min_hunger,
                                        self.max_hunger)

        if self.curr_hunger <= 0:
            self.apply_se_once(stfx.Starvation)
        elif self.curr_hunger > 0:
            self.remove_se(stfx.Starvation)
예제 #5
0
    def curr_health(self, curr_health):
        self.__curr_health = math.clamp(curr_health, self.min_health,
                                        self.max_health)

        if self.alive and self.curr_health <= 0:
            self.die()