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


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

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


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

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