コード例 #1
0
        public void actualizar(GameTime gameTime)
        {
            try
            {
                if (activo)
                {
                    posicion.Y += velocidad;

                    if ((int)eDesplazamiento.izquierda == (int)this.desplazamiento)
                    {
                        posicion.X -= velocidad;
                    }
                    else if ((int)eDesplazamiento.derecha == (int)this.desplazamiento)
                    {
                        posicion.X += velocidad;
                    }
                }

                if (posicion.Y > viewport.Height || vida == 0)
                {
                    activo = false;
                }
                animacion.Position = posicion;
                animacion.Update(gameTime);
            }
            catch (Exception) { }
        }
コード例 #2
0
        public void actualizar(KeyboardState teclado, KeyboardState estadoAnterior, GameTime gameTime)
        {
            try
            {
                if (teclado.IsKeyDown(Keys.Up))
                {
                    posicion.Y -= 5.0f;
                }

                if (teclado.IsKeyDown(Keys.Down))
                {
                    posicion.Y += 5.0f;
                }

                if (teclado.IsKeyDown(Keys.Right))
                {
                    posicion.X += 5.0f;
                }

                if (teclado.IsKeyDown(Keys.Left))
                {
                    posicion.X -= 5.0f;
                }

                if (teclado.IsKeyDown(Keys.Space) && estadoAnterior.IsKeyUp(Keys.Space))
                {
                    if (proyectiles.Count < numeroProyectiles)
                    {
                        disparo.Play();
                        agregarProyectil();
                    }
                }

                animacion.Position = posicion;
                animacion.Update(gameTime);

                posicion.X = MathHelper.Clamp(posicion.X, 0 + animacion.FrameWidth / 2, viewport.Width - animacion.FrameWidth / 2);
                posicion.Y = MathHelper.Clamp(posicion.Y, viewport.Height / 4, viewport.Height - animacion.FrameHeight / 2);
            }
            catch (Exception) { }
        }