示例#1
0
        /// <summary>
        /// Returns a Y-value that represents a flat line above the slope that
        /// the other object could stand on.
        /// </summary>
        public float? FindYLineAboveFloor(WorldObject other)
        {
            float line = float.PositiveInfinity;

            float h;
            if (other.Left >= this.pointL.X && other.Left <= this.pointR.X)
            {
                // The left edge if the object is within range.
                h = FindHeightGivenX(other.Left);
                line = line < h ? line : h;
            }
            if (other.Right >= this.pointL.X && other.Right <= this.pointR.X)
            {
                // The right edge of the object is within range.
                h = FindHeightGivenX(other.Right);
                line = line < h ? line : h;
            }
            if (this.pointL.X >= other.Left && this.pointL.X <= other.Right)
            {
                // The left point of the floor intersects with the object.
                line = line < this.pointL.Y ? line : this.pointL.Y;
            }
            if (this.pointR.X >= other.Left && this.pointR.X <= other.Right)
            {
                // The right point of the floor intersects with the object.
                line = line < this.pointR.Y ? line : this.pointR.Y;
            }

            if (float.IsInfinity(line))
                return null;
            else
                return line;
        }
示例#2
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;
        }
示例#3
0
 // Empties the contents of a room.
 public virtual void Reset()
 {
     this.floors = new List<Floor>();
     this.blocks = new List<Block>();
     this.cameraTarget = null;
     this.objects = new BufferedList<WorldObject>();
     this.nodes = new NodeManager();
     this.decalsBack = new BufferedList<Decal>();
     this.decalsFront = new BufferedList<Decal>();
 }
示例#4
0
 public bool IntersectsWith(WorldObject other)
 {
     return (this.Right > other.Left && this.Left < other.Right && this.Bottom > other.Top && this.Top < other.Bottom);
 }