/// <summary> /// Draw pedestrians /// </summary> /// <param name="lane">Traffic Lane</param> /// <param name="state">Current state of the traffic light</param> /// <returns>Point with the correct coordinates</returns> public void drawPedestrians(PedestrianLane lane, string pStyle) { Rectangle r; SolidBrush brush; Color c; Random random = new Random(); foreach (Point p in lane.Points) { switch (random.Next(4)) { case 1: c = Color.Red; break; case 2: c = Color.Blue; break; default: c = Color.Orange; break; } brush = new SolidBrush(c); r = new Rectangle(p.X, p.Y, PED_WIDTH, PED_HEIGHT); painter.Graphics.FillRectangle(brush, r); } }
/// <summary> /// Draws pedestrian lights /// </summary> /// <param name="lane">Pedestrian Lane</param> /// <param name="state">Current state of the pedestrian light</param> public void drawPedestrianLight(PedestrianLane lane, bool state) { Rectangle r; SolidBrush brush = new SolidBrush(Color.Red); if (state) { brush.Color = Color.Green; } Point[] points = getCoordinatesForPedestrianLights(lane, state); foreach (Point p in points) { r = new Rectangle(p.X, p.Y, TRAFFIC_LIGHT_WIDTH, TRAFFIC_LIGHT_HEIGHT); painter.Graphics.FillRectangle(brush, r); } }
/// <summary> /// Determines the starting position of the pedestrian at random /// A random lane and a random point of the lane /// </summary> private Point WhereToStart() { Random rng = new Random(); int startHelper = rng.Next(1, 2); if (startHelper == 1) { lane = crossing.pLanes[0]; } else { lane = crossing.pLanes[1]; } startHelper = rng.Next(1, 2); if (startHelper == 1) { return(lane.Points[0]); } else { return(lane.Points[lane.Points.Count - 1]); } }
/// <summary> /// Get coordinates to draw pedestrian lights /// </summary> /// <param name="lane">Pedestrian Lane</param> /// <param name="state">Current state of the pedestrian light</param> /// <returns>List of Points with the correct coordinates</returns> private Point[] getCoordinatesForPedestrianLights(PedestrianLane l, bool state) { Point[] points = new Point[2]; int x = 0; int y = 0; int x2 = 0; int y2 = 0; if (l.ID == 1) { x = LIGHT_STRUCT_X_SPOTS_CROSSING_B_PEDS[0]; x2 = LIGHT_STRUCT_X_SPOTS_CROSSING_B_PEDS[1]; y = LIGHT_STRUCT_Y_SPOTS_CROSSING_B_PEDS[0]; y2 = LIGHT_STRUCT_Y_SPOTS_CROSSING_B_PEDS[1]; } else { x = LIGHT_STRUCT_X_SPOTS_CROSSING_B_PEDS[2]; x2 = LIGHT_STRUCT_X_SPOTS_CROSSING_B_PEDS[3]; y = LIGHT_STRUCT_Y_SPOTS_CROSSING_B_PEDS[2]; y2 = LIGHT_STRUCT_Y_SPOTS_CROSSING_B_PEDS[3]; } if (state) { x += 7; x2 += 7; } points[0] = new Point(x, y); points[1] = new Point(x2, y2); return(points); }
/// <summary> /// Determines the starting position of the pedestrian at random /// A random lane and a random point of the lane /// </summary> private Point WhereToStart() { Random rng = new Random(); int startHelper = rng.Next(1, 2); if (startHelper == 1) lane = crossing.pLanes[0]; else lane = crossing.pLanes[1]; startHelper = rng.Next(1, 2); if (startHelper == 1) return lane.Points[0]; else return lane.Points[lane.Points.Count - 1]; }
/// <summary> /// Get coordinates to draw pedestrian lights /// </summary> /// <param name="lane">Pedestrian Lane</param> /// <param name="state">Current state of the pedestrian light</param> /// <returns>List of Points with the correct coordinates</returns> private Point[] getCoordinatesForPedestrianLights(PedestrianLane l, bool state) { Point[] points = new Point[2]; int x = 0; int y = 0; int x2 = 0; int y2 = 0; if (l.ID == 1) { x = LIGHT_STRUCT_X_SPOTS_CROSSING_B_PEDS[0]; x2 = LIGHT_STRUCT_X_SPOTS_CROSSING_B_PEDS[1]; y = LIGHT_STRUCT_Y_SPOTS_CROSSING_B_PEDS[0]; y2 = LIGHT_STRUCT_Y_SPOTS_CROSSING_B_PEDS[1]; } else { x = LIGHT_STRUCT_X_SPOTS_CROSSING_B_PEDS[2]; x2 = LIGHT_STRUCT_X_SPOTS_CROSSING_B_PEDS[3]; y = LIGHT_STRUCT_Y_SPOTS_CROSSING_B_PEDS[2]; y2 = LIGHT_STRUCT_Y_SPOTS_CROSSING_B_PEDS[3]; } if (state) { x += 7; x2 += 7; } points[0] = new Point(x, y); points[1] = new Point(x2, y2); return points; }
/// <summary> /// Draws pedestrian lights /// </summary> /// <param name="lane">Pedestrian Lane</param> /// <param name="state">Current state of the pedestrian light</param> public void drawPedestrianLight(PedestrianLane lane, bool state) { Rectangle r; SolidBrush brush = new SolidBrush(Color.Red); if (state) brush.Color = Color.Green; Point[] points = getCoordinatesForPedestrianLights(lane, state); foreach (Point p in points) { r = new Rectangle(p.X, p.Y, TRAFFIC_LIGHT_WIDTH, TRAFFIC_LIGHT_HEIGHT); painter.Graphics.FillRectangle(brush, r); } }