Exemplo n.º 1
0
        public void Update(GameTime gameTime)
        {
            // Move the Screen with Velocity
            if (xVel < -15)
            {
                xVel = -15;
            }
            if (xVel > 15)
            {
                xVel = 15;
            }
            camX += (int)xVel;
            xVel /= 1.13;
            if (Math.Abs(xVel) < 0.9)
            {
                xVel = 0.0;
            }

            // Move the Screen with the mouse
            if (Game.input.MouseY() > 0 && Game.input.MouseY() < Game.GAME_HEIGHT)
            {
                if (/*Game.input.MouseX() > -50 && */ Game.input.MouseX() < BLOCK_WIDTH * 2)
                {
                    camX -= ((BLOCK_WIDTH * 2 - Game.input.MouseX()) / 10) <= 15 ? (BLOCK_WIDTH * 2 - Game.input.MouseX()) / 10 : 15;
                }

                if (/*Game.input.MouseX() < Game.GAME_WIDTH + 50 && */ Game.input.MouseX() > Game.GAME_WIDTH - BLOCK_WIDTH * 2)
                {
                    camX += ((Game.input.MouseX() - (Game.GAME_WIDTH - BLOCK_WIDTH * 2)) / 10) <= 15 ? ((Game.input.MouseX() - (Game.GAME_WIDTH - BLOCK_WIDTH * 2)) / 10) : 15;
                }
            }

            // Cap the camera position
            if (camX < 0)
            {
                camX = 0;
            }
            if (camX > width * BLOCK_WIDTH - Game.WINDOW_WIDTH)
            {
                camX = width * BLOCK_WIDTH - Game.WINDOW_WIDTH;
            }

            // Calculare Selected box
            int selectedX = (camX + Game.input.MouseX()) / BLOCK_WIDTH;
            int selectedY = Game.input.MouseY() / BLOCK_HEIGHT;

            selectedBox = new Point(selectedX, selectedY);

            // Update all the Derps
            derpManager.Update(gameTime);

            //Temp Derping Code
            if (Game.input.MouseLeftKeyClicked())
            {
                derpManager.SpawnDerp(selectedX, selectedY, 1);
            }
            else if (Game.input.MouseRightKeyClicked())
            {
                derpManager.SpawnDerp(selectedX, selectedY, 2);
            }
        }
