Example #1
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);

            graphics.PreferredBackBufferWidth  = ScreenData.Get().GetFullScreenWidth();
            graphics.PreferredBackBufferHeight = ScreenData.Get().GetFullScreenHeight();
            //graphics.IsFullScreen = true;

            graphics.ApplyChanges();
            Content.RootDirectory = "Content";
        }
Example #2
0
        double prevRadius = 0;       // the previous radius

        public Leaf(KeySet keySet, Color color)
        {
            this.keySet = keySet;
            this.color  = color;

            this.pos     = new CartesianVector((ScreenData.Get().GetFullScreenWidth() / 2) - 300, ScreenData.Get().GetFullScreenHeight() / 4);
            this.anchor  = new CartesianVector(pos.x + 300, pos.y);
            this.vel     = new PhysicsVector(0, 0);
            this.gravity = new PhysicsVector(Math.PI / 2, .1);
            UpdateAngle();

            this.maxSpeed = 8;
        }
Example #3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            screenWidth     = ScreenData.Get().GetFullScreenWidth();
            maxScreenWidth  = screenWidth * 2;
            screenHeight    = ScreenData.Get().GetFullScreenHeight();
            maxScreenHeight = screenHeight * 2;
            screenRatio     = screenWidth / ScreenData.Get().GetFullScreenWidth();

            leaves.Add(new Leaf(new KeySet(Keys.Up, Keys.Down, Keys.Left, Keys.Right), Color.GreenYellow));
            leaves.Add(new Leaf(new KeySet(Keys.W, Keys.S, Keys.A, Keys.D), Color.DarkRed));
            leaves.RemoveRange(numPlayers, leaves.Count - numPlayers);
            // TODO: Add your initialization logic here
            leafTexture   = Content.Load <Texture2D>("leaf");
            vectorTexture = Content.Load <Texture2D>("Vector");
            anchorTexture = Content.Load <Texture2D>("Anchor");
            base.Initialize();
        }
Example #4
0
        public void CheckMapBounds()
        {
            int minObjX = screenX + screenWidth / 2;
            int maxObjX = screenX + screenWidth / 2;
            int minObjY = screenY + screenHeight / 2;
            int maxObjY = screenY + screenHeight / 2;

            if (screenRatio > 1)             // If the screen is larger than normal, then set it back to normal
            {
                int deltaScreen = screenWidth - ScreenData.Get().GetFullScreenWidth();
                if (deltaScreen > 0)
                {
                    screenX    += deltaScreen / 2;
                    screenWidth = ScreenData.Get().GetFullScreenWidth();
                }
                deltaScreen = screenHeight - ScreenData.Get().GetFullScreenHeight();
                if (deltaScreen > 0)
                {
                    screenY     += deltaScreen / 2;
                    screenHeight = ScreenData.Get().GetFullScreenHeight();
                }
            }

            foreach (Leaf leaf in leaves)
            {
                if (leaf.pos.x > maxObjX)
                {
                    maxObjX = (int)leaf.pos.x;
                }
                else if (leaf.pos.x < minObjX)
                {
                    minObjX = (int)leaf.pos.x;
                }
                if (leaf.pos.y > maxObjY)
                {
                    maxObjY = (int)leaf.pos.y;
                }
                else if (leaf.pos.y < minObjY)
                {
                    minObjY = (int)leaf.pos.y;
                }
            }

            // Hard bounds on max and min obj X;
            if (minObjX < -ScreenData.Get().GetFullScreenWidth())
            {
                minObjX = -ScreenData.Get().GetFullScreenWidth();
            }
            if (maxObjX > ScreenData.Get().GetFullScreenWidth() + screenWidth)
            {
                maxObjX = ScreenData.Get().GetFullScreenWidth() + screenWidth;
            }


            if (minObjX < screenX + borderX)                         // Check to see if there's an object OOB Left
            {
                screenX = minObjX - borderX;                         // Correct OOB Left
            }
            if (maxObjX > screenX + screenWidth - borderX)           // Check to see if there's an object OOB Right
            {                                                        // We need to move the screen to the right
                if (maxObjX - minObjX > screenWidth - (2 * borderX)) // Check to see if both objects can fit on the screen
                {                                                    // No, so we need to scale up the screen
                    screenWidth = maxObjX - screenX + borderX;       // Correct OOB Right
                }
                else                                                 // Yes, we can move the screen to the right
                {
                    screenX = maxObjX + borderX - screenWidth;       // Correct OOB Right
                }
            }

            if (minObjY < screenY + borderY)                          // Check to see if there's an object OOB Top
            {
                screenY = minObjY - borderY;                          // Correct OOB Top
            }
            if (maxObjY > screenY + screenHeight - borderY)           // Check to see if there's an object OOB Bottom
            {                                                         // We need to move the screen down
                if (maxObjY - minObjY > screenHeight - (2 * borderY)) // Check to see if both objects can fit on the screen
                {                                                     // No, so we need to scale up the screen
                    screenHeight = maxObjY - screenY + borderY;       // Correct OOB Bottom

                    int delta = screenHeight - maxScreenHeight;
                    if (delta > 0)                     // If we're already stretched too thin, drop the top guy.
                    {
                        screenHeight = maxScreenHeight;
                        screenY     += delta;
                    }
                }
                else                                            // Yes, we can move the screen down
                {
                    screenY = maxObjY + borderY - screenHeight; // Correct OOB Bottom
                }
            }

            double widthRatio  = screenWidth / (double)ScreenData.Get().GetFullScreenWidth();
            double heightRatio = screenHeight / (double)ScreenData.Get().GetFullScreenHeight();

            screenRatio = (widthRatio > heightRatio ? widthRatio : heightRatio);             // Set to the greater ratio
        }