Ejemplo n.º 1
0
        public override void Initialize()
        {
            // Load background
            ResourcesService resources = game.services.Get <ResourcesService>(ServicesDefinition.Resources);

            title    = resources.Load <SpriteFont>(Constants.fontTitle);
            overview = resources.Load <Texture2D>(Constants.textureOverview);

            // Listen to mouse events
            ControlsGameplayManager gpControls = game.gameplays.Get <ControlsGameplayManager>(GameplaysDefinition.Controls);

            gpControls.OnMouseMove  += new ControlsGameplayManager.OnMouseMoveDelegate(OnMouseMove);
            gpControls.OnMouseClick += new ControlsGameplayManager.OnMouseClickDelegate(OnMouseClick);

            // Register the overview actions
            BackgroundGameplayManager gpBackground = game.gameplays.Get <BackgroundGameplayManager>(GameplaysDefinition.Background);
            InteractiveObject         viewTop      = new InteractiveObject();

            viewTop.ActivationZone = new Rectangle(10, (int)(0.5f * (Constants.windowHeight - 0.4f * overview.Height)), (int)(overview.Width * 0.4f), (int)(overview.Height * 0.133f));
            viewTop.OnAction      += () => { gpBackground.BackgroundMode = BackgroundMode.Aerial; };
            interactives.Add(viewTop);

            InteractiveObject viewOverview = new InteractiveObject();

            viewOverview.ActivationZone = new Rectangle(viewTop.ActivationZone.X, viewTop.ActivationZone.Y + viewTop.ActivationZone.Height, viewTop.ActivationZone.Width, viewTop.ActivationZone.Height);
            viewOverview.OnAction      += () => { gpBackground.BackgroundMode = BackgroundMode.Overview; };
            interactives.Add(viewOverview);

            InteractiveObject viewBottom = new InteractiveObject();

            viewBottom.ActivationZone = new Rectangle(viewTop.ActivationZone.X, viewOverview.ActivationZone.Y + viewTop.ActivationZone.Height, viewTop.ActivationZone.Width, viewTop.ActivationZone.Height);
            viewBottom.OnAction      += () => { gpBackground.BackgroundMode = BackgroundMode.Underground; };
            interactives.Add(viewBottom);
        }
Ejemplo n.º 2
0
        protected void DrawGrid()
        {
            // Get the background manager in order to know the ground level
            BackgroundGameplayManager gpBackground = game.gameplays.Get <BackgroundGameplayManager>(GameplaysDefinition.Background);

            // Fill as many cells as possible
            Vector2 center    = new Vector2(0.5f * (Constants.windowHeight * Constants.windowRatio) - 0.5f * Constants.cellWidth, (float)gpBackground.GroundLevel);
            int     i         = 0;
            int     j         = 0;
            bool    yFinished = false;

            while (!yFinished)
            {
                while (true)
                {
                    Vector2 position = undergroundGrid.GetPosition(-i, j, center, Constants.cellWidth);
                    yFinished = (position.Y > Constants.windowHeight);
                    if (position.X <= 0f)
                    {
                        break;
                    }
                    spriteBatch.Draw(cell, position, null, Color.White, 0f, Vector2.Zero, (float)Constants.cellWidth / (float)cell.Width, SpriteEffects.None, 0f);

                    if (i != 0)
                    {
                        Vector2 opposite = undergroundGrid.GetPosition(i, j, center, Constants.cellWidth);
                        spriteBatch.Draw(cell, opposite, null, Color.White, 0f, Vector2.Zero, (float)Constants.cellWidth / (float)cell.Width, SpriteEffects.None, 0f);
                    }

                    i += 2;
                }
                j -= 1;
                i  = (j % 2);
            }
        }
Ejemplo n.º 3
0
        protected void DrawTree()
        {
            // Get the background manager in order to know the ground level
            BackgroundGameplayManager gpBackground = game.gameplays.Get <BackgroundGameplayManager>(GameplaysDefinition.Background);

            treeGenerator.InitialState.position = new Vector3(0.5f * (Constants.windowHeight * Constants.windowRatio), (float)gpBackground.GroundLevel, 0f);

            // Render top of the tree
            WindGameplayManager gpWind = game.gameplays.Get <WindGameplayManager>(GameplaysDefinition.Wind);

            treeGenerator.InitialState.windIntensity = 0.003f * gpWind.Intensity;
            treeGenerator.Execute();
        }
Ejemplo n.º 4
0
        protected void DrawRoot(UndergroundCell cell, Direction direction)
        {
            // Get the objects we need for the rendering
            ResourcesService          resources    = game.services.Get <ResourcesService>(ServicesDefinition.Resources);
            BackgroundGameplayManager gpBackground = game.gameplays.Get <BackgroundGameplayManager>(GameplaysDefinition.Background);

            // Draw the child root
            {
                // Get the texture matching the cell
                Texture2D tex = resources.Load <Texture2D>($"textures/roots/root-in-{cell.Size}");

                // Get the center of the rendering
                Vector2 center   = new Vector2(0.5f * tex.Width, 0.5f * tex.Height);
                Vector2 offset   = new Vector2(0.5f * (Constants.windowHeight * Constants.windowRatio), (float)(gpBackground.GroundLevel + 0.433f * Constants.cellWidth));
                Vector2 position = undergroundGrid.GetPosition(cell.X, cell.Y, offset, Constants.cellWidth);
                float   rotation = undergroundGrid.GetAngle(direction);

                // Render the root
                spriteBatch.Draw(tex, position, null, Color.White, rotation, center, (float)Constants.cellWidth / (float)tex.Width, SpriteEffects.None, 0f);
            }

            // Draw the parent root
            {
                // Get the texture matching the cell
                Texture2D tex = resources.Load <Texture2D>($"textures/roots/root-out-{cell.Size}");

                // Get the parent cell
                UndergroundCell  parent      = null;
                Tuple <int, int> coordinates = undergroundGrid.GetNeighbourCoordinates(cell, undergroundGrid.GetOppositeDirection(direction));
                if (undergroundGrid.IsCellCreated(coordinates.Item1, coordinates.Item2))
                {
                    parent = undergroundGrid[coordinates.Item1, coordinates.Item2];
                }
                if (parent != null)
                {
                    // Get the center of the rendering
                    Vector2 center   = new Vector2(0.5f * tex.Width, 0.5f * tex.Height);
                    Vector2 offset   = new Vector2(0.5f * (Constants.windowHeight * Constants.windowRatio), (float)(gpBackground.GroundLevel + 0.433f * Constants.cellWidth));
                    Vector2 position = undergroundGrid.GetPosition(parent.X, parent.Y, offset, Constants.cellWidth);
                    float   rotation = undergroundGrid.GetAngle(undergroundGrid.GetOppositeDirection(direction));

                    // Render the root
                    spriteBatch.Draw(tex, position, null, Color.White, rotation, center, (float)Constants.cellWidth / (float)tex.Width, SpriteEffects.None, 0f);

                    Console.WriteLine($"Draw parent {coordinates.Item1},{coordinates.Item2} with size {cell.Size}");
                }
            }
        }