示例#1
0
        /// <summary>
        /// The constructor for a player.
        /// </summary>
        public Player(Vector3 Position, ParentAI AI, Animation animation)
            : base(Position)
        {
            this.AI = AI;
            this.animation = animation;

            UsesIce = true;
            UsesLadders = true;
        }
示例#2
0
        public void LoadTexturesFromFile(String Filename, ContentManager Content)
        {
            // The filename should not have the extension.

            TextReader rawTextureFile = new StreamReader("Content/Texts/" + Filename + ".tin");
            String line;
            do
            {
                line = rawTextureFile.ReadLine();
                if (line != null)
                {
                    // Loads a tileset
                    if (line[0] == '#')
                    {
                        String[] _lineSplit = line.Split('#');

                        Texture2D _texture = Content.Load<Texture2D>("Tilesets/" + _lineSplit[2]);

                        LoadTileset(_lineSplit[2], _texture, int.Parse(_lineSplit[1]));
                    }

                    // Loads an animation.
                    else if (line[0] == '@')
                    {
                        // Splits the data.
                        String[] _lineSplit = line.Split('@');

                        // Loads the texture.
                        Texture2D _texture = Content.Load<Texture2D>("Animations/" + _lineSplit[2]);

                        // Gets the grid width.
                        int gridWidth = int.Parse(_lineSplit[1]);

                        float frameSize = _texture.Width / gridWidth;

                        // Creates a new animation.
                        Animation _ani = new Animation(_texture);

                        for (int i = 3; i < _lineSplit.Length; i++)
                        {
                            // Creates a new list to hold texture data.
                            List<TextureData> _smallAni = new List<TextureData>();

                            // Gets the frames in this smaller animation.
                            int _frames = int.Parse(_lineSplit[i]);

                            // Loads individual frames.
                            for (int f = 0; f < _frames; f++)
                            {
                                TextureData _tex = new TextureData(
                                    _lineSplit[2] + (i-3).ToString() + "_" + f.ToString(),
                                    _texture,
                                    new Vector2((float)f / (float)gridWidth, frameSize * (i-3) / (float)_texture.Height),
                                    new Vector2(1f / (float)gridWidth, frameSize / (float)_texture.Height));

                                _smallAni.Add(_tex);
                            }

                            _ani.AniList.Add(_smallAni);
                        }

                        AniDic.Add(_lineSplit[2], _ani);
                    }

                    // Loads a single image
                    else
                    {
                        Texture2D _texture = Content.Load<Texture2D>("Textures/" + line);
                        AddTexture(new TextureData(line, _texture));
                    }
                }
            }
            while (line != null);

            rawTextureFile.Close();
        }