Пример #1
0
        public void SetCoordinates(Beam beam, GameScreen.GameState gameState)
        {
            angle     = Utilities.CalculateAngle(beam);
            tempAngle = angle;
            // Halla la cordenada donde dibujar la punta del triangulo basandose en el angulo del beam
            if (gameState == GameScreen.GameState.player1Turn)
            {
                Coordinates[2, 1] = (short)((length * Math.Sin(angle)) + (beam.Coordinates[0, 1]));
                direction         = -1;
            }
            else
            {
                Coordinates[2, 1] = (short)((length * Math.Sin(angle)) + (beam.Coordinates[0, 1]));
                angle             = angle * -1;
                direction         = 1;
            }

            Coordinates[0, 0] = beam.Coordinates[0, 0];
            Coordinates[0, 1] = beam.Coordinates[0, 1];
            Coordinates[1, 0] = beam.Coordinates[1, 0];
            Coordinates[1, 1] = beam.Coordinates[1, 1];


            if (angle >= 0)
            {
                Coordinates[2, 0] = (short)(beam.Coordinates[1, 0] + (length * Math.Cos(angle)) + (beam.Coordinates[1, 0] - beam.Coordinates[0, 0]) - Speed + 1);
            }
            else
            {
                Coordinates[2, 0] = (short)(beam.Coordinates[0, 0] + (length * Math.Cos(angle)) + (beam.Coordinates[1, 0] - beam.Coordinates[0, 0]) - Speed + 1);
            }
        }
Пример #2
0
        private void drawPopUps(GameScreen.GameState gameState, float levelOverTimer)
        {
            // Ready
            if (gameState == GameScreen.GameState.Ready)
            {
                drawTextureAtCenter(textures.ReadyText);
            }

            // Paused
            else if (gameState == GameScreen.GameState.Paused)
            {
                drawTextureAtCenter(textures.PauseMenu[Input.PauseSelection]);
            }

            // Level over
            else if (gameState == GameScreen.GameState.LevelOver)
            {
                // Winner
                if (world.Enemies.Count == 0)
                {
                    if (levelOverTimer % (PopupFlashLength * 2) < PopupFlashLength)
                    {
                        drawTextureAtCenter(textures.WinnerTextWhite);
                    }
                    else
                    {
                        drawTextureAtCenter(textures.WinnerTextRed);
                    }
                }

                // Loser
                else if (world.Player.Health <= 0)
                {
                    if (levelOverTimer % (PopupFlashLength * 2) < PopupFlashLength)
                    {
                        drawTextureAtCenter(textures.LoserTextWhite);
                    }
                    else
                    {
                        drawTextureAtCenter(textures.LoserTextRed);
                    }
                }
            }
        }
Пример #3
0
        public void Render(GameScreen.GameState gameState, float levelOverTimer)
        {
            graphicsDevice.Clear(Color.Black);

            // Draw to render target
            graphicsDevice.SetRenderTarget(renderTarget);
            spriteBatch.Begin(samplerState: SamplerState.PointClamp); // Do not linearly interpolate when stretching textures

            // Background
            spriteBatch.Draw(textures.Environments[world.Environment], new Rectangle(0, 0, World.Width, World.Height), Color.White);

            // GameChars
            foreach (GameChar gameChar in world.AllGameChars)
            {
                drawGameChar(gameChar);
            }

            // Balls
            foreach (Ball ball in world.Balls)
            {
                drawBall(ball);
            }

            // UI
            foreach (GameChar gameChar in world.AllGameChars)
            {
                drawHealthBar(gameChar);
                drawInventory(gameChar);
                drawLungeBar(gameChar);
            }

            drawPopUps(gameState, levelOverTimer);
            drawCursor();

            spriteBatch.End();

            // Draw render target to window
            graphicsDevice.SetRenderTarget(null);
            spriteBatch.Begin(samplerState: SamplerState.PointClamp);
            spriteBatch.Draw(renderTarget, new Rectangle(0, 0, WindowWidth, WindowHeight), Color.White);
            spriteBatch.End();
        }
