本文整理汇总了C++中Tilemap::Intersect方法的典型用法代码示例。如果您正苦于以下问题:C++ Tilemap::Intersect方法的具体用法?C++ Tilemap::Intersect怎么用?C++ Tilemap::Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tilemap
的用法示例。
在下文中一共展示了Tilemap::Intersect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void Pacman::Update(const SDLInput& input, Tilemap& tilemap, float deltaTime, const std::shared_ptr<SDLRenderTarget>& tileSurface, const std::vector<SDLSurface>& gridSurf)
{
if (m_State == PacState::PowerUp) // if powered up
{
float currentTime = Timer::GetTime();
if ((currentTime - m_powerDuration) > 5.f) // if powered up for more tha 5 seconds
{
m_State = PacState::Normal;// return to normal
}
}
//set our speed
float speed = 5.5f * deltaTime;
// clamp position
size_t cX = (size_t)(clamp(m_Position.x, 0.f, 18.f) + 0.5f);
size_t cY = (size_t)(clamp(m_Position.y, 0.f, 22.f) + 0.5f);
switch (m_CurrentDirection) // move in direction
{
case Direction::Left:
m_Position.x -= speed;
break;
case Direction::Right:
m_Position.x += speed;
break;
case Direction::Up:
m_Position.y -= speed;
break;
case Direction::Down:
m_Position.y += speed;
break;
}
//make the side wall let us trough
if (m_Position.x < 0.f)
{
m_Position.x = 19.f;
}
if (m_Position.x > 19.0f)
{
m_Position.x = 0.f;
}
if (m_CurrentDirection == Direction::None && m_NextDirection != Direction::None && tilemap.GetDirectionFlag(cX, cY, (size_t)m_NextDirection))
{// if the current direction is None and the next input direction is not none and we can go in that direction
m_CurrentDirection = m_NextDirection; // switch directions
m_NextDirection = Direction::None; // set next to none
}
if (m_CurrentDirection != Direction::None) // if our current direction is not None ( we are not at base)
{
m_DistanceLeft -= speed; // reduce the distance of travel
if (m_DistanceLeft <= 0.f) //if we have traveled 1 tile
{
if (!tilemap.GetDirectionFlag(cX, cY, (size_t)m_CurrentDirection)) // if the tile we are on dosent have the current direction direction flag set
{
m_CurrentDirection = Direction::None;// make curent dir none
}
if (m_NextDirection != Direction::None) // if we have a pending direction command
{
if (tilemap.GetDirectionFlag(cX, cY, (size_t)m_NextDirection)) // and if the tile we are one has the next direction tag set
{
m_CurrentDirection = m_NextDirection;// go in that direction
}
}
m_DistanceLeft += 1.0f;// add distace to travel
}
}
Rect rect(m_Position.x + 0.05f, m_Position.y + 0.05f, 0.9f, 0.9f);//construct a collision rect;
//get all intersections
auto intersections = tilemap.Intersect(rect);
for (auto &i : intersections) // go trough them
{
if (i.type == Coin) // if its a coin
{
m_Points += 1; // increase points
tilemap.Set(i.x, i.y, Empty); //remove coin
tileSurface->Clear(); // clear tilemap render
tileSurface->RenderTileset(gridSurf, tilemap.GetGrid(), 19, 32.0f);// re - render the grid without the coin.
}
}
//set directions accortind to input keys
if (input.GetKey(Left))
{
m_NextDirection = Direction::Left;
}
if (input.GetKey(Right))
{
m_NextDirection = Direction::Right;
}
//.........这里部分代码省略.........