Exemplo n.º 1
0
        public override void Draw(GameTime gameTime)
        {
            if (Texture == null)
            {
                return;
            }

            Globals.SpriteBatch.Draw(Texture, Posicao, null, Color.White, -Direcao.Angle(), new Vector2(Texture.Width / 2, Texture.Height / 2), 1f, SpriteEffects.None, 0);
        }
Exemplo n.º 2
0
        public override void Draw(GameTime gameTime)
        {
            if (!(Game as Main).Started)
            {
                return;
            }

            Globals.SpriteBatch.Draw(Texture, Posicao, Animation.Source, Arma.Cor, -Direcao.Angle(), Animation.Center, 1f, SpriteEffects.None, 0);

            // foreach (var item in Bounds)
            //     Globals.SpriteBatch.DrawPoint(item, 2f, Color.Red);
        }
Exemplo n.º 3
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();
        }