Пример #1
0
 public RoomEditor()
 {
     editorSurface = new RenderTarget2D(Engine.Instance.GraphicsDevice, Engine.WINDOW_WIDTH * 2, Engine.WINDOW_HEIGHT * 2);
     Player p = new Player(Vector2.Zero, this);
     this.objects.Add(p);
     cameraTarget = p;
 }
Пример #2
0
 public void FillNodes()
 {
     foreach(Vector2 p in nodes.GetNodeList("player"))
     {
         Player p2 = new Player(p, this);
         p2.KeyJump = Keys.W;
         p2.KeyLeft = Keys.A;
         p2.KeyRight = Keys.D;
         this.cameraTargets.Add(p2);
         objects.Add(p2);
     }
 }
Пример #3
0
        /// <summary>
        /// Loads a room with the specified filename.
        /// 
        /// Returns 0 if everything is OK.
        /// Returns 2 if cannot find the file.
        /// Returns 3 if it had to load new textures.
        /// Returns 4 if we are missing textures.
        /// Returns -1 if the file is corrupt.
        /// </summary>
        /// <param name="fname">The filename to load from.</param>
        /// <returns>A code indicating error or success.</returns>
        public int Load(string fname)
        {
            // Reads in the entire file.
            string[] lines;
            try
            {
                lines = System.IO.File.ReadAllLines(fname);
            }
            catch
            {
                return 2;
            }

            Reset();

            // Sets file index to 10 (skip header)
            int i = 0;
            name = lines[i++];
            this.boundsTopLeft.X = float.Parse(lines[i++]);
            this.boundsTopLeft.Y = float.Parse(lines[i++]);
            this.boundsBottomRight.X = float.Parse(lines[i++]);
            this.boundsBottomRight.Y = float.Parse(lines[i++]);
            i = 10;
            int flag = 0;

            while (i < lines.Length)
            {
                string type = lines[i++];
                switch (type)
                {
                    case "Floor":
                        floors.Add(new Floor(new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++]))));
                        break;
                    case "Block":
                        blocks.Add(new Block(new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++]))));
                        break;
                    case "TopBlock":
                        blocks.Add(new Block(new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), true));
                        break;
                    case "Player":
                        Player p = new Player(new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), this);
                        objects.Add(p);
                        this.cameraTarget = p;
                        break;
                    case "WorldObject":
                        objects.Add(new WorldObject(new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), TextureBin.GetTexture(lines[i++]), this));
                        break;
                    case "Node":
                        nodes.AddNode(lines[i++], new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])));
                        break;
                    case "Decal":
                        bool isFront = (lines[i++] == "F");
                        Vector2 pos = new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++]));
                        Color col = new Color(int.Parse(lines[i++]), int.Parse(lines[i++]), int.Parse(lines[i++]), int.Parse(lines[i++]));
                        Vector2 ori = new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++]));

                        Texture2D tex;
                        if (!TextureBin.GetDictionary.ContainsKey(lines[i]))
                        {
                            if (TextureBin.LoadTextureFromStream("Content\\Decals\\" + lines[i] + ".png") == 0)
                            {
                                tex = TextureBin.GetTexture(lines[i]);
                                flag = 3;
                            }
                            else
                            {
                                tex = TextureBin.Pixel;
                                flag = 4;
                            }

                        }
                        else
                            tex = TextureBin.GetTexture(lines[i]);
                        i++;

                        Decal d = new Decal(pos, tex, ori, col, float.Parse(lines[i++]), float.Parse(lines[i++]), float.Parse(lines[i++]));
                        if (isFront)
                            decalsFront.Add(d);
                        else
                            decalsBack.Add(d);
                        break;
                    default:
                        i = lines.Length;
                        flag = -1;
                        break;
                }
            }

            return flag;
        }