本文整理汇总了C++中Tilemap::getCrateOnRight方法的典型用法代码示例。如果您正苦于以下问题:C++ Tilemap::getCrateOnRight方法的具体用法?C++ Tilemap::getCrateOnRight怎么用?C++ Tilemap::getCrateOnRight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tilemap
的用法示例。
在下文中一共展示了Tilemap::getCrateOnRight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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++)
//.........这里部分代码省略.........