Example #1
0
    def compute_movement(self):
        if self._has_movement:
            current = time.time()

            if current - self._last_movement_time_stamp > 1.0 / self._speed:
                self._last_movement_time_stamp = current
                movement = Direction.as_vector(self._direction)
                self._position += movement
Example #2
0
    def has_all_neighbours(self, position, filter_terrain_list,
                           direction_list):
        for direction_vec in Direction.as_vector_list(direction_list):
            neighbour = position + direction_vec
            if not self.is_terrain(neighbour, filter_terrain_list):
                return False

        return True
Example #3
0
    def get_neighbour_list(self, position, filter_terrain_list,
                           direction_list):
        neighbour_list = []

        for direction_vec in Direction.as_vector_list(direction_list):
            neighbour = position + direction_vec
            if self.is_terrain(neighbour, filter_terrain_list):
                neighbour_list.append(neighbour)

        return neighbour_list
Example #4
0
    def _player_movement_request(self, player_movement_message, endpoint):
        player = self._check_player_for_event(endpoint)

        if not Direction.is_orthogonal(player_movement_message.direction):
            logger.error("Unexpected movement value from player '{}'".format(
                player.get_character()))
            self._output_queue.put(OutputPack("", endpoint))
            return

        control = player.get_control()
        if control:
            control.move(player_movement_message.direction)
Example #5
0
    def _generate_internal_walls(self):
        random_engine = random.Random(self._seed)

        available_coordinates_list = self.get_position_list_distance(
            [Terrain.EMPTY], GEN_MIN_BLOCK_DISTANCE)

        while 1 - GEN_WALL_PROPORTION < len(
                available_coordinates_list) / self.get_size():
            block_len_list = range(GEN_MIN_BLOCK_LEN, GEN_MAX_BLOCK_LEN)
            wall_size_list = random_engine.sample(
                block_len_list,
                random_engine.randrange(GEN_MIN_BLOCK_CHUNK,
                                        GEN_MAX_BLOCK_CHUNK))
            wall_direction = random_engine.choice(Direction.ORTHOGONAL_LIST)
            direction = wall_direction
            position = random_engine.choice(available_coordinates_list)
            self.set_at(position, Terrain.INTERNAL_WALL)

            for wall_size in wall_size_list:
                direction_vec = Direction.as_vector(direction)
                for i in range(0, wall_size):
                    new_position = position + direction_vec
                    if self.is_inside(
                            new_position) and self.has_all_neighbours_distance(
                                new_position, [Terrain.EMPTY],
                                GEN_MIN_BLOCK_DISTANCE, direction):
                        position = new_position
                        self.set_at(position, Terrain.INTERNAL_WALL)
                    else:
                        break

                direction = wall_direction if direction != wall_direction else random_engine.choice(
                    Direction.get_orthogonal_list(direction))

            available_coordinates_list = self.get_position_list_distance(
                [Terrain.EMPTY], GEN_MIN_BLOCK_DISTANCE)
Example #6
0
    def draw_entities(self, entity_list):
        pencil = self._screen.create_pencil(self.get_arena_origin())

        for entity in entity_list:
            if Direction.NONE != entity.direction:
                point = entity.position + Direction.as_vector(entity.direction)
                cursor, color = ("·", 240)

                if entity.character == self._player_character:
                    if self._skill_cast_try:
                        if self.is_terrain_blocked(point):
                            self._skill_cast_failure_cursor_counter = 5
                    if self._skill_cast_failure_cursor_counter > 0:
                        cursor, color = ("×", 124)
                        self._skill_cast_failure_cursor_counter -= 1

                pencil.draw(Vec2(point.x * 2, point.y), cursor, color,
                            TermPencil.Style.BOLD)

        for entity in entity_list:
            pencil.draw(Vec2(entity.position.x * 2, entity.position.y),
                        entity.character)
Example #7
0
 def get_direction_vec(self):
     return Direction.as_vector(self._direction)