Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FreezingArcher.Game.MazeTest"/> class.
        /// </summary>
        /// <param name="messageProvider">The message provider for this instance.</param>
        /// <param name="objmnr">The object manager for this instance.</param>
        /// <param name="rendererContext">The renderer context for the maze scenes.</param>
        /// <param name="game">The game the maze should be generated in.</param>
        public MazeTest (MessageProvider messageProvider, ObjectManager objmnr, RendererContext rendererContext,
            Content.Game game, Application app, CompositorNodeScene sceneNode,
            CompositorImageOverlayNode healthOverlayNode, CompositorColorCorrectionNode colorCorrectionNode,
            CompositorNodeOutput outputNode, CompositorWarpingNode warpingNode)
        {
            ValidMessages = new[] {
                (int) MessageId.Input,
                (int) MessageId.Update,
                (int) MessageId.HealthChanged,
                (int) MessageId.CollisionDetected,
                (int) MessageId.StaminaChanged,
                (int) MessageId.ItemUse,
                (int) MessageId.FlashlightToggled
            };
            messageProvider += this;
            mazeGenerator = new MazeGenerator (objmnr);

            MazeSceneNode = sceneNode;
            HealthOverlayNode = healthOverlayNode;
            ColorCorrectionNode = colorCorrectionNode;
            OutputNode = outputNode;
            WarpingNode = warpingNode;
            this.game = game;
            application = app;

            FPS_Text = new Gwen.ControlInternal.Text (app.RendererContext.Canvas);
            FPS_Text.String = "0 FPS";
            FPS_Text.Font = new Gwen.Font (app.RendererContext.GwenRenderer);
            FPS_Text.SetPosition (5, 5);
            FPS_Text.Font.Size = 15;
            FPS_Text.Hide ();

            HealthOverlayNode.OverlayTexture = rendererContext.CreateTexture2D ("bloodsplatter", true, "Content/bloodsplatter.png");
            HealthOverlayNode.Factor = 0;
            HealthOverlayNode.Blending = OverlayBlendMode.Multiply;
            warpingNode.WarpTexture = rendererContext.CreateTexture2D ("warp", true, "Content/warp.jpg");

            game.SceneNode = MazeSceneNode;

            game.AddGameState ("maze_overworld", Content.Environment.Default, null);
            var state = game.GetGameState ("maze_overworld");

            state.Scene = new CoreScene (rendererContext, messageProvider);
            state.Scene.SceneName = "MazeOverworld";
            state.Scene.Active = false;
            state.Scene.BackgroundColor = Color4.Fuchsia;
            state.Scene.DistanceFogIntensity = 0.07f;
            state.Scene.AmbientColor = Color4.White;
            state.Scene.AmbientIntensity = 0.3f;
            state.Scene.MaxRenderingDistance = 1000.0f;

            state.AudioContext = new AudioContext (state.MessageProxy);

            state.MessageProxy.StartProcessing ();

            loadingScreen = new LoadingScreen (application, messageProvider, "Content/loading.png",
                "MazeLoadingScreen",
                new[] { new Tuple<string, GameStateTransition> ("main_menu", GameStateTransition.DefaultTransition) },
                new[] { new Tuple<string, GameStateTransition> (state.Name, new GameStateTransition (0)) });

            endScreen = new EndScreen (application, rendererContext, new Tuple<string, GameStateTransition>[] {
                new Tuple<string, GameStateTransition> ("maze_overworld", GameStateTransition.DefaultTransition),
                new Tuple<string, GameStateTransition> ("maze_underworld", GameStateTransition.DefaultTransition)
            });

            game.SwitchToGameState ("MazeLoadingScreen");

            Player = EntityFactory.Instance.CreateWith ("player", state.MessageProxy, new[] {
                typeof(HealthComponent),
                typeof(StaminaComponent)
            }, new[] {
                typeof(MovementSystem),
                typeof(KeyboardControllerSystem),
                typeof(MouseControllerSystem),
                typeof(SkyboxSystem),
                typeof(PhysicsSystem)
            });

            inventoryGui = new InventoryGUI (app, state, Player, messageProvider, warpingNode);
            var inventory = new Inventory (messageProvider, state, Player, new Vector2i (5, 7), 9);
            inventoryGui.Init (rendererContext.Canvas, inventory);

            PauseMenu = new PauseMenu (application, ColorCorrectionNode, rendererContext.Canvas,
                () => maze [currentMaze].AIManager.StartThinking (), () => maze [currentMaze].AIManager.StopThinking ());
            
            AddAudio (state);

            // embed new maze into game state logic and create a MoveEntityToScene
            SkyboxSystem.CreateSkybox (state.Scene, Player);
            Player.GetComponent<TransformComponent> ().Position = new Vector3 (0, 1.85f, 0);
            var maze_cam_entity = EntityFactory.Instance.CreateWith ("maze_cam_transform", state.MessageProxy, new[] { typeof(TransformComponent) });
            var maze_cam_transform = maze_cam_entity.GetComponent<TransformComponent> ();
            var maze_cam = new BaseCamera (maze_cam_entity, state.MessageProxy, orthographic: true);
            state.Scene.CameraManager.AddCamera (maze_cam, "maze");
            maze_cam_transform.Position = new Vector3 (115, 240, 110);
            maze_cam_transform.Rotation = Quaternion.FromAxisAngle (Vector3.UnitX, MathHelper.PiOver2);
            state.Scene.CameraManager.AddCamera (new BaseCamera (Player, state.MessageProxy), "player");

            RigidBody playerBody = new RigidBody (new SphereShape (1f));
            playerBody.Position = Player.GetComponent<TransformComponent> ().Position.ToJitterVector ();
            playerBody.AllowDeactivation = false;
            playerBody.Material.StaticFriction = 0f;
            playerBody.Material.KineticFriction = 0f;
            playerBody.Material.Restitution = 0.1f;
            //playerBody.Mass = 1000000.0f;
            playerBody.Update ();
            Player.GetComponent<PhysicsComponent> ().RigidBody = playerBody;
            Player.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
            Player.GetComponent<PhysicsComponent> ().PhysicsApplying = AffectedByPhysics.Position;

            #if PRESENTATION
            Player.GetComponent<HealthComponent>().MaximumHealth = 500;
            Player.GetComponent<HealthComponent>().Health = 500;
            #endif

            state.PhysicsManager.World.AddBody (playerBody);

            int seed = new FastRandom ().Next ();
            var rand = new FastRandom (seed);
            Logger.Log.AddLogEntry (LogLevel.Debug, "MazeTest", "Seed: {0}", seed);

            #if PRESENTATION
            maze [0] = mazeGenerator.CreateMaze<OverworldMazeTheme> (rand.Next (), state.MessageProxy, state.PhysicsManager, app.AudioManager, 10, 10);
            #else
            maze [0] = mazeGenerator.CreateMaze<OverworldMazeTheme> (rand.Next (), state.MessageProxy, state.PhysicsManager, app.AudioManager, 30, 30);
            #endif
            maze [0].PlayerPosition += Player.GetComponent<TransformComponent> ().Position;
            maze [0].AIManager.RegisterEntity (Player);

            for (int i = 0; i < OverworldScobisCount; i++)
            {
                ScobisInstances.Add (new Scobis (state, maze [0].AIManager, rendererContext));
            }

            for (int i = 0; i < OverworldCaligoCount; i++)
            {
                CaligoInstances.Add (new Caligo (state, maze [0].AIManager, rendererContext, warpingNode));
            }

            for (int i = 0; i < OverworldViridionCount; i++)
            {
                ViridionInstances.Add (new Viridion (state, maze [0].AIManager, rendererContext, ColorCorrectionNode)); 
            }

            for (int i = 0; i < OverworldGhostCount; i++)
            {
                GhostInstances.Add (new Ghost (state, maze [0].AIManager, rendererContext, ColorCorrectionNode));
            }

            game.AddGameState ("maze_underworld", Content.Environment.Default,
                new[] { new Tuple<string, GameStateTransition> ("maze_overworld", new GameStateTransition (0)) },
                new[] { new Tuple<string, GameStateTransition> ("maze_overworld", new GameStateTransition (0)),
                    new Tuple<string, GameStateTransition> ("endscreen_state", new GameStateTransition (0))
                });
            state = game.GetGameState ("maze_underworld");
            state.Scene = new CoreScene (rendererContext, messageProvider);
            state.Scene.SceneName = "MazeUnderworld";
            state.Scene.Active = false;
            state.Scene.BackgroundColor = Color4.AliceBlue;
            state.Scene.DistanceFogIntensity = 0.07f;
            state.Scene.AmbientColor = Color4.White;
            state.Scene.AmbientIntensity = 0.3f;
            state.Scene.MaxRenderingDistance = 1000.0f;

            state.AudioContext = new AudioContext (state.MessageProxy);

            AddAudio (state);

            state.Scene.CameraManager.AddCamera (new BaseCamera (Player, state.MessageProxy), "player");
            #if PRESENTATION
            maze [1] = mazeGenerator.CreateMaze<UnderworldMazeTheme> (rand.Next (), state.MessageProxy, state.PhysicsManager, app.AudioManager, 10, 10);
            #else
            maze [1] = mazeGenerator.CreateMaze<UnderworldMazeTheme> (rand.Next (), state.MessageProxy, state.PhysicsManager, app.AudioManager, 30, 30);
            #endif
            maze [1].PlayerPosition += Player.GetComponent<TransformComponent> ().Position;
            maze [1].AIManager.RegisterEntity (Player);

            Func<int, int, bool> containsPortalFunc = (x, y) =>
            {
                foreach (var m in maze)
                {
                    var cell = m.entities [x, y].GetComponent<PhysicsComponent> ().RigidBody.Tag as MazeCell;
                    if (cell != null && cell.IsPortal)
                    {
                        return true;
                    }
                }
                return false;
            };

            mazeWallMover = new MazeWallMover (maze [0], maze [1], game.GetGameState ("maze_overworld"), containsPortalFunc);

            state.MessageProxy.StopProcessing ();
            //game.SwitchToGameState("maze_overworld");

            for (int i = 0; i < UnderworldCaligoCount; i++)
            {
                CaligoInstances.Add (new Caligo (state, maze [1].AIManager, rendererContext, warpingNode));
            }

            for (int i = 0; i < UnderworldPassusCount; i++)
            {
                PassusInstances.Add (new Passus (ColorCorrectionNode, state, maze [1].AIManager, rendererContext));
            }

            for (int i = 0; i < UnderworldRoachesCount; i++)
            {
                RoachesInstances.Add(new Roaches (state, maze [0].AIManager, rendererContext));
            }

            for (int i = 0; i < UnderworldFenFireCount; i++)
            {
                FenFireInstances.Add (new FenFire (state, maze [1].AIManager, rendererContext));
            }
        }