예제 #1
0
 public void Atirar()//Atira com a arma
 {
     _playerArmaEquipada.Atira(_mouseRef);
 }
예제 #2
0
        public override void Update(GameTime gameTime)
        {
            if (!(Game as Main).Started)
            {
                return;
            }

            var dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

            var keys = Keyboard.GetState().GetPressedKeys();

            if (Arma.Municao <= 0)
            {
                Arma = new CanhaoSimples();
            }

            if (keys.Contains(Keys.Up))
            {
                Animation.Start();
                Inercia -= Direcao * dt * Aceleracao;
            }
            else if (keys.Contains(Keys.Down))
            {
                Inercia += Direcao * dt * Aceleracao / 5;
            }
            else
            {
                Animation.Stop().SelectIndex(6);
            }

            Animation.Update(gameTime);

            if (keys.Contains(Keys.Right))
            {
                Direcao = Direcao.Rotate(0.1f);
            }
            else if (keys.Contains(Keys.Left))
            {
                Direcao = Direcao.Rotate(-0.1f);
            }

            if (Posicao.X > Game.Window.ClientBounds.Width)
            {
                Posicao = new Vector2(0, Posicao.Y);
            }
            if (Posicao.X < 0)
            {
                Posicao = new Vector2(Game.Window.ClientBounds.Width, Posicao.Y);
            }

            if (Posicao.Y > Game.Window.ClientBounds.Height)
            {
                Posicao = new Vector2(Posicao.X, 0);
            }
            if (Posicao.Y < 0)
            {
                Posicao = new Vector2(Posicao.X, Game.Window.ClientBounds.Height);
            }

            var angle = -Direcao.Angle();

            Bounds.Clear();

            Bounds.Add(Posicao);
            Bounds.Add(new Vector2(Posicao.X, Posicao.Y - Animation.Source.Height / 2).Rotate(angle, Posicao));
            Bounds.Add(new Vector2(Posicao.X - Animation.Source.Width / 2 + 5, Posicao.Y - Animation.Source.Height / 2 + 5).Rotate(angle, Posicao));
            Bounds.Add(new Vector2(Posicao.X + Animation.Source.Width / 2 - 5, Posicao.Y - Animation.Source.Height / 2 + 5).Rotate(angle, Posicao));


            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                Arma.Atira(Game, gameTime, new [] { Bounds[2], Bounds[3] }, -Direcao);
            }

            if (Keyboard.GetState().IsKeyUp(Keys.Space))
            {
                Arma.Reset();
            }

            Posicao += Inercia;

            var meteoros = Game.Components.OfType <Meteoro>();

            // if (meteoros.Any(p => p.Contem(Bounds)))
            //     (Game as Main).End();
        }