Ejemplo n.º 1
0
        public Rectangle GetWaitingHitbox(TrafficPanel panel)
        {
            //Creates a 'hitbox' of sorts to check for cars inside
            Rectangle checkArea = Rectangle.Empty;

            switch (this.TrafficSide)
            {
            case 0:
                checkArea = new Rectangle(0, this.RectLoc.Y, this.RectLoc.X, 40);

                break;

            case 1:
                checkArea = new Rectangle(this.RectLoc.X, (this.RectLoc.Y + 10), 40, panel.Height);
                break;

            case 2:
                checkArea = new Rectangle((this.RectLoc.X + 10), this.RectLoc.Y, panel.Width - this.RectLoc.X, 40);
                break;

            case 3:
                checkArea = new Rectangle(this.RectLoc.X, 0, 40, this.RectLoc.Y);
                break;
            }

            return(checkArea);
        }
Ejemplo n.º 2
0
        //public static TrafficLight[] MapLights { get; private set; }

        /// <summary>
        /// Saves a map as a .timap file
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="panel"></param>
        /// <returns></returns>
        public static bool SaveMap(string filePath, TrafficPanel panel)
        {
            try
            {
                using (FileStream fs = new FileStream(filePath, FileMode.Create))
                {
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        //Writes height and width with count of tiles
                        bw.Write(panel.Width);
                        bw.Write(panel.Height);

                        Tile[] tiles = panel.GetAllTiles();
                        bw.Write(tiles.Length);

                        //Writes each tiles X Y and type tile
                        foreach (Tile tile in tiles)
                        {
                            bw.Write(tile.RectLoc.X);
                            bw.Write(tile.RectLoc.Y);
                            bw.Write(tile.TypeTile);

                            //If its a trafficlight it writes its specific properties
                            if (tile.TypeTile == "TrafficLight")
                            {
                                TrafficLight light = (TrafficLight)tile;
                                bw.Write(light.ID);
                                bw.Write(light.RectLoc.Width);
                                bw.Write(light.RectLoc.Height);
                                bw.Write(light.TrafficSide);
                                int[] syncedLights = light.GetSyncedLights();

                                //Writes it's synced lights ID's
                                bw.Write(syncedLights.Length);
                                foreach (int i in syncedLights)
                                {
                                    bw.Write(i);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets cars waiting in the traffic lights wait direction (which side
        /// cars come from)
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="vehicles"></param>
        /// <returns></returns>
        public Vehicle[] GetCarsWaiting(TrafficPanel panel, Vehicle[] vehicles)
        {
            Rectangle hitbox = this.GetWaitingHitbox(panel);

            return(vehicles.Where((x) => hitbox.Contains(new Point(x.VehicleRect.X + 5, x.VehicleRect.Y + 5))).ToArray());
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Changes this lights colour
 /// </summary>
 /// <param name="colour"></param>
 /// <param name="panel"></param>
 public void ChangeColour(Color colour, TrafficPanel panel)
 {
     this.LightColour = colour;
     panel.Invalidate();
 }