Пример #4
0
        public static void Update(GameScreen.GameState gameState)
        {
            lastKeyboardState = keyboardState;
            lastMouseState    = mouseState;

            keyboardState = Keyboard.GetState();
            mouseState    = Mouse.GetState();

            // Look for pause
            if (keyboardState.IsKeyDown(Keys.Escape) && !lastKeyboardState.IsKeyDown(Keys.Escape))
            {
                PauseSelection = NumPauseOptions; // Last option is back
                Pause          = !Pause;
            }

            if (gameState == GameScreen.GameState.Playing)
            {
                // Throw
                if (mouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton != ButtonState.Pressed)
                {
                    Throw = true;
                    // Scale window coordinates to world coordinates
                    ThrowHere = new Vector2(
                        (float)mouseState.X / Renderer.WindowWidth * World.Width,
                        (float)mouseState.Y / Renderer.WindowHeight * World.Height);
                }
                // Lunge
                else if (mouseState.RightButton == ButtonState.Pressed && lastMouseState.RightButton != ButtonState.Pressed)
                {
                    Lunge = true;
                    // Scale window coordinates to world coordinates
                    LungeHere = new Vector2(
                        (float)mouseState.X / Renderer.WindowWidth * World.Width,
                        (float)mouseState.Y / Renderer.WindowHeight * World.Height);
                }
            }

            // Pause menu
            else if (gameState == GameScreen.GameState.Paused)
            {
                // Mouse
                if (mouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton != ButtonState.Pressed)
                {
                    // Restart
                    if (UI.RestartOption.Contains(MouseVirtualPos))
                    {
                        // Confirm
                        if (PauseSelection == 1)
                        {
                            Restart = true;
                        }
                        else
                        {
                            PauseSelection = 1;
                        }
                    }

                    // Main menu
                    else if (UI.MainMenuOption.Contains(MouseVirtualPos))
                    {
                        // Confirm
                        if (PauseSelection == 2)
                        {
                            MainMenu = true;
                        }
                        else
                        {
                            PauseSelection = 2;
                        }
                    }

                    // Back
                    else if (UI.BackOption.Contains(MouseVirtualPos))
                    {
                        // Confirm
                        if (PauseSelection == 3)
                        {
                            Pause = !Pause;
                        }
                        else
                        {
                            PauseSelection = 3;
                        }
                    }
                }

                // Keyboard
                // Move selection up
                if ((keyboardState.IsKeyDown(Keys.Up) && !lastKeyboardState.IsKeyDown(Keys.Up)) ||
                    (keyboardState.IsKeyDown(Keys.W) && !lastKeyboardState.IsKeyDown(Keys.W)))
                {
                    if (PauseSelection > 1)
                    {
                        PauseSelection--;
                    }
                }
                // Move selection down
                if ((keyboardState.IsKeyDown(Keys.Down) && !lastKeyboardState.IsKeyDown(Keys.Down)) ||
                    (keyboardState.IsKeyDown(Keys.S) && !lastKeyboardState.IsKeyDown(Keys.S)))
                {
                    if (PauseSelection < NumPauseOptions)
                    {
                        PauseSelection++;
                    }
                }
                // Look for with enter key
                if ((keyboardState.IsKeyDown(Keys.Enter) && !lastKeyboardState.IsKeyDown(Keys.Enter)) ||
                    (keyboardState.IsKeyDown(Keys.Space) && !lastKeyboardState.IsKeyDown(Keys.Space)))
                {
                    switch (PauseSelection)
                    {
                    case 1:     // Restart
                        Restart = true;
                        break;

                    case 2:     // Main menu
                        MainMenu = true;
                        break;

                    case 3:     // Back
                        Pause = !Pause;
                        break;
                    }
                }
            }
        }