Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6. using PlayerIO.GameLibrary;
  7.  
  8. namespace Enline
  9. {
  10. class Detector
  11. {
  12. //public System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(600, 600, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
  13. public System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(30,255,0,0), 4);
  14. public int R = 20; //radius around the player locations to check
  15. //public Player checkee;
  16.  
  17. public void Main() {
  18. }
  19.  
  20. public Rectangle result(Player checkee, List<Player> players) {
  21. //List<Graphics> lines = new List<Graphics>();
  22.  
  23. Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 4f);
  24. Bitmap bitmap = new System.Drawing.Bitmap(600, 600, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
  25. Graphics g = Graphics.FromImage(bitmap);
  26. g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
  27.  
  28. foreach (Player player in players)
  29. {
  30. if (player!=checkee) drawPath(player,g,bitmap);
  31. }
  32.  
  33. g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
  34. drawPath(checkee, g, bitmap);
  35.  
  36. //findTheSpot(bitmap,checkee);
  37.  
  38. return findTheSpot(bitmap, checkee);
  39.  
  40. g.Dispose();
  41. }
  42.  
  43. public Graphics drawPath(Player player, Graphics g, Bitmap bitmap){
  44. //Graphics g = Graphics.FromImage(bitmap);
  45.  
  46. float command;
  47. bool counts = false;
  48. List<PointF> path = new List<PointF>();
  49.  
  50. for (int q = 0; q < player.path.Count; q += 3)
  51. {
  52. command = player.path[q];
  53. if (command == 1) counts = !counts;
  54. path.Add(new PointF(player.path[q + 1], player.path[q + 2]));
  55.  
  56. if (counts != true)
  57. {
  58. g.DrawLines(pen, path.ToArray());
  59. path.Clear();
  60. g = Graphics.FromImage(bitmap);
  61. }
  62. }
  63. return g;
  64. }
  65.  
  66. public Rectangle findTheSpot(Bitmap map, Player player){
  67. Color pixel;
  68. Rectangle rect = new Rectangle(0,0,0,0);
  69. map.Save("C:\\Photon\\hitmap.bmp");
  70.  
  71. int minWidth = Convert.ToInt16( player.x - R);
  72. if (minWidth < 0) minWidth = 0;
  73.  
  74. int minHeight = Convert.ToInt16(player.y - R);
  75. if (minHeight < 0) minHeight = 0;
  76.  
  77. int maxWidth = minWidth + R*2;
  78. if (maxWidth > map.Width) maxWidth = map.Width;
  79.  
  80. int maxHeight = minHeight + R*2;
  81. if (maxHeight > map.Height) maxHeight = map.Height;
  82.  
  83. for (int i = minWidth; i < maxWidth; i++)
  84. {
  85. for (int k = minHeight; k < maxHeight; k++)
  86. {
  87. pixel = map.GetPixel(i, k);
  88. if (pixel.A != 0 && pixel.A != pen.Color.A)
  89. {
  90. if (rect.X == 0) rect.X = i;
  91. if (rect.Y == 0) rect.Y = k;
  92. if (rect.Width < i - rect.X) rect.Width = i - rect.X;
  93. if (rect.Height < k) rect.Height = k - rect.Y;
  94. }
  95. }
  96. }
  97. return rect;
  98. }
  99.  
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement