Beispiel #1
0
void Crawler::move(Map *map)
{
    Monster::move(map);

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

        case Move:
            if (check_ahead(map)) {
                swap_move_dir();
            }
            check_ground(map);
            if (m_dir == Right) {
                set_vx(get_attribute("move_speed"));
            }
            else {
                set_vx(-get_attribute("move_speed"));
            }
            animate_move();
            break;

        default:
            break;
    }
}
Beispiel #2
0
void Hovering::move(Map *map)
{
    switch(m_action) {
        case Still:
            set_action(Move);
            break;

        case Move:
            face_reference(get_attribute("turn_width"));
            animate_move();
            if (m_dir == Right) {
                if (m_x < m_x1) {
                    set_vx(get_attribute("move_speed"));
                }
                else {
                    set_vx(0);
                }
            }
            else {
                if (m_x > m_x0) {
                    set_vx(-get_attribute("move_speed"));
                }
                else {
                    set_vx(0);
                }
            }

            if (m_attack_timer.expired(get_attribute("attack_timer"))) {
                int dist = get_attribute("attack_distance");
                int x = m_xref - get_front();
                int y = m_yref - get_y();
                if (x * x + y * y < dist * dist) {
                    fire();
                }
            }
            Body::move(map);
            break;

        case Hit:
        case HitPerish:
            set_vy(0);
            process_hit();
            Monster::move(map);
            break;

        default:
            break;
    }

    // Move bullets
    unsigned n = m_bullets.size();
    for (unsigned i = 0; i < n; i++) {
        m_bullets[i]->move(map);
    }
}
Beispiel #3
0
void Dancer::move(Map *map)
{
    Monster::move(map);

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

        case Move:
            face_reference(get_attribute("turn_width"));
            animate_move();

            if (m_attack_timer.check(get_attribute("attack_timer"))) {
                int dist = get_attribute("attack_distance");
                int x = m_xref - get_front();
                int y = m_yref - get_y();
                if (x * x + y * y < dist * dist) {
                    m_attack_timer.reset();
                    set_jump(map);
                    if (get_reference() == Right) {
                        set_speed(get_attribute("jump_forward"),
                                  -get_attribute("jump_speed"));
                    }
                    else {
                        set_speed(-get_attribute("jump_forward"),
                                  -get_attribute("jump_speed"));
                    }
                }
            }
            else {
                if (m_dir == Right) {
                    set_vx(get_attribute("move_speed"));
                }
                else {
                    set_vx(-get_attribute("move_speed"));
                }
            }
            break;

        default:
            break;
    }
}
Beispiel #4
0
void Waver::move(Map *map)
{
    switch(m_action) {
        case Still:
            set_action(Move);
            break;

        case Move:
            face_reference(get_attribute("turn_width"));
            animate_move();
            if (m_dir == Right) {
                set_vx(get_move_speed(map));
            }
            else {
                set_vx(-get_move_speed(map));
            }

            m_wave_index += get_attribute("frequency");
            if (m_wave_index >= c_num_steps) {
                m_wave_index = m_wave_index - c_num_steps;
            }
            set_vy(get_attribute("amplitude") * m_wave_y[m_wave_index] / 16);
            Body::move(map);
            break;

        case Hit:
        case HitPerish:
            set_ay(0);
            set_vy(0);
            process_hit();
            Monster::move(map);
            break;

        default:
            break;
    }
}
Beispiel #5
0
void MekaDragon::move(Map *map)
{
    Monster::move(map);

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

        case Move:
            face_reference(get_attribute("turn_width"));
            set_lock_direction(true);
            if (m_horizontal_dir == HorizontalForward) {

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

                if (abs(m_xref - m_x) < get_attribute("attack_distance")) {
                    m_horizontal_dir = HorizontalBackward;
                }
            }
            else if (m_horizontal_dir == HorizontalBackward) {

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

                if (abs(m_xref - m_x) > get_attribute("retreat_distance") ||
                    check_behind(map)) {
                    m_horizontal_dir = HorizontalForward;
                }
            }

            if (m_attack_now ||
                m_attack_timer.expired(get_attribute("attack_timer"))) {
                m_attack_timer.reset();
                m_attack_now = false;
                set_attack();
            }
            break;

        case Attack:
            if (m_idle_timer.check(get_attribute("attack_idle"))){
                fire();
            }
            break;

        case Hit:
            m_idle_timer.reset();
            m_attack_now = true;
            break;

        default:
            break;
    }

    unsigned n = m_bullets.size();
    for (unsigned i = 0; i < n; i++) {
        m_bullets[i]->move(map);
    }
}
Beispiel #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;
    }
}