Beispiel #1
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here
            //Conseguir la posicion y el zoom
            posicionmover = camara.GetPosition();
            zoom          = camara.GetZoom();

            //Manejo de botones
            if (ventanainfo == true)
            {
                if (botoninfo.EnterButton() && MouseController.getInstance().leftClick())
                {
                    ventanainfo = false;
                }
            }
            else
            {
                if (botoninfo.EnterButton() && MouseController.getInstance().leftClick())
                {
                    ventanainfo = true;
                }
                else if (botonclear.EnterButton() && MouseController.getInstance().leftClick())
                {
                    for (int i = 0; i < array.GetLength(0); i++)
                    {
                        for (int j = 0; j < array.GetLength(1); j++)
                        {
                            if (array.Valor(i, j) == 1)
                            {
                                array.CambioEstado(i, j);
                            }
                        }
                    }
                }
                else if (botonplay.EnterButton() && MouseController.getInstance().leftClick())
                {
                    ejecuta = !ejecuta;
                }
                else if (zoomup.EnterButton() && MouseController.getInstance().leftClick())
                {
                    camara.AdjustZoom(1f);
                }
                else if (zoomdown.EnterButton() && MouseController.getInstance().leftClick())
                {
                    camara.AdjustZoom(-1f);
                }
                else if (botonvel1.EnterButton() && MouseController.getInstance().leftClick())
                {
                    velocidad = 30;
                    contador  = 0;
                }
                else if (botonvel2.EnterButton() && MouseController.getInstance().leftClick())
                {
                    velocidad = 2;
                    contador  = 0;
                }
                else if (botonvel3.EnterButton() && MouseController.getInstance().leftClick())
                {
                    velocidad = 1;
                    contador  = 0;
                }
                //Cambio de estado de celulas con click izquierdo
                else if (MouseController.getInstance().leftClick() && (ejecuta == false))
                {
                    position = MouseController.getInstance().getLocation().ToVector2();
                    y        = ((((int)position.Y + (((int)posicionmover.Y - 430)) * zoom) - (30 * zoom) + (430 * (zoom - 1))) / (8 * zoom));
                    x        = ((((int)position.X + (((int)posicionmover.X - 430)) * zoom) - (30 * zoom) + (430 * (zoom - 1))) / (8 * zoom));

                    if (x >= 0 && x < 100 && y < 100 && y >= 0)
                    {
                        array.CambioEstado((int)Math.Floor(x), (int)Math.Floor(y));
                    }
                }
            }

            //Toggle de la ejecucion del juego
            if (MouseController.getInstance().rightClick())
            {
                ejecuta = !ejecuta;
            }

            //Update de la camara
            camara.UpdateCamera(GraphicsDevice.Viewport);

            //Ejecucion del juego
            if (ejecuta == true)
            {
                contador += 1;
                if (contador == velocidad)
                {
                    array.Ciclo();
                    contador = 0;
                }
            }

            activo = array.Activo();

            MouseController.getInstance().update();
            KeyboardController.getInstance().update();

            base.Update(gameTime);
        }