Exemplo n.º 1
0
        /// <summary>
        /// Constructs a random sprite with all the appropriate timing
        /// and color information required.
        /// </summary>
        public ISprite CreateRandomSprite()
        {
            // Get a random type
            AssetSprite ras = RandomAssetSprite;

            if (ras.Drawables.Count == 0)
            {
                throw new Exception("No defined sprites for " + ras.Name);
            }

            // If we have one frame, its simple
            if (ras.Drawables.Count == 1)
            {
                ISprite ds = new DrawableSprite(ras.Drawables[0]);
                ds.ID = name;
                return(ds);
            }

            // Otherwise, create a fixed rate (for now)
            FixedRateDrawableSprite fix = new FixedRateDrawableSprite();

            fix.FPS = 3;
            fix.ID  = name;
            fix.Drawables.AddAll(ras.Drawables);
            return(fix);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a specific asset type, either using the data in the
        /// hash or creating a new one and adding it.
        /// </summary>
        public AssetSprite GetAssetSprite(string key)
        {
            // Scan through the list first
            foreach (AssetSprite sprite in sprites)
            {
                if (sprite.Name == key)
                {
                    return(sprite);
                }
            }

            // Create a new one
            AssetSprite nas = new AssetSprite(key);

            sprites.Add(nas);
            return(nas);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads a specific asset type, either using the data in the
        /// hash or creating a new one and adding it.
        /// </summary>
        public AssetSprite GetAssetSprite(string key)
        {
            // Scan through the list first
            foreach (AssetSprite sprite in sprites)
                if (sprite.Name == key)
                    return sprite;

            // Create a new one
            AssetSprite nas = new AssetSprite(key);
            sprites.Add(nas);
            return nas;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Function to queue up all the assets required for the
        /// functioning of the system.
        /// </summary>
        public void Queue()
        {
            // Scan the Assets/Images directory for drawables
            DirectoryInfo images = new DirectoryInfo(
                Path.Combine("Assets", "Images"));
            DirectoryInfo sounds = new DirectoryInfo(
                Path.Combine("Assets", "Sounds"));

            // Load the individual images into memory
            foreach (FileInfo fi in images.GetFiles("*.png"))
            {
                // Load these images
                QueueDrawable("Assets/Images/" + fi.Name);
            }

            // Load the individual directories
            Regex regex = new Regex(@"(\s+\d+)?\.png");

            foreach (DirectoryInfo di in images.GetDirectories())
            {
                // Ignore some common ones
                if (di.Name.StartsWith("."))
                {
                    continue;
                }

                // Get the asset sprite type for this directory
                string key = di.Name;

                if (!sprites.Contains(key))
                {
                    sprites[key] = new AssetSpriteType(key);
                }

                AssetSpriteType spriteType = sprites[key];

                // Load the type information, if we have one
                if (File.Exists(Path.Combine(di.FullName, "block.xml")))
                {
                    // Load the block information, this controls the
                    // color of the blocks.
                    LoadAssetTypeMeta(spriteType,
                                      new FileInfo(Path.Combine(di.FullName, "block.xml")));
                }

                // Go through each file in this directory
                foreach (FileInfo fi in di.GetFiles("*.png"))
                {
                    // Figure out the components
                    string path = String.Format("Assets/Images/{0}/{1}",
                                                key, fi.Name);
                    string key2 = regex.Replace(fi.Name, "");

                    // Get the asset sprite
                    AssetSprite sprite = spriteType.GetAssetSprite(key2);

                    // Queue loading the drawable
                    Queue(new AssetLoaderSprite(sprite, path));
                }
            }

            // Look for sounds and music
            foreach (DirectoryInfo di in sounds.GetDirectories())
            {
                // Go through each file in this directory. The
                // directory name is the category of music while the
                // individual files are randomly selected from the
                // category.
                // "Vorbis is the new mp3"
                foreach (FileInfo fi in di.GetFiles("*.ogg"))
                {
                    // We want to register this file with the sound
                    // manager. Since the SoundManager doesn't load
                    // things, we are just registering directory with
                    // it.
                    Game.Sound.Register(di.Name, fi);
                }
            }
        }
Exemplo n.º 5
0
 public AssetLoaderSprite(AssetSprite sprite, string path)
 {
     this.sprite = sprite;
     Filename    = path;
 }
Exemplo n.º 6
0
 public AssetLoaderSprite(AssetSprite sprite, string path)
 {
     this.sprite = sprite;
     Filename = path;
 }