/** * \brief Creates an arrow. * \param hero The hero. */ Arrow::Arrow(const Hero& hero): MapEntity("", 0, hero.get_layer(), 0, 0, 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()); set_optimization_distance(0); // Make the arrow continue outside the screen until disappear_date. std::string path = " "; path[0] = '0' + (direction * 2); Movement* movement = new PathMovement(path, 192, true, false, false); set_movement(movement); disappear_date = System::now() + 10000; stop_now = false; entity_reached = NULL; }
/** * \brief Constructor. * * Creates a bomb. * * \param name Unique name identifying the entity on the map or an empty string. * \param layer layer of the entity to create * \param x x coordinate of the entity to create * \param y y coordinate of the entity to create */ Bomb::Bomb(const std::string& name, Layer layer, int x, int y): Detector(COLLISION_FACING_POINT, name, layer, x, y, 16, 16), explosion_date(System::now() + 6000) { create_sprite("entities/bomb"); get_sprite().enable_pixel_collisions(); set_size(16, 16); set_origin(8, 13); set_optimization_distance(0); // make the bomb explode even if the hero runs far away }
/** * \brief Creates a new crystal. * \param name name of the entity to create * \param layer layer of the entity to create on the map * \param x x coordinate of the entity to create * \param y y coordinate of the entity to create */ Crystal::Crystal(const std::string& name, Layer layer, int x, int y): Detector(COLLISION_SPRITE | COLLISION_RECTANGLE | COLLISION_FACING_POINT, name, layer, x, y, 16, 16), state(false), next_possible_hit_date(System::now()) { set_origin(8, 13); set_optimization_distance(2000); // Because of bombs and arrows on the crystal. create_sprite("entities/crystal", true); star_sprite = new Sprite("entities/star"); twinkle(); }
/** * \brief Creates a new crystal. * \param name name of the entity to create * \param layer layer of the entity to create on the map * \param xy Coordinates of the entity to create. */ Crystal::Crystal(const std::string& name, Layer layer, const Point& xy): Detector(COLLISION_SPRITE | COLLISION_OVERLAPPING | COLLISION_FACING, name, layer, xy, Size(16, 16)), state(false), next_possible_hit_date(System::now()) { set_origin(8, 13); set_optimization_distance(2000); // Because of bombs and arrows on the crystal. create_sprite("entities/crystal", true); star_sprite = std::make_shared<Sprite>("entities/star"); twinkle(); }
/** * @brief Creates an explosion. * @param layer layer of the explosion * @param xy coordinates of the center of the explosion * @param with_damages true to hurt the hero and the enemies */ Explosion::Explosion(Layer layer, const Rectangle &xy, bool with_damages): Detector(COLLISION_SPRITE | COLLISION_RECTANGLE, "", layer, xy.get_x(), xy.get_y(), 48, 48) { // initialize the entity create_sprite("entities/explosion"); set_optimization_distance(2000); // because of placing a bomb on a switch get_sprite().enable_pixel_collisions(); if (with_damages) { set_bounding_box_from_sprite(); } }
/** * \brief Creates an explosion. * \param name Name identifying the entity on the map or an empty string. * \param layer layer of the explosion * \param xy coordinates of the center of the explosion * \param with_damage true to hurt the hero and the enemies */ Explosion::Explosion(const std::string& name, Layer layer, const Point& xy, bool with_damage): Detector(COLLISION_SPRITE | COLLISION_OVERLAPPING, name, layer, xy, Size(48, 48)) { // initialize the entity create_sprite("entities/explosion"); set_optimization_distance(2000); // because of placing a bomb on a switch get_sprite().enable_pixel_collisions(); if (with_damage) { set_size(48, 48); set_origin(24, 24); } }
/** * \brief Creates an arrow. * \param hero the hero */ Arrow::Arrow(Hero& hero): hero(hero) { // initialize the entity int direction = hero.get_animation_direction(); set_layer(hero.get_layer()); create_sprite("entities/arrow", true); get_sprite().set_current_direction(direction); set_bounding_box_from_sprite(); set_xy(hero.get_center_point()); set_optimization_distance(0); // Make the arrow continue outside the screen until disappear_date. std::string path = " "; path[0] = '0' + (direction * 2); Movement *movement = new PathMovement(path, 192, true, false, false); set_movement(movement); disappear_date = System::now() + 10000; stop_now = false; entity_reached = NULL; }