示例#1
0
Destructible::Destructible(const std::string& name, int x, int y, DestructibleType type) :
  Detector(CollisionMode::COLLISION_NONE | CollisionMode::COLLISION_CENTER,
	 name, x, y, 16, 16),
  type(type) {
	create_sprite(get_animation_set_id());
	set_bounding_box_from_sprite();
}
示例#2
0
/**
 * \brief Creates the sprite of this pickable item,
 * depending on its subtype.
 *
 * Pickable items represented with two sprites:
 * the item itself and, for some items, its shadow.
 */
void Pickable::initialize_sprites() {

  // Shadow sprite.
  delete shadow_sprite;
  EquipmentItem& item = treasure.get_item();
  const std::string& animation = item.get_shadow();

  bool has_shadow = false;
  if (!animation.empty()) {
    shadow_sprite = new Sprite("entities/shadow");
    has_shadow = shadow_sprite->has_animation(animation);
  }

  if (!has_shadow) {
    // No shadow or no such shadow animation.
    delete shadow_sprite;
    shadow_sprite = NULL;
  }
  else {
    shadow_sprite->set_current_animation(animation);
  }

  // Main sprite.
  create_sprite("entities/items");
  Sprite& item_sprite = get_sprite();
  item_sprite.set_current_animation(treasure.get_item_name());
  int direction = treasure.get_variant() - 1;
  if (direction < 0 || direction >= item_sprite.get_nb_directions()) {
    Debug::error(StringConcat() << 
        "Pickable treasure '" << treasure.get_item_name() << "' has variant "
        << treasure.get_variant()
        << " but sprite 'entities/items' has only "
        << item_sprite.get_nb_directions() << " variant(s) in animation '"
        << treasure.get_item_name() << "'");
    direction = 0;  // Fallback.
  }
  item_sprite.set_current_direction(direction);
  item_sprite.enable_pixel_collisions();

  // Set the origin point and the size of the entity.
  set_bounding_box_from_sprite();

  uint32_t now = System::now();

  if (falling_height != FALLING_NONE) {
    allow_pick_date = now + 700;  // The player will be allowed to take the item after 0.7 seconds.
    can_be_picked = false;
  }
  else {
    can_be_picked = true;
  }

  // Initialize the item removal.
  if (will_disappear) {
    blink_date = now + 8000;       // The item blinks after 8s.
    disappear_date = now + 10000;  // The item disappears after 10s.
  }
}
示例#3
0
/**
 * @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();
  }
}
示例#4
0
/**
 * @brief Creates a boomerang.
 * @param hero the hero
 * @param max_distance maximum distance of the movement in pixels
 * @param speed speed of the movement in pixels per second
 * @param angle the angle of the boomerang trajectory in radians
 * @param sprite_name animation set id representing the boomerang
 */
Boomerang::Boomerang(Hero& hero, int max_distance, int speed, double angle,
    const std::string& sprite_name):
  MapEntity(),
  hero(hero),
  has_to_go_back(false),
  going_back(false),
  speed(speed) {

  // initialize the entity
  set_layer(hero.get_layer());
  create_sprite(sprite_name);
  set_bounding_box_from_sprite();

  int hero_x = hero.get_top_left_x();
  int hero_y = hero.get_top_left_y();
  switch (hero.get_animation_direction()) {

    case 0:
      set_xy(hero_x + 24, hero_y + 8);
      break;

    case 1:
      set_xy(hero_x + 8, hero_y - 8);
      break;

    case 2:
      set_xy(hero_x - 8, hero_y + 8);
      break;

    case 3:
      set_xy(hero_x + 8, hero_y + 24);
      break;

  }

  initial_coords.set_xy(get_xy());

  StraightMovement* movement = new StraightMovement(false, false);
  movement->set_speed(speed);
  movement->set_angle(angle);
  movement->set_max_distance(max_distance);
  set_movement(movement);

  next_sound_date = System::now();
}
示例#5
0
文件: Arrow.cpp 项目: ElAleyo/solarus
/**
 * \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;
}