Exemplo n.º 1
0
bool Player::set_hit(Object *object)
{
    bool result = false;

    if (!m_invisible) {
        // TODO: Check if player hp is above zero instead
        result = Actor::set_hit(object);
        if (result) {

            set_lock_direction(true);

            // Move backwards and upwards
            if (m_dir == Right) {
                set_speed(-get_attribute("move_speed"),
                          -get_attribute("jump_speed"));
            }
            else {
                set_speed(get_attribute("move_speed"),
                          -get_attribute("jump_speed"));
            }

            // Make player invisible for a certain time
            set_invisible(true);
        }
    }

    return result;
}
Exemplo n.º 2
0
bool Player::set_hit(Object *object, Status *status)
{
    bool result = false;

    if (!m_invisible) {
        result = Actor::set_hit(object);
        if (result) {

            set_lock_direction(true);

            // Move backwards and upwards
            if (m_dir == Right) {
                set_vx(-get_attribute("move_speed"));
            }
            else {
                set_vx(get_attribute("move_speed"));
            }

            if (m_in_water) {
                set_vy(-get_attribute("water_jump_speed"));
            }
            else {
                set_vy(-get_attribute("jump_speed"));
            }
            m_hit_ground = false;

            Monster *monster = (Monster *) object;
            if (status->set_hit(monster->get_attribute("ap")) &&
                !status->use_potion()) {
                set_invisible(true);
                set_solid(false);
                set_perish(false);
            }
            else {
                // Make player invisible for a certain time
                set_invisible(true);
            }
        }
    }

    return result;
}
Exemplo n.º 3
0
void Actor::set_perish(bool invisible)
{
    set_invisible(invisible);
    switch(m_dir) {
        case Right:
            m_frame = get_attribute("perish_start");
            break;

        case Left:
            m_frame = get_attribute("perish_end");
            break;

        default:
            break;
    }
    set_action(HitPerish);
}
Exemplo n.º 4
0
void Actor::set_perish()
{
    set_invisible(true);
    switch(m_dir) {
        case Right:
            m_frame = get_attribute("right_perish");
            break;

        case Left:
            m_frame = get_attribute("left_perish");
            break;

        default:
            break;
    }
    m_hit = HitPerish;
}
Exemplo n.º 5
0
void Player::player_move(Map *map)
{
    Actor::move(map);

    check_water(map);

    int input = get_input();

    const Tmx::Tileset *tileset = map->get_tileset(0);
    const Tmx::PropertySet prop = tileset->GetProperties();

    // Check if on catapult
    int catid = prop.GetNumericProperty("catapult");
    if (catid && check_below(map, 1, catid, catid) == 0) {
        if (input & PRESS_RIGHT) {
            set_vx(get_attribute("move_speed"));
        }
        else if (input & PRESS_LEFT) {
            set_vx(-get_attribute("move_speed"));
        }
        set_jump(map, true);
    }

    switch(m_action) {
        case Still:
            set_vx(0);

        case Move:
            // Check for crouch or move
            if (input & PRESS_DOWN) {
                set_action(Crouch);
            }
            else if (input & PRESS_RIGHT) {
                animate_move();
                set_action(Move);
                set_vx(get_attribute("move_speed"));
            }
            else if (input & PRESS_LEFT) {
                animate_move();
                set_action(Move);
                set_vx(-get_attribute("move_speed"));
            }
            else {
                set_action(Still);
            }

            // Check for jump
            if (input & PRESS_JUMP) {
                if (m_jump_ready && m_hit_ground) {
                    if (input & PRESS_RIGHT) {
                        set_vx(get_attribute("move_speed"));
                    }
                    else if (input & PRESS_LEFT) {
                        set_vx(-get_attribute("move_speed"));
                    }
                    set_jump(map, false);
                }
                m_jump_ready = false;
            }
            else {
                // Restore jump lock
                m_jump_ready = true;
            }

            Body::move(map);
            if (get_fall()) {
                set_action(Fall);
            }
            break;

        case Fall:
            // Check for change of direction during fall
            if (input & PRESS_RIGHT) {
                set_vx(get_attribute("move_speed"));
            }
            else if (input & PRESS_LEFT) {
                set_vx(-get_attribute("move_speed"));
            }

            Body::move(map);
            if (!get_fall()) {
                m_hit_ground = true;
                set_action(Still);
            }
            break;

        case Jump:
        case Catapult:
            Body::move(map);
            if (get_fall()) {
                set_action(Fall);
            }
            break;

        case Crouch:
            set_vx(0);
            Body::move(map);
            if (!get_fall()) {
                m_hit_ground = true;
            }

            if (!(input & PRESS_DOWN)) {
                set_action(Still);
            }
            break;

        case Hit:
            if (m_hit_timer.expired(get_attribute("hit_time"))) {
                set_vx(0);
                set_lock_direction(false);
                reset_hit();
            }
            Body::move(map);
            break;

        case HitPerish:
            animate_perish();
            set_speed(0, -get_attribute("move_speed"));
            Body::move(map);
            if (m_y < -get_image_height()) {
                set_solid(true);
                set_invisible(false);
                set_action(HitPerished);
            }
            break;

        case Attack:
        case AttackLow:
            if (animate_attack()) {
                reset_attack();
            }
            Body::move(map);
            if (!get_fall()) {
                m_hit_ground = true;
            }
            break;

        default:
            Body::move(map);
            break;
    }
}
Exemplo n.º 6
0
void Actor::move(Map *map)
{
    if (m_invisible_timer.expired(get_attribute("invisible_time"))) {
        set_invisible(false);
    }
}