Exemplo n.º 2
0
        public void Update(GameTime gameTime)
        {
            // Scroll back and forth
            if (Game.input.KeyDown(Keys.A) || Game.input.KeyDown(Keys.Left))
            {
                SlideView(-2);
            }
            if (Game.input.KeyDown(Keys.D) || Game.input.KeyDown(Keys.Right))
            {
                SlideView(2);
            }

            // Move the Screen with Velocity
            if (xVel < -15)
            {
                xVel = -15;
            }
            if (xVel > 15)
            {
                xVel = 15;
            }
            camX += (int)xVel;
            xVel /= 1.13;
            if (Math.Abs(xVel) < 0.9)
            {
                xVel = 0.0;
            }

            // Move the Screen with the mouse
            if (Game.input.MouseY() > 0 && Game.input.MouseY() < Game.GAME_HEIGHT)
            {
                // Move the screen to the Right. Cap the movement speed with the ternary operation
                if (Game.input.MouseX() < BLOCK_WIDTH * 2)
                {
                    camX -= ((BLOCK_WIDTH * 2 - Game.input.MouseX()) / 10) <= 15 ? (BLOCK_WIDTH * 2 - Game.input.MouseX()) / 10 : 15;
                }

                // Move the screen to the Left. Cap the movement speed with the ternary operation
                if (Game.input.MouseX() > Game.GAME_WIDTH - BLOCK_WIDTH * 2)
                {
                    camX += ((Game.input.MouseX() - (Game.GAME_WIDTH - BLOCK_WIDTH * 2)) / 10) <= 15 ? ((Game.input.MouseX() - (Game.GAME_WIDTH - BLOCK_WIDTH * 2)) / 10) : 15;
                }
            }

            // Cap the camera position
            if (camX < 0)
            {
                camX = 0;
            }
            if (camX > width * BLOCK_WIDTH - Game.WINDOW_WIDTH)
            {
                camX = width * BLOCK_WIDTH - Game.WINDOW_WIDTH;
            }

            // Calculare Selected box
            int selectedX = (camX + Game.input.MouseX()) / BLOCK_WIDTH;
            int selectedY = Game.input.MouseY() / BLOCK_HEIGHT;

            selectedBox = new Point(selectedX, selectedY);

            // Update all Spawners
            for (int y = 0; y < height; ++y)
            {
                if (leftSpawners[y] != null)
                {
                    leftSpawners[y].Update(gameTime);
                    rightSpawners[y].Update(gameTime);
                }
            }

            // Handle the "Mouse State"
            // This will change when we are trying to build DNA, delete DNA, etc
            // This is also where we will build DNA onto the field

            // Stop Construction if we Right-Click (a universal cancel)
            if (Game.input.constructionState != 0 && Game.input.MouseRightKeyClicked())
            {
                Game.input.constructionState = 0;
            }

            // Check for Construction if we Left-Click
            if (Game.input.constructionState != 0 && Game.input.MouseLeftKeyClicked())
            {
                // Find the X,Y coordinate in the grid that the mouse is in
                int sx = selectedBox.X - (camX / BLOCK_WIDTH);
                int sy = selectedBox.Y - (camY / BLOCK_HEIGHT);

                // Make sure we are within the game boundry, otherwise do nothing
                if (sx >= 0 && sx <= Game.GAME_WIDTH / BLOCK_WIDTH && sy >= 0 && sy <= Game.GAME_HEIGHT / BLOCK_HEIGHT && Game.input.mouseClear)
                {
                    // Check if any Spawner accepts this position as a valid DNA location
                    // If so, add the DNA to their strand and continue. Luckily there should never be overlap, so we don't have to worry about doing double.
                    int mx = Game.input.MouseX();
                    int my = Game.input.MouseY();
                    for (int i = 0; i < leftSpawners.Length; ++i)
                    {
                        if (leftSpawners[i] != null && leftSpawners[i].CheckMouseOver(camX + mx, my) != -1)
                        {
                            leftSpawners[i].AddDNA(leftSpawners[i].CheckMouseOver(camX + mx, my), Game.input.constructionState - 1);
                        }

                        // DEBUG: Only do this on the right side for debugging purposes
                        if (rightSpawners[i] != null && rightSpawners[i].CheckMouseOver(camX + mx, my) != -1)
                        {
                            rightSpawners[i].AddDNA(rightSpawners[i].CheckMouseOver(camX + mx, my), Game.input.constructionState - 1);
                        }
                    }

                    // Reset Construction State
                    Game.input.constructionState = 0;
                }
            }

            // DEBUG CODE:
            // - create a derp for now if you click on a hub
            if (Game.input.MouseLeftKeyClicked() && selectedX >= 0 && selectedX < width && selectedY >= 0 && selectedY < height && gameGrid[selectedY, selectedX] == 'A')
            {
                int hp   = 5 + MyRandom.Next(TEAM.HOME, 10);
                int spd  = 25 + MyRandom.Next(TEAM.HOME, 50);
                int atk  = 3 + MyRandom.Next(TEAM.HOME, 4);
                int aspd = 25 + MyRandom.Next(TEAM.HOME, 50);
                int rng  = 2 + MyRandom.Next(TEAM.HOME, 30);

                DerpStats stats = new DerpStats(hp, spd, atk, aspd, rng, 16, 16);
                TEAM      derpTeam;

                if (selectedX == 0)
                {
                    derpTeam = TEAM.HOME;
                }
                else
                {
                    derpTeam = TEAM.AWAY;
                }

                derpManager.SpawnDerp(selectedX * BLOCK_WIDTH + (BLOCK_WIDTH / 2), selectedY * BLOCK_HEIGHT + (BLOCK_HEIGHT / 2), derpTeam, stats);
            }

            // Update all the Derps
            derpManager.Update(gameTime);
        }