Пример #1
0
void Walker::move(Map *map)
{
    Monster::move(map);

    switch(m_action) {
        case Still:
            set_action(Move);
            break;

        case Move:
            if (check_ahead(map)) {
                swap_move_dir();
            }

            if (m_dir == Right) {
                set_vx(get_attribute("move_speed"));
            }
            else {
                set_vx(-get_attribute("move_speed"));
            }
            animate_move();
            break;

        default:
            break;
    }

}
Пример #2
0
void Climber::move_climb(Map *map, int input)
{
    const Tmx::Tileset *tileset = map->get_tileset(0);
    const Tmx::PropertySet prop = tileset->GetProperties();
    int block_id = prop.GetNumericProperty("climb");

    if (!m_leave_ready && m_leave_timer.expired(c_leave_time)) {
        m_leave_ready = true;
    }

    switch (m_climb_dir) {
        case ClimbRight:
        case ClimbLeft:
            if (input & PRESS_JUMP) {
                if (m_leave_ready) {
                    leave_climb(map);
                }
            }
            else if (input & PRESS_DOWN) {
                animate_climb();
                set_action(Move);
                set_dir(Right);
                set_vy(check_ahead(map, get_attribute("move_speed"),
                                   block_id, block_id));
            }
            else if (input & PRESS_UP) {
                animate_climb();
                set_action(Move);
                set_dir(Left);
                set_vy(-check_ahead(map, get_attribute("move_speed"),
                                    block_id, block_id));
            }
            else {
                set_dir();
                set_action(Still);
                set_vy(0);
            }
            break;

        default:
            break;
    }

    Body::move(map);
}
Пример #3
0
bool Object::check_ahead(Map *map, int start, int end)
{
    bool result = false;
    int min_dx = check_ahead(map, m_dx, start, end);

    if (min_dx != m_dx) {
        m_dx = min_dx;
        result = true;
    }

    return result;
}
Пример #4
0
void Climber::move(Map *map)
{
    int input = get_input();

    if (m_climb_dir == ClimbNone && (m_action == Jump || m_action == Fall)) {
        const Tmx::Tileset *tileset = map->get_tileset(0);
        const Tmx::PropertySet prop = tileset->GetProperties();

        // Check if on climb block
        int block_id = prop.GetNumericProperty("climb");
        if (block_id) {
            if (m_dir == Right && (input & PRESS_RIGHT)) {
                if (check_ahead(map, 1, block_id, block_id) == 0) {
                    set_vx(0);
                    set_ay(0);
                    m_leave_ready = false;
                    m_climb_dir = ClimbRight;
                }
            }
            else if (m_dir == Left && (input & PRESS_LEFT)) {
                if (check_ahead(map, 1, block_id, block_id) == 0) {
                    set_vx(0);
                    set_ay(0);
                    m_leave_ready = false;
                    m_climb_dir = ClimbLeft;
                }
            }
        }
    }

    if (m_climb_dir == ClimbNone) {
        Knight::move(map);
    }
    else {
        move_climb(map, input);
    }
}
Пример #5
0
void Body::move(Map *map)
{
    float tw = float(map->get_tile_width());
    float th = float(map->get_tile_height());

    m_vx += m_ax;
    if (m_vx < -tw) {
        m_vx = -tw;
    }
    else if (m_vx > tw) {
        m_vx = tw;
    }

    m_vy += m_ay;
    if (m_vy < -th) {
        m_vy = -th;
    }
    else if (m_vy > th) {
        m_vy = th;
    }

    if (m_vx > 0.0f) {
        m_dx = int(m_vx);
        if (!m_lock_dir) {
            set_dir(Right);
            if (m_solid) {
                if (check_ahead(map)) {
                    m_vx = 0.0f;
                }
            }
        }
        else if (m_dir == Right) {
            if (m_solid) {
                if (check_ahead(map)) {
                    m_vx = 0.0f;
                }
            }
        }
        else if (m_dir == Left) {
            if (m_solid) {
                if (check_behind(map)) {
                    m_vx = 0.0f;
                }
            }
        }
        m_x += m_dx;
    }
    else if (m_vx < 0.0f) {
        m_dx = -int(m_vx);
        if (!m_lock_dir) {
            set_dir(Left);
            if (m_solid) {
                if (check_ahead(map)) {
                    m_vx = 0.0f;
                }
            }
        }
        else if (m_dir == Right) {
            if (m_solid) {
                if (check_behind(map)) {
                    m_vx = 0.0f;
                }
            }
        }
        else if (m_dir == Left) {
            if (m_solid) {
                if (check_ahead(map)) {
                    m_vx = 0.0f;
                }
            }
        }
        m_x -= m_dx;
    }
    else {
        set_dir(Keep);
        m_dx = 0;
    }

    if (m_vy > 0.0f) {
        m_dy = int(m_vy);
        if (m_solid) {
            if (check_below(map)) {
                m_vy = 0.0f;
            }
        }
        if (m_dy) {
            m_vert_dir = VerticalDown;
            m_y += m_dy;
        }
    }
    else if (m_vy < 0.0f) {
        m_dy = -int(m_vy);
        if (m_solid) {
            if (check_above(map)) {
                m_vy = 0.0f;
            }
        }
        if (m_dy) {
            m_vert_dir = VerticalUp;
            m_y -= m_dy;
        }
    }
    else {
        m_dy = 0;
    }

    if (!m_dy) {
        m_vert_dir = VerticalNone;
    }
}
Пример #6
0
void LockFlyer::move(Map *map)
{
    Monster::move(map);

    if (m_hit == HitOne) {
        if (m_hit_timer.expired(get_attribute("hit_time"))) {
            m_dx = 0;
            reset_hit();
        }
        else {
            // Move backwards
            m_dx = get_attribute("move_speed");

            // Check for collision with map
            check_behind(map);

            // Right of player
            if (get_reference() == Right) {
                m_x -= m_dx;
            }
            else {
                m_x += m_dx;
            }
        }
    }

    switch(m_action) {
        case Still:
            if (m_hit == HitNone) {
                if (m_attack_timer.check(get_attribute("attack_timer"))) {
                    const Sprite *spr = get_sprite();
                    int dist = get_attribute("attack_distance");
                    int x = m_xref - get_front();
                    int y = m_yref - (get_y() + spr->get_height() / 2);
                    if (x * x + y * y < dist * dist) {
                        m_attack_timer.reset();
                        set_move_dir();
                        m_lock_y = m_yref + spr->get_height() / 2;
                    }
                }
            }
            break;

        case Move:
            if (m_hit == HitNone) {
                const Sprite *spr = get_sprite();
                if (abs(m_lock_y - m_y) > get_attribute("move_speed")) {
                    if (m_y < m_lock_y) {
                        m_vertical_dir = VerticalDown;
                    }
                    else if (m_y > m_lock_y) {
                        m_vertical_dir = VerticalUp;
                    }
                }
                else {
                    m_vertical_dir = VerticalNone;
                }

                // Move
                if (m_vertical_dir == VerticalDown) {
                    m_dy = get_attribute("move_speed");
                    check_below(map);
                    if (!m_dy) {
                        set_action(Still);
                    }
                    else {
                        m_y += m_dy;
                    }
                }
                else if (m_vertical_dir == VerticalUp) {
                    m_dy = get_attribute("move_speed");
                    check_above(map);
                    if (!m_dy) {
                        set_action(Still);
                    }
                    else {
                        m_y -= m_dy;
                    }
                }
                else {
                    m_dx = get_attribute("move_speed");
                    face_reference(get_attribute("turn_width"));
                    check_ahead(map);
                    if (!m_dx) {
                        set_action(Still);
                    }
                    else {
                        if (m_dir == Right) {
                            m_x += m_dx;
                        }
                        else if (m_dir == Left) {
                            m_x -= m_dx;
                        }
                    }
                }
                animate_move();
            }
            break;

        default:
            break;
    }
}
Пример #7
0
void Player::player_move(Map *map)
{
    const Tmx::Tileset *tileset = map->get_tileset(0);
    const Tmx::PropertySet prop = tileset->GetProperties();

    // Check if under water
    int start = prop.GetNumericProperty("water_start");
    int end = prop.GetNumericProperty("water_end");
    if (start && check_ahead(map, 1, start, end) == 0) {
        if (!m_water_timer.expired(get_attribute("water_treshold"))) {
            return;
        }

        m_water_timer.reset();
    }

    // Check if on catapult
    int catid = prop.GetNumericProperty("catapult");
    if (catid && check_below(map, 1, catid, catid) == 0) {
        set_vy(int(-get_attribute("catapult_speed")));
        set_action(Jump);
    }

    Actor::move(map);
    set_ay(get_attribute("weight"));

    int input = get_input();
    switch(m_action) {
        case Still:
            set_vx(0);

        case Move:
            // Check for jump
            if (input & PRESS_JUMP) {
                if (m_jump_ready) {
                    m_jump_ready = false;
                    set_action(Jump);
                    if (input & PRESS_RIGHT) {
                        set_speed(get_attribute("jump_forward"),
                                  -get_attribute("jump_speed"));
                    }
                    else if (input & PRESS_LEFT) {
                        set_speed(-get_attribute("jump_forward"),
                                  -get_attribute("jump_speed"));
                    }
                    else {
                        set_vy(-get_attribute("jump_speed"));
                    }
                }
            }
            else {
                // Restore jump lock
                m_jump_ready = true;

                // 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);
                    set_vx(0);
                }
            }

            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("jump_forward"));
            }
            else if (input & PRESS_LEFT) {
                set_vx(-get_attribute("jump_forward"));
            }

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

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

        case Crouch:
            set_vx(0);
            Body::move(map);

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

        case Hit:
            if (m_hit_timer.expired(get_attribute("hit_time"))) {
                m_hit_timer.reset();
                set_vx(0);
                set_lock_direction(false);
                m_hit = HitNone;
                set_action(Still);
            }
            Body::move(map);
            break;

        default:
            Body::move(map);
            break;
    }
}