public void Load()
        {
            // Music testing
            CodeVariant = 3;

            if (CodeVariant == 1)
            {
                BackgroundMusicIntro = Engine.AssetLoader.Get <AudioAsset>("Audio/Frozen Cave Intro.wav");
                BackgroundMusic      = Engine.AssetLoader.Get <AudioAsset>("Audio/Frozen Cave 12.wav");

                IntroLayer = Engine.Host.Audio.CreateLayer("Audio/Intro layer", 1);
                CustomAudioTrack fcIntro = new CustomAudioTrack(BackgroundMusicIntro, 11.29f, PlayMainTrackOnMainLayer);
                IntroLayer.AddToQueue(fcIntro);

                MainLayer = Engine.Host.Audio.CreateLayer("Main layer", 1);
            }
            else if (CodeVariant == 2)
            {
                //BackgroundMusicIntro = Engine.AssetLoader.Get<AudioAsset>("Frozen Cave Intro 2.wav");
                //BackgroundMusic = Engine.AssetLoader.Get<AudioAsset>("Frozen Cave 12.wav");

                BackgroundMusicIntro = Engine.AssetLoader.Get <AudioAsset>("Audio/Frozen Cave Intro 4.wav");
                BackgroundMusic      = Engine.AssetLoader.Get <AudioAsset>("Audio/Frozen Cave Loop 3.wav");

                SecondaryLayer = Engine.Host.Audio.CreateLayer("Secondary layer", 1);
                SecondaryLayer.AddToQueue(BackgroundMusicIntro);
                SecondaryLayer.AddToQueue(BackgroundMusic);
            }

            // Texture loading should be done before any texture usages
            // to make sure they are loaded in parallel
            TextureLoader.Load(LoadedRoom.Textures);

            // Init the player
            Player = new Midori(LoadedRoom.Spawn);
            Units.Add(Player);

            // Init the camera
            Engine.Renderer.Camera = new ScalableArtCamera(new Vector3(Player.X, 540, 0), 1f);

            // Set the TextureArrayLimit to 1 for GPU's that support only zero indexing
            // Engine.Renderer.TextureArrayLimit = 1;

            // Create units
            foreach (ConfigUnit configUnit in LoadedRoom.Units)
            {
                Unit unit;
                switch (configUnit.Type)
                {
                case "Shishi":
                    unit = new Shishi(configUnit.Name, configUnit.TextureName, configUnit.Position, configUnit.Size);
                    break;

                default:
                    throw new Exception("No applicable classes");
                }
                Units.Add(unit);
                NonPlayerUnits.Add(unit);
            }

            // Magic Flows
            MagicFlow m = new MagicFlow();

            m.AddSegment(new Collision.LineSegment(100, 5400, 950, 4600));
            m.AddSegment(new Collision.LineSegment(950, 4600, 1450, 4800));
            m.AddSegment(new Collision.LineSegment(1450, 4800, 2000, 4200));
            MagicFlows.Add(m);

            m = new MagicFlow();
            m.AddSegment(new Collision.LineSegment(1450, 5400, 1750, 5300));
            m.AddSegment(new Collision.LineSegment(1750, 5300, 1950, 5200));
            m.AddSegment(new Collision.LineSegment(1950, 5200, 2050, 5100));
            m.AddSegment(new Collision.LineSegment(2050, 5100, 2100, 5000));
            m.AddSegment(new Collision.LineSegment(2100, 5000, 2100, 4900));
            m.AddSegment(new Collision.LineSegment(2100, 4900, 2050, 4800));
            m.AddSegment(new Collision.LineSegment(2050, 4800, 1950, 4700));
            m.AddSegment(new Collision.LineSegment(1950, 4700, 1750, 4600));
            MagicFlows.Add(m);

            // Create platforms
            for (int i = 0; i < LoadedRoom.CollisionPlatforms.Count; i++)
            {
                ConfigCollisionPlatform configPlatform = LoadedRoom.CollisionPlatforms[i];
                Collision.LineSegment   realPlatform   = new Collision.LineSegment(configPlatform.PointA, configPlatform.PointB);
                if (realPlatform.IsSloped)
                {
                    SlopedCollisionPlatforms.Add(realPlatform);
                }
                else
                {
                    AxisAlignedCollisionPlatforms.Add(realPlatform);
                }

                CollisionPlatforms.Add(realPlatform);
            }

            // Create decorations
            // Backgrounds
            for (int i = 0; i < LoadedRoom.Backgrounds.Count; i++)
            {
                ConfigDecoration configDecor = LoadedRoom.Backgrounds[i];
                Backgrounds.Add(
                    new Decoration(
                        configDecor.Name,
                        configDecor.TextureName,
                        configDecor.Size,
                        configDecor.Position,
                        configDecor.DisplaySize,
                        configDecor.TextureArea,
                        configDecor.FlipX,
                        configDecor.BlurIntensity,
                        configDecor.ShadowReverseIntensity
                        )
                    );
            }
            // Background Decorations
            for (int i = 0; i < LoadedRoom.BackgroundDecorations.Count; i++)
            {
                ConfigDecoration configDecor = LoadedRoom.BackgroundDecorations[i];
                BackgroundDecorations.Add(
                    new Decoration(
                        configDecor.Name,
                        configDecor.TextureName,
                        configDecor.Size,
                        configDecor.Position,
                        configDecor.DisplaySize,
                        configDecor.TextureArea,
                        configDecor.FlipX,
                        configDecor.BlurIntensity,
                        configDecor.ShadowReverseIntensity
                        )
                    );
            }
            // Foreground Decorations
            for (int i = 0; i < LoadedRoom.ForegroundDecorations.Count; i++)
            {
                ConfigDecoration configDecor = LoadedRoom.ForegroundDecorations[i];
                ForegroundDecorations.Add(
                    new Decoration(
                        configDecor.Name,
                        configDecor.TextureName,
                        configDecor.Size,
                        configDecor.Position,
                        configDecor.DisplaySize,
                        configDecor.TextureArea,
                        configDecor.FlipX,
                        configDecor.BlurIntensity,
                        configDecor.ShadowReverseIntensity
                        )
                    );
            }

            for (int i = 0; i < LoadedRoom.SceneChangers.Count; i++)
            {
                SceneChanger sceneChanger = LoadedRoom.SceneChangers[i];
                SceneChangers.Add(sceneChanger);
            }
        }
