What I am trying to do:
- Render a small minimap with the current player's location and the enemy locations.
- The "up" direction on the 2D minimap should always show what is in front of the player in game, then the right direction should show what is on the right of the player, same for down and left.
- The player should always be centered on the minimap.
What I have already done:
Rendered the player on the minimap based upon it's in game x and y coordinates, rendered the enemies on the minimap based upon their x and y coordinates. When I move around in game the enemies in the minimap move relative to the player movements.
What I tried (but didn't work):
float radarX = 200;
float radarY = 200;
float zoom = 2;
// Function
float xOffset = radarX - LocalPlayer.Position.x;
float yOffset = radarY - LocalPlayer.Position.y;
draw(zoom *(LocalPlayer.Position.x + xOffset),
zoom * (LocalPlayer.Position.y + yOffset);
foreach(Player p in Game.OtherPlayers) // list of enemies
{
Vector2 rotatedLocation = VectorExt.Rotate(new Vector2(p.Position.x, p.Position.y), -LocalPlayer.Yaw - 90); // negate and -90 to convert to normal coordinate system (0 @ RHS, 90 @ Top, 180 @ LHS, 270 @ Bottom)
float tempX = zoom * (rotatedLocation.x + xOffset);
float tempY = zoom * (rotatedLocation.y + yOffset);
draw(myPen, zoom * (LocalPlayer.Position.x + xOffset), zoom * (LocalPlayer.Position.y + yOffset);
}
// End of function
// VectorExt.Rotate
var ca = Math.Cos(radians);
var sa = Math.Sin(radians);
return new Vector2(Convert.ToSingle(ca * v.x - sa * v.y), Convert.ToSingle(sa * v.x + ca * v.y));
// End of VectorExt.Rotate
Thanks in advance.