void SectorParser::create_sector() { auto tileset = TileManager::current()->get_tileset(m_sector.level->get_tileset()); bool worldmap = Editor::current() ? Editor::current()->get_worldmap_mode() : false; if (!worldmap) { auto background = std::make_shared<Background>(); background->set_images(DEFAULT_BG_TOP, DEFAULT_BG_MIDDLE, DEFAULT_BG_BOTTOM); background->set_speed(0.5); m_sector.add_object(background); auto bkgrd = std::make_shared<TileMap>(tileset); bkgrd->resize(100, 35); bkgrd->set_layer(-100); bkgrd->set_solid(false); m_sector.add_object(bkgrd); auto frgrd = std::make_shared<TileMap>(tileset); frgrd->resize(100, 35); frgrd->set_layer(100); frgrd->set_solid(false); m_sector.add_object(frgrd); } auto intact = std::make_shared<TileMap>(tileset); if (worldmap) { intact->resize(100, 100, 9); } else { intact->resize(100, 35, 0); } intact->set_layer(0); intact->set_solid(true); m_sector.add_object(intact); auto spawn_point = std::make_shared<SpawnPoint>(); spawn_point->name = "main"; spawn_point->pos = Vector(64, 480); m_sector.spawnpoints.push_back(spawn_point); if (worldmap) { GameObjectPtr spawn_point_marker = std::make_shared<worldmap_editor::WorldmapSpawnPoint>("main", Vector(4, 4)); m_sector.add_object(spawn_point_marker); } else { GameObjectPtr spawn_point_marker = std::make_shared<SpawnPointMarker>( spawn_point.get() ); m_sector.add_object(spawn_point_marker); } auto camera = std::make_shared<Camera>(&m_sector, "Camera"); m_sector.add_object(camera); m_sector.update_game_objects(); }
/** * @brief Creates a carried item (i.e. an item carried by the hero). * @param hero the hero who is lifting the item to be created * @param original_entity the entity that will be replaced by this carried item * (its coordinates, size and origin will be copied) * @param animation_set_id name of the animation set for the sprite to create * @param destruction_sound_id name of the sound to play when this item is destroyed * (or an empty string) * @param damage_on_enemies damage received by an enemy if the item is thrown on him * (possibly 0) * @param explosion_date date of the explosion if the item should explode, * or 0 if the item does not explode */ CarriedItem::CarriedItem(Hero& hero, MapEntity& original_entity, const std::string& animation_set_id, const std::string& destruction_sound_id, int damage_on_enemies, uint32_t explosion_date): MapEntity(), hero(hero), is_lifting(true), is_throwing(false), is_breaking(false), break_on_intermediate_layer(false) { // put the item on the hero's layer set_layer(hero.get_layer()); // align correctly the item with the hero int direction = hero.get_animation_direction(); if (direction % 2 == 0) { set_xy(original_entity.get_x(), hero.get_y()); } else { set_xy(hero.get_x(), original_entity.get_y()); } set_origin(original_entity.get_origin()); set_size(original_entity.get_size()); // create the lift movement and the sprite PixelMovement *movement = new PixelMovement(lifting_trajectories[direction], 100, false, true); create_sprite(animation_set_id); get_sprite().set_current_animation("stopped"); set_movement(movement); // create the breaking sound this->destruction_sound_id = destruction_sound_id; // create the shadow (not visible yet) this->shadow_sprite = new Sprite("entities/shadow"); this->shadow_sprite->set_current_animation("big"); // damage on enemies this->damage_on_enemies = damage_on_enemies; // explosion this->explosion_date = explosion_date; }
/** * @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(); }
void handle_state(monitor_t *m, desktop_t *d, node_t *n, xcb_atom_t state, unsigned int action) { if (state == ewmh->_NET_WM_STATE_FULLSCREEN) { if (action == XCB_EWMH_WM_STATE_ADD) { set_state(m, d, n, STATE_FULLSCREEN); } else if (action == XCB_EWMH_WM_STATE_REMOVE) { if (n->client->state == STATE_FULLSCREEN) { set_state(m, d, n, n->client->last_state); } } else if (action == XCB_EWMH_WM_STATE_TOGGLE) { set_state(m, d, n, IS_FULLSCREEN(n->client) ? n->client->last_state : STATE_FULLSCREEN); } arrange(m, d); } else if (state == ewmh->_NET_WM_STATE_BELOW) { if (action == XCB_EWMH_WM_STATE_ADD) { set_layer(m, d, n, LAYER_BELOW); } else if (action == XCB_EWMH_WM_STATE_REMOVE) { if (n->client->layer == LAYER_BELOW) { set_layer(m, d, n, n->client->last_layer); } } else if (action == XCB_EWMH_WM_STATE_TOGGLE) { set_layer(m, d, n, n->client->layer == LAYER_BELOW ? n->client->last_layer : LAYER_BELOW); } } else if (state == ewmh->_NET_WM_STATE_ABOVE) { if (action == XCB_EWMH_WM_STATE_ADD) { set_layer(m, d, n, LAYER_ABOVE); } else if (action == XCB_EWMH_WM_STATE_REMOVE) { if (n->client->layer == LAYER_ABOVE) { set_layer(m, d, n, n->client->last_layer); } } else if (action == XCB_EWMH_WM_STATE_TOGGLE) { set_layer(m, d, n, n->client->layer == LAYER_ABOVE ? n->client->last_layer : LAYER_ABOVE); } } else if (state == ewmh->_NET_WM_STATE_STICKY) { if (action == XCB_EWMH_WM_STATE_ADD) { set_sticky(m, d, n, true); } else if (action == XCB_EWMH_WM_STATE_REMOVE) { set_sticky(m, d, n, false); } else if (action == XCB_EWMH_WM_STATE_TOGGLE) { set_sticky(m, d, n, !n->sticky); } } else if (state == ewmh->_NET_WM_STATE_DEMANDS_ATTENTION) { if (action == XCB_EWMH_WM_STATE_ADD) { set_urgent(m, d, n, true); } else if (action == XCB_EWMH_WM_STATE_REMOVE) { set_urgent(m, d, n, false); } else if (action == XCB_EWMH_WM_STATE_TOGGLE) { set_urgent(m, d, n, !n->client->urgent); } } }
/** * \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; }
/** * @brief Creates a hookshot. * @param hero the hero */ Hookshot::Hookshot(Hero &hero): next_sound_date(System::now()), has_to_go_back(false), going_back(false), entity_reached(NULL), link_sprite("entities/hookshot") { // initialize the entity int direction = hero.get_animation_direction(); set_layer(hero.get_layer()); create_sprite("entities/hookshot", true); get_sprite().set_current_direction(direction); link_sprite.set_current_animation("link"); set_size(16, 16); set_origin(8, 13); set_xy(hero.get_xy()); std::string path = " "; path[0] = '0' + (direction * 2); Movement *movement = new PathMovement(path, 192, true, false, false); set_movement(movement); }