//adding the chosen objects to the object list
        private void FormLevelEditor_DragDrop(object sender, DragEventArgs e)
        {
            Point p = this.PointToClient(Cursor.Position);

            switch ((ObjectType)e.Data.GetData(typeof(ObjectType)))
            {
            case ObjectType.Finish:
                ObstacleList.RemoveAll((o) => { return(o.GetType() == typeof(Finish)); });
                ObstacleList.Add(new Finish(p.X, p.Y));
                break;

            case ObjectType.Mine:
                ObstacleList.Add(new Mine(p.X, p.Y));
                break;

            case ObjectType.Mud:
                ObstacleList.Add(new Mud(p.X, p.Y));
                break;

            case ObjectType.Rocketlauncher:
                ObstacleList.Add(new Missilelauncher(p.X, p.Y));
                break;

            case ObjectType.Sandbag:
                ObstacleList.Add(new Sandbag(p.X, p.Y));
                break;

            case ObjectType.Tree:
                ObstacleList.Add(new Tree(p.X, p.Y));
                break;
            }
            //MessageBox.Show(string.Format("{0} gedropt at {1}, {2}", (ObjectType)e.Data.GetData(typeof(ObjectType)), p.X, p.Y));
        }
Пример #2
0
 void Start()
 {
     for (int i = 0; i < 200; i++)
     {
         int        n        = Random.Range(0, 4) + 1;
         ObstacleVO obstacle = InGameData.Instance.ObstacleList.Find(a => a.Type == n).Copy();
         obstacle.SetCreatePosition(2000 + (i * Random.Range(0, 5) * 60));
         ObstacleList.Add(obstacle);
     }
 }
Пример #3
0
 public bool AddObstacle(Position position)
 {
     ObstacleList.Add(position);
     ObstacleMatrix[position.Y, position.X] = true;
     return(true);
 }
        //opening the dialogs for choosing an existing level
        private void loadLevel()
        {
            OpenFileDialog BrowseFile = new OpenFileDialog();

            BrowseFile.Filter      = "XML Files (*.xml)|*.xml";
            BrowseFile.FilterIndex = 0;
            BrowseFile.DefaultExt  = "xml";
            if (BrowseFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ObstacleList.Clear();
                doc = new XmlDocument();
                try
                {
                    doc.Load(BrowseFile.FileName);
                }
                catch (Exception e)
                {
                    MessageBox.Show("Level Could't be read please check your file. Error: " + e, "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                XmlNodeList xmlnode;
                xmlnode = doc.GetElementsByTagName("object");
                for (int i = 0; i < xmlnode.Count; i++)
                {
                    string name  = xmlnode[i].ChildNodes.Item(0).InnerText;
                    int    xaxis = Convert.ToInt32(xmlnode[i].ChildNodes.Item(1).InnerText);
                    int    yaxis = Convert.ToInt32(xmlnode[i].ChildNodes.Item(2).InnerText);
                    string speed = xmlnode[i].ChildNodes.Item(3).InnerText;
                    //adding the objects to the object list
                    switch (name)
                    {
                    case "tree":
                        Tree tree = new Tree(xaxis, yaxis);
                        ObstacleList.Add(tree);
                        Console.WriteLine("Tree added to list.");
                        break;

                    case "sandbag":
                        Sandbag sandbag = new Sandbag(xaxis, yaxis);
                        ObstacleList.Add(sandbag);
                        Console.WriteLine("Tree added to list.");
                        break;

                    case "mine":
                        Mine mine = new Mine(xaxis, yaxis);
                        ObstacleList.Add(mine);
                        Console.WriteLine("Tree added to list.");
                        break;

                    case "mud":
                        Mud mud = new Mud(xaxis, yaxis);
                        ObstacleList.Add(mud);
                        Console.WriteLine("Tree added to list.");
                        break;

                    case "finish":
                        Finish finish = new Finish(xaxis, yaxis);
                        ObstacleList.Add(finish);
                        Console.WriteLine("Tree added to list.");
                        break;

                    case "missilelauncher":
                        ObstacleList.Add(new Missilelauncher(xaxis, yaxis));
                        Console.WriteLine("Missilelauncher added to list.");
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// The load obstacles.
        /// </summary>
        /// <param name="ObstacleList">The obstacle list.</param>
        /// <remarks></remarks>
        public void LoadObstacles(ref List <SceneryInfo> ObstacleList)
        {
            if (ObstacleList == null)
            {
                ObstacleList = new List <SceneryInfo>();
            }
            else
            {
                ObstacleList.Clear();
            }

            map.OpenMap(MapTypes.Internal);

            // Lists all Obstacles
            for (int i = 0; i < map.MapHeader.fileCount; i++)
            {
                if (map.MetaInfo.TagType[i] == "scnr")
                {
                    Meta m = new Meta(map);

                    // Base address of SCNR tag, offset of Crate Palette pointer (+816)
                    map.BR.BaseStream.Position = map.MetaInfo.Offset[i] + 816;
                    int chunkCount  = map.BR.ReadInt32();
                    int chunkOffset = map.BR.ReadInt32() - map.SecondaryMagic;

                    // Crate (Obstacle) Palette Objects
                    for (int a = 0; a < chunkCount; a++)
                    {
                        SceneryInfo Obstacle = new SceneryInfo();

                        // The Palette Chunk #
                        Obstacle.ScenPalNumber = a;

                        // Each chunk is 40 bytes apart
                        map.BR.BaseStream.Position = chunkOffset + a * 40;
                        char[] tagName = map.BR.ReadChars(4);
                        Obstacle.ScenTagNumber = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                        if (Obstacle.ScenTagNumber != -1)
                        {
                            // Retrieve the Model HLMT tag from the Scenery tag (+56)
                            map.BR.BaseStream.Position = map.MetaInfo.Offset[Obstacle.ScenTagNumber] + 56;
                            Obstacle.HlmtTagNumber     = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                            // Base address of HLMT tag, offset of MODE pointer (+4)
                            map.BR.BaseStream.Position = map.MetaInfo.Offset[Obstacle.HlmtTagNumber] + 4;
                            Obstacle.ModelTagNumber    = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                            m.ReadMetaFromMap(Obstacle.ModelTagNumber, false);
                            Obstacle.Model = new ParsedModel(ref m);
                            ParsedModel.DisplayedInfo.LoadDirectXTexturesAndBuffers(ref device, ref Obstacle.Model);

                            string[] s = map.FileNames.Name[Obstacle.ScenTagNumber].Split('\\');
                            Obstacle.Name    = s[s.Length - 1];
                            Obstacle.TagPath = map.FileNames.Name[Obstacle.ScenTagNumber];
                            Obstacle.TagType = map.MetaInfo.TagType[Obstacle.ScenTagNumber];
                            ObstacleList.Add(Obstacle);
                        }
                    }

                    break;
                }
            }

            map.CloseMap();
        }
Пример #6
0
 public void AddObstacle(Obstacle c)
 {
     ObstacleList.Add(c);
 }