Esempio n. 1
0
void Player::check_water(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_center(map, start, end)) {
        set_ay(get_attribute("water_weight"));
        m_in_water = true;
    }
    else {
        if (m_in_water) {
            if (m_action == Jump) {
                set_vy(-get_attribute("water_jump_speed"));
            }
            else if (m_action == Catapult) {
                set_vy(-get_attribute("water_catapult_speed"));
            }
        }
        set_ay(get_attribute("weight"));
        m_in_water = false;
    }

}
Esempio n. 2
0
void Player::set_jump(Map *map, bool catapult)
{
    m_media->play_sound("jump.wav");

    if (m_in_water) {
        if (catapult) {
            set_vy(-get_attribute("water_catapult_speed"));
            set_action(Catapult);
        }
        else {
            set_vy(-get_attribute("water_jump_speed"));
            set_action(Jump);
        }
    }
    else {
        if (catapult) {
            set_vy(-get_attribute("catapult_speed"));
            set_action(Catapult);
        }
        else {
            set_vy(-get_attribute("jump_speed"));
            set_action(Jump);
        }
    }

    m_hit_ground = false;
}
Esempio n. 3
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);
}
Esempio n. 4
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);
    }
}
Esempio n. 5
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;
}
Esempio n. 6
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;
    }
}
Esempio n. 7
0
void Climber::leave_climb(Map *map)
{
#if 0
    switch (m_climb_dir) {
        case ClimbRight:
            set_vx(-get_attribute("move_speed"));
            break;

        case ClimbLeft:
            set_vx(get_attribute("move_speed"));
            break;

        default:
            break;
    }
#endif

    m_climb_dir = ClimbNone;
    set_vy(0);
    Player::set_jump(map);
}
Esempio n. 8
0
void Monster::set_jump(Map *map)
{
    set_vy(-get_attribute("jump_speed"));
    m_hit_ground = false;
    set_action(Jump);
}
Esempio n. 9
0
void Body::set_speed(int vx, int vy)
{
    set_vx(vx);
    set_vy(vy);
}
Esempio n. 10
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;
    }
}