예제 #1
0
        public void Release()
        {
            MyCollection.Release();
            MyCollection = null;

            MyType    = null;
            MyTileSet = null;

            MyLevel = null;
        }
예제 #2
0
        public static Background UseCode(BackgroundTemplate template, Background b)
        {
            b.MyCollection.Lists.Clear();

            template.Code(b);

            b.SetLevel(b.MyLevel);
            b.SetBackground(b);

            //b.Move(new Vector2(Tools.GlobalRnd.RndFloat(0, -15000), 0));

            b.Reset();

            return(b);
        }
예제 #3
0
        public static void Load(string path)
        {
            BackgroundTemplate template;

            if (PathLookup.ContainsKey(path))
            {
                template = PathLookup[path];
            }
            else
            {
                template = new BackgroundTemplate();

                var name = Tools.GetFileName(path);
                template.Name = name;
                template.File = path;

                AddTemplate(template);
            }

            template.MadeOfCode = false;
            template.MadeOfText = true;
        }
예제 #4
0
        public override void Init(Level level)
        {
            MyLevel      = level;
            MyCollection = new BackgroundCollection(MyLevel);
            TR           = new Vector2(5000, 2000);
            BL           = new Vector2(-2000, -2000);

            if (MyTemplate != null)
            {
                if (MyTemplate.MadeOfCode)
                {
                    if (level.Geometry == LevelGeometry.Up || level.Geometry == LevelGeometry.Down)
                    {
                        MyTemplate = BackgroundType._Castle_Vertical;
                    }

                    UseCode(MyTemplate, this);
                }
                else if (MyTemplate.MadeOfText)
                {
                    Load(MyTemplate.File);
                }
            }
        }
예제 #5
0
 public static void AddTemplate(BackgroundTemplate template)
 {
     NameLookup.AddOrOverwrite(template.Name, template);
     PathLookup.AddOrOverwrite(template.File, template);
 }
예제 #6
0
 public static Background Get(BackgroundTemplate Type)
 {
     return(Type.MakeInstanceOf());
 }
예제 #7
0
        /// <summary>
        /// Read tileset info from a file.
        /// </summary>
        public void Read(String path)
        {
            MyPath = path;
            _Start();

            // Find path
            Tools.UseInvariantCulture();
            FileStream stream        = null;
            string     original_path = path;

            try
            {
                stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None);
            }
            catch
            {
                try
                {
                    path   = Path.Combine(Globals.ContentDirectory, original_path);
                    stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None);
                }
                catch
                {
                    try
                    {
                        path   = Path.Combine(Globals.ContentDirectory, Path.Combine("DynamicLoad", original_path));
                        stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None);
                    }
                    catch
                    {
                        Tools.Log(string.Format("Attempting to load a .tileset file. Path <{0}> not found."));
                    }
                }
            }


            StreamReader reader = new StreamReader(stream);

            String line;

            line = reader.ReadLine();
            while (line != null)
            {
                var bits = Tools.GetBitsFromLine(line);

                if (bits.Count > 1)
                {
                    var first = bits[0];

                    // Is it a pillar?
                    if (first.Contains("Pillar_"))
                    {
                        ParseBlock(bits, first, Pillars);
                    }
                    // Is it a platform?
                    else if (first.Contains("Platform_"))
                    {
                        ParseBlock(bits, first, Platforms);
                    }
                    // Is it a ceiling?
                    else if (first.Contains("Ceiling_"))
                    {
                        HasCeiling = true;
                        var pq = ParseBlock(bits, first, Ceilings);
                        pq.Data.BottomFlush = true;
                    }
                    // Is it a start piece?
                    if (first.Contains("Start_"))
                    {
                        ParseBlock(bits, first, StartBlock);
                    }
                    // Is it an end piece?
                    if (first.Contains("End_"))
                    {
                        ParseBlock(bits, first, EndBlock);
                    }
                    // Is it a moving block?
                    else if (first.Contains("MovingBlock_"))
                    {
                        ParseBlock(bits, first, MyTileSetInfo.MovingBlocks.Group);
                    }
                    // Is it an elevator block?
                    else if (first.Contains("Elevator_"))
                    {
                        ParseBlock(bits, first, MyTileSetInfo.Elevators.Group);
                    }
                    // Is it a pendulum block?
                    else if (first.Contains("Pendulum_"))
                    {
                        ParseBlock(bits, first, MyTileSetInfo.Pendulums.Group);
                    }
                    // Is it a falling block?
                    else if (first.Contains("FallingBlock_"))
                    {
                        ParseBlock(bits, first, MyTileSetInfo.FallingBlocks.Group);
                    }
                    // Is it a bouncy block?
                    else if (first.Contains("BouncyBlock_"))
                    {
                        ParseBlock(bits, first, MyTileSetInfo.BouncyBlocks.Group);
                    }
                    else
                    {
                        switch (first)
                        {
                        case "sprite_anim":
                            var dict = Tools.GetLocations(bits, "name", "file", "size", "frames", "frame_length", "reverse_at_end");

                            var name = bits[dict["name"] + 1];
                            var file = bits[dict["file"] + 1];

                            AnimationData_Texture sprite_anim = null;
                            if (dict.ContainsKey("frames"))
                            {
                                int start_frame = int.Parse(bits[dict["frames"] + 1]);
                                int end_frame;
                                if (bits[dict["frames"] + 2][0] == 't')
                                {
                                    end_frame = int.Parse(bits[dict["frames"] + 3]);
                                }
                                else
                                {
                                    end_frame = int.Parse(bits[dict["frames"] + 2]);
                                }
                                sprite_anim = new AnimationData_Texture(file, start_frame, end_frame);
                            }

                            if (dict.ContainsKey("frame_length"))
                            {
                                var frame_length = int.Parse(bits[dict["frame_length"] + 1]);
                                sprite_anim.Anims[0].Speed = 1f / frame_length;
                            }

                            Tools.TextureWad.Add(sprite_anim, name);

                            break;

                        case "BackgroundFile":
                            BackgroundTemplate template;
                            try
                            {
                                template = BackgroundType.NameLookup[bits[1]];
                            }
                            catch
                            {
                                template      = new BackgroundTemplate();
                                template.Name = bits[1];
                            }

                            MyBackgroundType = template;

                            break;

                        case "Name": Name = bits[1]; break;

                        default:
                            Tools.ReadLineToObj(MyTileSetInfo, bits);
                            break;
                        }
                    }
                }

                line = reader.ReadLine();
            }

            reader.Close();
            stream.Close();

            _Finish();
        }