Beispiel #1
0
        private void InitArchetypalQuad()
        {
            //SKYBOX
            float halfLength = 0.5f;

            VertexPositionColorTexture[] vertices = new VertexPositionColorTexture[4];
            vertices[0] = new VertexPositionColorTexture(new Vector3(-halfLength, halfLength, 0), Color.White,
                                                         new Vector2(0, 0));
            vertices[1] = new VertexPositionColorTexture(new Vector3(-halfLength, -halfLength, 0), Color.White,
                                                         new Vector2(0, 1));
            vertices[2] = new VertexPositionColorTexture(new Vector3(halfLength, halfLength, 0), Color.White,
                                                         new Vector2(1, 0));
            vertices[3] = new VertexPositionColorTexture(new Vector3(halfLength, -halfLength, 0), Color.White,
                                                         new Vector2(1, 1));

            BasicEffect unlitTexturedEffect = new BasicEffect(graphics.GraphicsDevice)
            {
                VertexColorEnabled = true,
                TextureEnabled     = true
            };

            Transform3D transform3D =
                new Transform3D(Vector3.Zero, Vector3.Zero, Vector3.One, Vector3.UnitZ, Vector3.UnitY);
            BasicEffectParameters effectParameters =
                new BasicEffectParameters(unlitTexturedEffect, Textures["kWall1"], Color.White, 1);
            IVertexData vertexData =
                new VertexData <VertexPositionColorTexture>(vertices, PrimitiveType.TriangleStrip, 2);

            ArchetypalTexturedQuad = new OurPrimitiveObject("original texture quad", ActorType.Decorator,
                                                            StatusType.Drawn | StatusType.Update, transform3D, effectParameters, vertexData);
        }
        /// <summary>
        ///     Our Slave objects that we will later clone are all made here. Like "templates" of objects. (Like Prefabs in Unity)
        /// </summary>
        private void InitStaticModels()
        {
            /*
             * Some initialization
             */

            Color coffeeColor = new Color(111 / 255.0f, 78 / 255.0f, 55 / 255.0f, 0.95f);

            CoffeeEffectParameters coffeeEffect = new CoffeeEffectParameters(main.Effects["Coffee"],
                                                                             main.Textures["CoffeeUV"], main.Textures["CoffeeFlow"], coffeeColor);
            Transform3D            transform3D            = new Transform3D(Vector3.Zero, -Vector3.Forward, Vector3.Up);
            NormalEffectParameters normalEffectParameters = new NormalEffectParameters(main.Effects["Normal"],
                                                                                       main.Textures["Chocolate"], main.Textures["big-normalmap"],
                                                                                       main.Textures["big-displacement"], Color.White, 1, light);

            /*
             * Here we make the static Tiles.
             */

            #region StaticTiles

            //Create the Basic Tile

            Tile chocolateTile = new Tile("ChocolateTile", ActorType.Primitive, StatusType.Drawn | StatusType.Update,
                                          transform3D, normalEffectParameters, main.Models["Cube"],
                                          true, ETileType.Static);

            //Create the Plate Stacks
            BasicEffectParameters effectParameters =
                new BasicEffectParameters(main.ModelEffect, main.Textures["Ceramic"], Color.White, 1);
            Tile plateStackTile = new Tile("plateStackTile", ActorType.Primitive, StatusType.Drawn | StatusType.Update,
                                           transform3D, effectParameters, main.Models["PlateStack"],
                                           true, ETileType.Static);

            //Create the Fork Model
            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["Finish"], Color.White, 1);
            OurModelObject forkModelObject =
                new OurModelObject("fork", ActorType.Decorator, StatusType.Drawn | StatusType.Update, transform3D,
                                   effectParameters, main.Models["Fork"]);
            //forkModelObject.ControllerList.Add(new RandomRotatorController("rotator", ControllerType.Curve));

            //Create the Knife Model
            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["Knife"], Color.White, 1);
            OurModelObject knifeModelObject =
                new OurModelObject("knife", ActorType.Decorator, StatusType.Drawn | StatusType.Update, transform3D,
                                   effectParameters, main.Models["Knife"]);
            //knifeModelObject.ControllerList.Add(new RandomRotatorController("rotator", ControllerType.Curve));

            //Create the Single Plate Model
            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["Finish"], Color.White, 1);
            OurModelObject singlePlateModelObject = new OurModelObject("singlePlate", ActorType.Decorator,
                                                                       StatusType.Drawn | StatusType.Update, transform3D, effectParameters,
                                                                       main.Models["SinglePlate"]);
            //singlePlateModelObject.ControllerList.Add(new RandomRotatorController("rotator", ControllerType.Curve));

            #endregion StaticTiles

            /*
             * Here we create the Tiles that interact with you on collision.
             */

            #region InteractableTiles

            //Create Button Tile
            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["Button"], Color.White, 1);
            ActivatableTile activatable = new ActivatableTile("Button", ActorType.Primitive,
                                                              StatusType.Drawn | StatusType.Update, transform3D, effectParameters,
                                                              main.Models["Button"], false, ETileType.Button);
            activatable.ControllerList.Add(new ColliderComponent("ButtonCC", ControllerType.Collider,
                                                                 OnActivatableCollisionEnter));

            //Create the Puddle (We call them spikes because they kill the player on collision)
            coffeeEffect = (CoffeeEffectParameters)coffeeEffect.Clone();
            coffeeEffect.UvTilesTexture = main.Textures["DropUV"];
            coffeeEffect.CoffeeColor    = new Color(new Color(239, 228, 176), 255);
            Tile spike = new Tile("Spike", ActorType.Primitive, StatusType.Drawn | StatusType.Update, transform3D,
                                  coffeeEffect, main.Models["Puddle"], false, ETileType.Spike);
            spike.ControllerList.Add(new ColliderComponent("CC", ControllerType.Collider, OnHostileCollision));

            //Create the Mug Pickups
            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["Mug"], Color.White, 1);
            Tile pickup = new Tile("Mug", ActorType.Primitive, StatusType.Drawn | StatusType.Update, transform3D,
                                   effectParameters, main.Models["Mug"], false, ETileType.Star);
            pickup.ControllerList.Add(new PlayerDeathComponent("PDC", ControllerType.Event));
            pickup.ControllerList.Add(new ColliderComponent("CC", ControllerType.Collider, OnCollectibleCollision));

            //Create the Goal Tile
            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["sugarbox"], Color.White, 1);
            Tile goal = new Tile("Goal", ActorType.Primitive, StatusType.Drawn | StatusType.Update, transform3D,
                                 effectParameters, main.Models["SugarBox"], false, ETileType.Win);
            goal.ControllerList.Add(new ColliderComponent("CCG", ControllerType.Collider, OnGoalCollided));

            //Create the Checkpoint Tile
            effectParameters =
                new BasicEffectParameters(main.ModelEffect, main.Textures["WhiteSquare"], Color.White, 1);
            Tile checkpoint = new Tile("Checkpoint", ActorType.Primitive, StatusType.Drawn | StatusType.Update,
                                       transform3D, effectParameters, main.Models["Smarties"], false, ETileType.Checkpoint);
            checkpoint.ControllerList.Add(new ColliderComponent("CC", ControllerType.Collider, OnCheckPointCollision));

            #endregion

            /*
             * Here we create the Tiles that can Move
             */

            #region MovableTiles

            //Create the Attachable Tiles
            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["SugarB"], Color.White, 1);
            AttachableTile attachableTile = new AttachableTile("AttachableTile", ActorType.Primitive,
                                                               StatusType.Drawn | StatusType.Update, transform3D, effectParameters,
                                                               main.Models["Cube"], ETileType.Attachable);
            attachableTile.ControllerList.Add(new TileMovementComponent("AttachableTileMC", ControllerType.Movement,
                                                                        300));
            attachableTile.ControllerList.Add(new PlayerDeathComponent("PDC", ControllerType.Event));

            //Create the Player Tile
            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["SugarW"], Color.White, 1);
            PlayerTile playerTile = new PlayerTile("Player", ActorType.Player, StatusType.Drawn, transform3D,
                                                   effectParameters, main.Models["Cube"], ETileType.Player);
            playerTile.ControllerList.Add(new PlayerController("PlayerPC", ControllerType.Player, main.KeyboardManager,
                                                               main.CameraManager));
            TileMovementComponent tileMovementComponent = new TileMovementComponent("PTMC", ControllerType.Movement,
                                                                                    300);
            playerTile.ControllerList.Add(tileMovementComponent);
            playerTile.ControllerList.Add(new PlayerMovementComponent("PlayerMC", ControllerType.Movement));
            playerTile.ControllerList.Add(new PlayerDeathComponent("PDC", ControllerType.Event));

            //Create the Enemy Tiles
            coffeeColor  = new Color(coffeeColor, 255);
            coffeeEffect = new CoffeeEffectParameters(main.Effects["Coffee"], main.Textures["DropUV"],
                                                      main.Textures["CoffeeFlow"], coffeeColor);
            PathMoveTile enemy = new PathMoveTile("Enemy", ActorType.NonPlayer, StatusType.Drawn | StatusType.Update,
                                                  transform3D, coffeeEffect, main.Models["Drop"], false, ETileType.Enemy);
            enemy.ControllerList.Add(new EnemyMovementComponent("emc", ControllerType.Movement, ActivationType.AlwaysOn,
                                                                0.5f, Smoother.SmoothingMethod.Smooth));
            enemy.ControllerList.Add(new ColliderComponent("CC", ControllerType.Collider, OnHostileCollision));

            //Create the Moving Platform Tiles
            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["Biscuit"], Color.White, 1);
            MovingPlatformTile movingPlatform = new MovingPlatformTile("MovingPlatform", ActorType.Platform,
                                                                       StatusType.Drawn | StatusType.Update, transform3D, effectParameters,
                                                                       main.Models["Biscuit"], true, ETileType.MovingPlatform);
            movingPlatform.ControllerList.Add(new PathMovementComponent("platformpmc", ControllerType.Movement,
                                                                        ActivationType.Activated, 0.5f, Smoother.SmoothingMethod.Decelerate));

            //Create the Doors Tiles
            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["Biscuit"], Color.White, 1);
            PathMoveTile doorTile = new PathMoveTile("Door Tile", ActorType.Platform,
                                                     StatusType.Drawn | StatusType.Update, transform3D, effectParameters,
                                                     main.Models["Cube"], true, ETileType.Door);
            doorTile.ControllerList.Add(new DoorMovementComponent("doorPMC", ControllerType.Movement,
                                                                  ActivationType.Activated, 0.5f, Smoother.SmoothingMethod.Accelerate));

            #endregion MovableTiles

            //Now we add them all to our dictionary to later clone.
            drawnActors = new Dictionary <string, OurDrawnActor3D>
            {
                { "StaticTile", chocolateTile },
                { "PlateStackTile", plateStackTile },
                { "AttachableBlock", attachableTile },
                { "PlayerBlock", playerTile },
                { "GoalTile", goal },
                { "EnemyTile", enemy },
                { "ButtonTile", activatable },
                { "MovingPlatformTile", movingPlatform },
                { "DoorTile", doorTile },
                { "SpikeTile", spike },
                { "StarPickupTile", pickup },
                { "CheckpointTile", checkpoint },
                { "Knife", knifeModelObject },
                { "Fork", forkModelObject },
                { "SinglePlate", singlePlateModelObject },
                { "Coffee", coffee }
            };
        }
        /// <summary>
        ///     Sets and puts level Decor at it's place.
        /// </summary>
        private void InitLevelDecor()
        {
            float   size  = 1.5f;
            Vector3 scale = new Vector3(size, size, size);

            BasicEffectParameters effectParameters =
                new BasicEffectParameters(main.ModelEffect, main.Textures["Wood"], Color.White, 1);
            Transform3D    transform3D = new Transform3D(new Vector3(10, -15, 15), Vector3.UnitZ, Vector3.UnitY);
            OurModelObject table       = new OurModelObject("Table", ActorType.Primitive, StatusType.Drawn, transform3D,
                                                            effectParameters, main.Models["Table"])
            {
                Transform3D = { Scale = scale }
            };

            main.ObjectManager.Add(table);

            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["Ceramic"], Color.White, 1);
            OurModelObject cups = new OurModelObject("Cups", ActorType.Primitive, StatusType.Drawn, transform3D,
                                                     effectParameters, main.Models["Cups"])
            {
                Transform3D = { Scale = scale }
            };

            drawnActors.Add("Cups", cups);
            main.ObjectManager.Add(cups);

            effectParameters =
                new BasicEffectParameters(main.ModelEffect, main.Textures["WhiteChocolate"], Color.White, 1);
            OurModelObject choco = new OurModelObject("Chocolate", ActorType.Primitive, StatusType.Drawn, transform3D,
                                                      effectParameters, main.Models["Chocolate"])
            {
                Transform3D = { Scale = scale }
            };

            main.ObjectManager.Add(choco);

            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["blackTile"], Color.White, 1);
            OurModelObject cat = new OurModelObject("Cat", ActorType.Primitive, StatusType.Drawn, transform3D,
                                                    effectParameters, main.Models["Cat"])
            {
                Transform3D = { Scale = scale }
            };

            main.ObjectManager.Add(cat);

            OurModelObject coffeePot = new OurModelObject("CPot", ActorType.Primitive, StatusType.Drawn, transform3D,
                                                          effectParameters, main.Models["Pot"])
            {
                Transform3D = { Scale = scale }
            };

            main.ObjectManager.Add(coffeePot);

            effectParameters =
                new BasicEffectParameters(main.ModelEffect, main.Textures["coffeeSpill"], Color.White, 1);
            OurModelObject coffeeSpill = new OurModelObject("potSpill", ActorType.Primitive, StatusType.Drawn,
                                                            transform3D, effectParameters, main.Models["Spill"])
            {
                Transform3D = { Scale = scale }
            };

            main.ObjectManager.Add(coffeeSpill);

            effectParameters = new BasicEffectParameters(main.ModelEffect, main.Textures["Checkers"], Color.White, 1);
            OurModelObject catBed = new OurModelObject("Catbed", ActorType.Primitive, StatusType.Drawn, transform3D,
                                                       effectParameters, main.Models["CatBed"])
            {
                Transform3D = { Scale = scale }
            };

            main.ObjectManager.Add(catBed);
        }