samedi 7 mars 2015

c# Draw image to screen for a minimap


Vote count:

0




I am attempting to create a game overlay, One of the final touches is converting the 2d radar into a radar and a minimap Before I worry about getting a sub-image that encompasses a small portion of the original image centered at my location i need to first properly draw the image in my radar.


The code for my working 2d radar is:





if (ShowRadar)
{
//background
//DrawFilledBox(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 50, 201f, 201f, Color.DarkOliveGreen, RadarTransparency);
//Draw radar Border
DrawBoxAbs(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 50, 201f, 201f, 1f, Color.Black);
//Draw radar axis
DrawLine(this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 50, this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 251, 1f, Color.Black);
DrawLine(this.GameWindowRect.Right - 225, this.GameWindowRect.Top + 150, this.GameWindowRect.Right - 24, this.GameWindowRect.Top + 150, 1f, Color.Black);
//Center point
RadarCenter = new Vector2(this.GameWindowRect.Right - 125, this.GameWindowRect.Top + 125 + 25);
DrawFilledBox(RadarCenter.X - 1f, RadarCenter.Y - 1f, 3f, 3f, Color.White);
//draw the map in radar
DrawImage(this.GameWindowRect.Right - 225f, this.GameWindowRect.Top + 50f, 201f, 201f, RadarTransparency);

if (RadarCenter.Length() > 0f)
{
//Display each entity in correct relational position
foreach (ENTITY entity in Entity)
{
Vector2 pointToRotate = new Vector2(entity.Pos.X, entity.Pos.Z);
Vector2 vector3 = new Vector2(player_X, player_Z);
pointToRotate = vector3 - pointToRotate;
float num30 = pointToRotate.Length() * 0.5f;
num30 = Math.Min(num30, 90f);
pointToRotate.Normalize();
pointToRotate = (Vector2)(pointToRotate * num30);
pointToRotate += RadarCenter;
pointToRotate = RotatePoint(pointToRotate, RadarCenter, player_D, true);
if (entity.Type == 0x04 && RadarPlayers)
{
DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.SkyBlue);
}
if ((entity.Type == 0x0C || entity.Type == 0x14 || entity.Type == 0x50 || entity.Type == 0x5b) && RadarAggressive)
{
DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.Red);
}
if ((entity.Type == 0x13 || entity.Type == 0x55) && RadarAnimals)
{
DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.LightGreen);
}
if ((entity.Type == 0x11 || entity.Type == 0x72 || entity.Type == 0x76) && RadarVehicles)
{
DrawFilledBox(pointToRotate.X, pointToRotate.Y, 3f, 3f, Color.HotPink);
}
}
}
}



And the code to draw the image is:





#region DrawImage
public static void DrawImage(float x, float y, float w, float h, int alpha = 255)
{
if (System.IO.File.Exists("map.png"))
{

Bitmap bmp = new Bitmap("map.png");
GFX = Graphics.FromImage(bmp);
Rectangle destRect = new Rectangle((int)x, (int)y, (int)w, (int)h);
GFX.DrawImage(bmp, destRect);
}
}
#endregion



Again the radar itself is working 100%, Although I aim to use an image as the background instead of a solid colour which is what I am struggling with.



asked 54 secs ago







c# Draw image to screen for a minimap

Aucun commentaire:

Enregistrer un commentaire