Game Development Reference
In-Depth Information
auto frameSize = m_iconSprite->Animation()->CurrentFrame().Region().Size();
auto halfSpriteSize = math::point(frameSize.x() / 2, frameSize.y() / 2);
vector2 screenPosition = directionToEntityXZ;
screenPosition = m_ellipse.GetPointInEllipse(directionToEntityXZ) - halfSpriteSize;
m_iconSprite->Play(m_animations[Default]);
m_iconSprite->Draw(screenPosition, entity->Color());
}
m_iconSprite->Play(m_animations[Player]);
auto frameSize = m_iconSprite->Animation()->CurrentFrame().Region().Size();
auto halfSpriteSize = point(frameSize.x()/2, frameSize.y()/2);
m_iconSprite->Draw(m_rectangle.Center() - halfSpriteSize);
We start by calculating the direction from the player's position to the entity, we then con-
vert this direction into a 2D direction only taking the X and -Z axes. We need to scale our
direction vector by a fourth of our zoom factor, consider that the zoom factor is scaling our
source rectangle in all four directions, yet the direction we calculate to our object is only
affected once by our zoom.
We now use the rotation matrix we had previously calculated to rotate our 2D direction
vectors by the player's angle Ɵ, this ensures that as the mini map rotates, so do the entity
icons on it.
Finally, we constrain our mini map icons on a circle on top of the map, this gives a very
nice effect as we are moving closer or away from entities.
float radius = (m_rectangle.Width()/2);
m_ellipse = math::ellipse(m_rectangle.Center(), math::vector2(radius, radius));
The ellipse is centered using our element's rectangle boundary by using half its width as
the radius. This makes our circle fit snuggly within the mini map. Calling the ellipse's
GetPointInEllipse function on the directionToEntityXZ will give us the final screen posi-
tion for our icon, finally we need to make sure we center our sprite by half of its size.
At this time we could use the information we have to select a different sprite animation if
the player is below or above the entity, we could rotate the entity's icon itself to represent
its own view direction and possibly draw the entity's field of view.
The player is also an entity yet we skip doing any calculations for it, the player is a special
case as all other entities are being drawn relative to it and even the mini map itself is being
rotated according to its own rotation.
Search WWH ::




Custom Search