示例#2
0
        public void CreateObjects()
        {
            // Create a dictionary to map GIDs to their source images
            foreach (TmxTileset tileset in Tilesets)
            {
                string[] sourceSplit = tileset.Source.Split("/");
                TilesetMap.Add(tileset.FirstGid, sourceSplit[sourceSplit.Length - 1]);
                // TODO - Possibly load textures asynchronously here
                // or add them to MainScene.Textures to pass to TextureLoader.Load although that won't help
                // because the Decoration constructor will Get/Load them before the TextureLoader
            }

            foreach (TmxObjectLayer objLayer in ObjectLayers)
            {
                foreach (TmxObject obj in objLayer.Objects)
                {
                    if (objLayer.Name.Contains("Platforms"))
                    {
                        if (obj.ObjectType == TmxObjectType.Polyline)
                        {
                            for (int i = 0; i < obj.Lines.Count; i++)
                            {
                                LineSegment platform = new LineSegment(obj.Lines[i].Start, obj.Lines[i].End);

                                if (platform.IsSloped)
                                {
                                    SlopedCollisionPlatforms.Add(platform);
                                }
                                else
                                {
                                    AxisAlignedCollisionPlatforms.Add(platform);
                                }

                                CollisionPlatforms.Add(platform);
                            }
                        }
                    }
                    else if (objLayer.Name.Contains("Magic Flows"))
                    {
                        if (obj.ObjectType == TmxObjectType.Polyline)
                        {
                            MagicFlow flow = new MagicFlow();

                            for (int i = 0; i < obj.Lines.Count; i++)
                            {
                                LineSegment platform = new LineSegment(obj.Lines[i].Start, obj.Lines[i].End);

                                flow.AddSegment(platform);
                            }

                            MagicFlows.Add(flow);
                        }
                    }
                    else if (objLayer.Name.Contains("Assets"))
                    {
                        if (obj.ObjectType == TmxObjectType.Image)
                        {
                            if (obj.Gid == null)
                            {
                                continue;
                            }

                            float decorationZ;
                            try
                            {
                                float.TryParse(obj.Properties["Z"], out decorationZ);
                            }
                            catch (KeyNotFoundException)
                            {
                                decorationZ = 3;
                            }

                            // In Tiled an image's X,Y coordinates represent the bottom-left corner of the image
                            Decoration decoration = new Decoration(
                                "Asset" + obj.X,
                                TilesetMap[(int)obj.Gid],
                                new Vector2((float)obj.Width, (float)obj.Height),
                                new Vector3((float)obj.X, (float)obj.Y, decorationZ),
                                new Vector2((float)obj.Width, (float)obj.Height),
                                null,
                                false,
                                Maths.DegreesToRadians((float)obj.Rotation)
                                );

                            BackgroundDecorations.Add(decoration);
                        }
                    }
                }
            }
        }