/** * \brief Updates this state. */ void Hero::FallingState::update() { State::update(); Hero& hero = get_hero(); if (!is_suspended() && get_sprites().is_animation_finished()) { // the hero has just finished falling Teletransporter* teletransporter = hero.get_delayed_teletransporter(); if (teletransporter != NULL) { // special hole with a teletransporter teletransporter->transport_hero(hero); } else { // normal hole that hurts the hero get_equipment().remove_life(2); hero.set_state(new BackToSolidGroundState(hero, true)); } } }
/** * @brief Updates this state. */ void Hero::StairsState::update() { State::update(); if (suspended) { return; } // first time: we play the sound and initialize if (phase == 0) { stairs.play_sound(way); next_phase_date = System::now() + 450; phase++; } // update the carried item if any if (carried_item != NULL) { carried_item->update(); } if (stairs.is_inside_floor()) { // inside a single floor: return to normal state as soon as the movement is finished if (hero.get_movement()->is_finished()) { if (way == Stairs::REVERSE_WAY) { get_entities().set_entity_layer(hero, LAYER_LOW); } hero.clear_movement(); if (carried_item == NULL) { hero.set_state(new FreeState(hero)); } else { hero.set_state(new CarryingState(hero, carried_item)); } } } else { // stairs between two different floors: more complicated HeroSprites &sprites = get_sprites(); if (hero.get_movement()->is_finished()) { hero.clear_movement(); if (carried_item == NULL) { hero.set_state(new FreeState(hero)); } else { hero.set_state(new CarryingState(hero, carried_item)); } if (way == Stairs::NORMAL_WAY) { // we are on the old floor: // there must be a teletransporter associated with these stairs, // otherwise the hero would get stuck into the walls Teletransporter *teletransporter = hero.get_delayed_teletransporter(); Debug::check_assertion(teletransporter != NULL, "Teletransporter expected with the stairs"); teletransporter->transport_hero(hero); } else { // we are on the new floor: everything is finished sprites.set_clipping_rectangle(); } } else { // movement not finished yet uint32_t now = System::now(); if (now >= next_phase_date) { phase++; next_phase_date += 350; // main movement direction corresponding to each animation direction while taking stairs static const int movement_directions[] = { 0, 0, 2, 4, 4, 4, 6, 0 }; int animation_direction = stairs.get_animation_direction(way); if (phase == 2) { // the first phase of the movement is finished if (animation_direction % 2 != 0) { // if the stairs are spiral, take a diagonal direction of animation sprites.set_animation_walking_diagonal(animation_direction); } else { // otherwise, take a usual direction sprites.set_animation_direction(animation_direction / 2); sprites.set_animation_walking_normal(); } } else if (phase == 3) { // the second phase of the movement (possibly diagonal) is finished sprites.set_animation_walking_normal(); if (way == Stairs::NORMAL_WAY) { // on the old floor, take a direction towards the next floor sprites.set_animation_direction(movement_directions[animation_direction] / 2); } else { // on the new floor, take the opposite direction from the stairs sprites.set_animation_direction((stairs.get_direction() + 2) % 4); } } } } } }