/** * \brief Creates an arrow. * \param hero The hero. */ Arrow::Arrow(const Hero& hero): Entity("", 0, hero.get_layer(), Point(0, 0), Size(0, 0)), hero(hero) { // initialize the entity int direction = hero.get_animation_direction(); create_sprite("entities/arrow", true); get_sprite().set_current_direction(direction); set_drawn_in_y_order(true); if (direction % 2 == 0) { // Horizontal. set_size(16, 8); set_origin(8, 4); } else { // Vertical. set_size(8, 16); set_origin(4, 8); } set_xy(hero.get_center_point()); notify_position_changed(); std::string path = " "; path[0] = '0' + (direction * 2); set_movement(std::make_shared<PathMovement>( path, 192, true, false, false )); disappear_date = System::now() + 10000; stop_now = false; entity_reached = nullptr; }
/** * @brief Sets the position of the entity or the point controlled by this movement. * @param x the new x position * @param y the new y position */ void Movement::set_xy(int x, int y) { if (entity != NULL) { entity->set_xy(x, y); notify_position_changed(); } else { this->xy.set_xy(x, y); } last_move_date = System::now(); }
/** * \brief Resets the block at its initial position. */ void Block::reset() { if (get_movement() != nullptr) { // the block was being pushed or pulled by the hero clear_movement(); when_can_move = System::now() + moving_delay; } last_position = initial_position; this->maximum_moves = initial_maximum_moves; set_xy(initial_position); notify_position_changed(); }
/** * @brief Computes the position of the object controlled by this movement. * * This function should be called whenever the angle, the radius or the center changes. */ void CircleMovement::recompute_position() { Rectangle center = this->center_point; if (center_entity != NULL) { center.add_xy(center_entity->get_xy()); } const Rectangle &xy = Geometry::get_xy(center, Geometry::degrees_to_radians(current_angle), current_radius); if (get_entity() == NULL || !test_collision_with_obstacles(xy.get_x() - get_entity()->get_x(), xy.get_y() - get_entity()->get_y())) { set_xy(xy); notify_position_changed(); } else { notify_obstacle_reached(); } }
/** * \brief Computes the position of the object controlled by this movement. * * This function should be called whenever the angle, the radius or the center changes. */ void CircleMovement::recompute_position() { Point center = this->center_point; if (center_entity != nullptr) { center += center_entity->get_xy(); } Point xy = Geometry::get_xy(center, Geometry::degrees_to_radians(current_angle), current_radius); if (get_entity() == nullptr || !test_collision_with_obstacles(xy - get_entity()->get_xy())) { set_xy(xy); notify_position_changed(); } else { notify_obstacle_reached(); } }
/** * \brief Sets the position of the object controlled by this movement. * \param xy The new coordinates. */ void Movement::set_xy(const Point& xy) { if (entity != nullptr) { // The object controlled is a map entity. entity->set_xy(xy); } else if (drawable != nullptr) { // The object controlled is a drawable. drawable->set_xy(xy); } // The object controlled is a point. this->xy = xy; notify_position_changed(); last_move_date = System::now(); }