当前位置: 首页>>代码示例>>C++>>正文


C++ Tilemap::getPlatformRight方法代码示例

本文整理汇总了C++中Tilemap::getPlatformRight方法的典型用法代码示例。如果您正苦于以下问题:C++ Tilemap::getPlatformRight方法的具体用法?C++ Tilemap::getPlatformRight怎么用?C++ Tilemap::getPlatformRight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tilemap的用法示例。


在下文中一共展示了Tilemap::getPlatformRight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Move

void Player::Move(sf::Time &deltaTime, Tilemap &t)
{
    //moving right and slowing down
    if(m_isMovingRight == true)
        m_movement.x += m_movSpeedConst * deltaTime.asMilliseconds();
    else if(m_isMovingRight == false && m_movement.x > 0)
    {
        m_movement.x -= m_movSpeedConst * 1.5 * deltaTime.asMilliseconds();
        if(m_movement.x < 0)
            m_movement.x = 0;
    }

    //moving left and slowing down
    if(m_isMovingLeft == true)
        m_movement.x -= m_movSpeedConst * deltaTime.asMilliseconds();
    else if(m_isMovingLeft == false && m_movement.x < 0)
    {
        m_movement.x += m_movSpeedConst* 1.5 * deltaTime.asMilliseconds();
        if(m_movement.x > 0)
            m_movement.x = 0;
    }

    //not over max speed
    if(m_movement.x >= m_movSpeedMax)
        m_movement.x = m_movSpeedMax;
    else if(m_movement.x <= -m_movSpeedMax)
        m_movement.x = -m_movSpeedMax;

    //don't move left right if colliding with wall
    if(int(m_bottom) % 64 == 0 && (t.getLevelMap((m_bottom + 2)/64, m_left/64) == 192 || t.getLevelMap((m_bottom + 2)/64, m_left/64) == 191 || t.getLevelMap((m_bottom + 2)/64, m_right/64) == 191 || t.getLevelMap((m_bottom + 2)/64, m_right/64) == 190 || t.getLevelMap((m_bottom + 2)/64, m_left/64) == 192 || t.getLevelMap((m_bottom + 2)/64, m_left/64) == 592 || t.getLevelMap((m_bottom + 2)/64, m_left/64) == 591 || t.getLevelMap((m_bottom + 2)/64, m_right/64) == 591 || t.getLevelMap((m_bottom + 2)/64, m_right/64) == 590))
    {}
    else if((t.getLevelMap(m_bottom/64, m_left/64) == 192 || t.getLevelMap(m_bottom/64, m_left/64) == 292 || t.getLevelMap(m_bottom/64, m_left/64) == 392 || t.getLevelMap(m_bottom/64, m_left/64) == 490 || t.getLevelMap(m_bottom/64, m_left/64) == 592 || t.getLevelMap(m_bottom/64, m_left/64) == 191 || t.getLevelMap(m_bottom/64, m_left/64) == 291 || t.getLevelMap(m_bottom/64, m_left/64) == 391 || t.getLevelMap(m_bottom/64, m_left/64) == 491 || t.getLevelMap(m_bottom/64, m_left/64) == 591) && m_movement.x < 0)
        m_movement.x = 0;
    else if((t.getLevelMap(m_bottom/64, m_right/64) == 190 || t.getLevelMap(m_bottom/64, m_right/64) == 290 || t.getLevelMap(m_bottom/64, m_right/64) == 390 || t.getLevelMap(m_bottom/64, m_right/64) == 492 || t.getLevelMap(m_bottom/64, m_right/64) == 590 || t.getLevelMap(m_bottom/64, m_right/64) == 191 || t.getLevelMap(m_bottom/64, m_right/64) == 291 || t.getLevelMap(m_bottom/64, m_right/64) == 391 || t.getLevelMap(m_bottom/64, m_right/64) == 491 || t.getLevelMap(m_bottom/64, m_right/64) == 591) && m_movement.x > 0)
        m_movement.x = 0;
    else if((t.getLevelMap((m_top + 2)/64, m_left/64) == 192 || t.getLevelMap((m_top + 2)/64, m_left/64) == 292 || t.getLevelMap((m_top + 2)/64, m_left/64) == 392 || t.getLevelMap((m_top + 2)/64, m_left/64) == 490 || t.getLevelMap((m_top + 2)/64, m_left/64) == 592 || t.getLevelMap((m_top + 2)/64, m_left/64) == 191 || t.getLevelMap((m_top + 2)/64, m_left/64) == 291 || t.getLevelMap((m_top + 2)/64, m_left/64) == 391 || t.getLevelMap((m_top + 2)/64, m_left/64) == 491 || t.getLevelMap((m_top + 2)/64, m_left/64) == 591) && m_movement.x < 0)
        m_movement.x = 0;
    else if((t.getLevelMap((m_top + 2)/64, m_right/64) == 190 || t.getLevelMap((m_top + 2)/64, m_right/64) == 290 || t.getLevelMap((m_top + 2)/64, m_right/64) == 390 || t.getLevelMap((m_top + 2)/64, m_right/64) == 492 || t.getLevelMap((m_top + 2)/64, m_right/64) == 590 || t.getLevelMap((m_top + 2)/64, m_right/64) == 191 || t.getLevelMap((m_top + 2)/64, m_right/64) == 291 || t.getLevelMap((m_top + 2)/64, m_right/64) == 391 || t.getLevelMap((m_top + 2)/64, m_right/64) == 491 || t.getLevelMap((m_top + 2)/64, m_right/64) == 591) && m_movement.x > 0)
        m_movement.x = 0;

    //don't move if colliding with a colliding crate!
    for(int i = 0; i < t.getCrateSize(); i++)
    {
        if(t.getCrateOnLeft(i) == true || t.getCrateOnRight(i) == true)
        {
            if(m_right < t.getCrateLeft(i) || m_left > t.getCrateRight(i) || m_top > t.getCrateBottom(i) || m_bottom < t.getCrateTop(i))
            {}
            else if(m_right >= t.getCrateLeft(i) && (m_right + m_left)/2 <= t.getCrateLeft(i) && m_movement.x > 0 &&(m_bottom - 2) >= t.getCrateTop(i))
                m_movement.x = 0;
            else if(m_left <= t.getCrateRight(i) && (m_right + m_left)/2 >= t.getCrateLeft(i) && m_movement.x < 0 && (m_bottom - 2) >= t.getCrateTop(i))
                m_movement.x = 0;
        }
    }

    //jumping
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::W) || sf::Keyboard::isKeyPressed(sf::Keyboard::Space) || sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        m_jumped = true;

    //if hit top of block, fall
    if((t.getLevelMap(m_top/64, (m_left + 2)/64) == 190 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 190 || t.getLevelMap(m_top/64, (m_left + 2)/64) == 191 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 191 || t.getLevelMap(m_top/64, (m_left + 2)/64) == 192 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 192 || t.getLevelMap(m_top/64, (m_left + 2)/64) == 290 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 290 || t.getLevelMap(m_top/64, (m_left + 2)/64) == 291 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 291 || t.getLevelMap(m_top/64, (m_left + 2)/64) == 292 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 292 ||
            t.getLevelMap(m_top/64, (m_left + 2)/64) == 390 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 390 || t.getLevelMap(m_top/64, (m_left + 2)/64) == 391 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 391 || t.getLevelMap(m_top/64, (m_left + 2)/64) == 392 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 392 || t.getLevelMap(m_top/64, (m_left + 2)/64) == 490 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 490 || t.getLevelMap(m_top/64, (m_left + 2)/64) == 491 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 491 || t.getLevelMap(m_top/64, (m_left + 2)/64) == 492 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 492 ||
            t.getLevelMap(m_top/64, (m_left + 2)/64) == 590 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 590 || t.getLevelMap(m_top/64, (m_left + 2)/64) == 591 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 591 || t.getLevelMap(m_top/64, (m_left + 2)/64) == 592 || t.getLevelMap(m_top/64, (m_right - 2)/64) == 592) && m_movement.y < 0)
        m_movement.y = 0;

    //setting jump stuff
    if(m_jumped == true && m_onGround == true)
    {
        m_movement.y = -m_gravity;
        m_jumped = false;
    }
    else
    {
        m_jumped = false;

        if(!m_onGround)
            m_movement.y += m_gravity * 0.003 * deltaTime.asMilliseconds();
        else
            m_movement.y = 0;

        if(m_movement.y > 0.5)
            m_movement.y = 0.5;
    }

    //move if on a platform
    for(int i = 0; i < t.getPlatformSize(); i++)
    {
        //not touching
        if(m_right < t.getPlatformLeft(i) || m_left > t.getPlatformRight(i) || m_top > t.getPlatformBottom(i) || m_bottom < t.getPlatformTop(i))
        {}
        else if(m_bottom - 2 > t.getPlatformTop(i))
        {}
        else if(m_left > t.getPlatformLeft(i) && m_right < t.getPlatformRight(i))
            m_movement.x += t.getPlatformMovement(i).x;
        else if( m_left < t.getPlatformLeft(i) && (m_left + m_right)/2 > t.getPlatformLeft(i) && int(m_movement.x) == 0)
            m_movement.x += t.getPlatformMovement(i).x;
        else if( m_right > t.getPlatformRight(i) && (m_left + m_right)/2 < t.getPlatformRight(i) && int(m_movement.x) == 0)
            m_movement.x += t.getPlatformMovement(i).x;
    }
    //move if on a crate (movement will be non-zero if crate is on a platform so...)
    /*for(int i = 0; i < t.getCrateSize(); i++)
//.........这里部分代码省略.........
开发者ID:Nicholas-Swift,项目名称:Game-of-Crates,代码行数:101,代码来源:Player.cpp

示例2: Update

void Player::Update(Tilemap &t, sf::RenderWindow &window, BackgroundProcesses &b)
{
    m_top = m_rect.getPosition().y;
    m_bottom = m_rect.getPosition().y + m_rect.getSize().y;
    m_left = m_rect.getPosition().x;
    m_right = m_rect.getPosition().x + m_rect.getSize().x;

    //collision with portal
    if(t.getLevelMap(m_bottom/64, m_left/64) == 999 || t.getLevelMap(m_bottom/64, m_right/64) == 999 || t.getLevelMap(m_top/64, m_left/64) == 999 || t.getLevelMap(m_top/64, m_right/64) == 999)
    {
        setPosition(sf::Vector2f(0, 0));
        t.setMap(window);
    }

    //respawning when falling through the bottom of the map!!
    if(m_bottom >= 30*64)
    {
        setPosition(sf::Vector2f(0, 0));
        t.setMap(t.getLevel(), window);
    }

    //downward collision on tilemap
    if(m_bottom / 64 < 0 || m_right < 0)
        m_onGround = false;
    else if(int(m_bottom) % 64 != 0)
        m_onGround = false;
    else if( (t.getLevelMap(m_bottom/64, m_left/64) >= 100 && t.getLevelMap(m_bottom/64, m_left/64) < 200) || (t.getLevelMap(m_bottom/64, m_left/64) >= 500 && t.getLevelMap(m_bottom/64, m_left/64) < 600) || (t.getLevelMap(m_bottom/64, m_right/64) >= 100 && t.getLevelMap(m_bottom/64, m_right/64) < 200) || (t.getLevelMap(m_bottom/64, m_right/64) >= 500 && t.getLevelMap(m_bottom/64, m_right/64) < 600) )
        m_onGround = true;
    else
        m_onGround = false;

    //downward collision on platform
    for(int i = 0; i < t.getPlatformSize(); i++)
    {
        if(m_right < t.getPlatformLeft(i) || m_left > t.getPlatformRight(i) || m_top > t.getPlatformBottom(i) || m_bottom < t.getPlatformTop(i))
        {}
        else if(int(m_bottom) <= t.getPlatformTop(i))
            m_onGround = true;
    }

    int whichCrate = -1;
    for(int i = 0; i < t.getCrateSize(); i++)
    {
        //downward collision on crate
        if(m_right < t.getCrateLeft(i) || m_left > t.getCrateRight(i) || m_top > t.getCrateBottom(i) || m_bottom < t.getCrateTop(i))
        {}
        else if(m_bottom >= t.getCrateTop(i) && m_bottom - 2 <= t.getCrateTop(i) && m_right - 2 > t.getCrateLeft(i) && m_left + 2 < t.getCrateRight(i))
        {
            m_onGround = true;
            m_onCrate = true;
            whichCrate = i;
            break;
        }
        else
        {
            m_onCrate = false;
        }
    }

    for(int i = 0; i < t.getCrateSize(); i++)
    {
        //downward collision on crate
        /*if(m_right < t.getCrateLeft(i) || m_left > t.getCrateRight(i) || m_top > t.getCrateBottom(i) || m_bottom < t.getCrateTop(i))
        {}
        else if(m_bottom >= t.getCrateTop(i) && m_bottom - 2 <= t.getCrateTop(i) && m_right - 2 > t.getCrateLeft(i) && m_left + 2 < t.getCrateRight(i))
        {
        	m_onGround = true;
        	m_onCrate = true;
        }
        else
        {
        	m_onCrate = false;
        } */

        if(i != whichCrate)
        {
            //not colliding with crate
            if(m_right < t.getCrateLeft(i) || m_left > t.getCrateRight(i) || m_top > t.getCrateBottom(i) || m_bottom < t.getCrateTop(i))
            {}

            //on top of crate
            else if(m_top <= t.getCrateBottom(i) && m_top >= (t.getCrateBottom(i) - 2))
            {
                t.setCratePos(i, sf::Vector2f(t.getCrateLeft(i), m_top - (t.getCrateBottom(i) - t.getCrateTop(i))));
            }

            //pushing crate right
            else if(m_right >= t.getCrateLeft(i) && m_left < t.getCrateLeft(i))
            {
                if(m_movement.x > 0)
                    t.setCratePos(i, sf::Vector2f(m_right, t.getCrateTop(i)));
            }

            //pushing crate left
            else if(m_left <= t.getCrateRight(i) && m_left > t.getCrateLeft(i))
            {
                if(m_movement.x < 0)
                    t.setCratePos(i, sf::Vector2f(m_left - (t.getCrateRight(i) - t.getCrateLeft(i)), t.getCrateTop(i)));
            }
        }
//.........这里部分代码省略.........
开发者ID:Nicholas-Swift,项目名称:Game-of-Crates,代码行数:101,代码来源:Player.cpp


注:本文中的Tilemap::getPlatformRight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。