Пример #1
0
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            lock (this.MyBody)
            {
                if (e.KeyData == Keys.Up)
                {
                    this.MyBody.Velocity = new LM.Senac.BouncingBall.Physics.Vector2d(this.MyBody.Velocity.X, this.MyBody.Velocity.Y - 30);
                }
                if (e.KeyData == Keys.Down)
                {
                    this.MyBody.Velocity = new LM.Senac.BouncingBall.Physics.Vector2d(this.MyBody.Velocity.X, this.MyBody.Velocity.Y + 30);
                }
                if (e.KeyData == Keys.Left)
                {
                    this.MyBody.Velocity = new LM.Senac.BouncingBall.Physics.Vector2d(this.MyBody.Velocity.X - 5, this.MyBody.Velocity.Y);
                }
                if (e.KeyData == Keys.Right)
                {
                    this.MyBody.Velocity = new LM.Senac.BouncingBall.Physics.Vector2d(this.MyBody.Velocity.X + 5, this.MyBody.Velocity.Y);
                }
            }

            lock (this.MainGame.MyPlanet.Bodies)
            {
                if (e.KeyData == Keys.L)
                {
                    Body bd = new Body();
                    bd.UseGravity = true;
                    bd.Color      = Brushes.Black;
                    bd.Position   = new LM.Senac.BouncingBall.Physics.Vector2d(400, 400);
                    bd.Velocity   = AuxMath.AngleDegreesToVector(85, -135);
                    bd.Size       = new Size2d(12, 12);
                    this._mainGame.MyPlanet.AddBody(bd);
                }
                if (e.KeyData == Keys.K)
                {
                    Body bd = new Body();
                    bd.UseGravity = true;
                    bd.Color      = Brushes.Black;
                    bd.Position   = new LM.Senac.BouncingBall.Physics.Vector2d(30, 400);
                    bd.Velocity   = AuxMath.AngleDegreesToVector(85, -45);
                    bd.Size       = new Size2d(12, 12);
                    this._mainGame.MyPlanet.AddBody(bd);
                }
                if (e.KeyData == Keys.J)
                {
                    Body bd = new Body();
                    bd.UseGravity = true;
                    bd.Color      = Brushes.Black;
                    bd.Position   = new LM.Senac.BouncingBall.Physics.Vector2d(70, 400);
                    bd.Velocity   = AuxMath.AngleDegreesToVector(85, -90);
                    bd.Size       = new Size2d(12, 12);
                    this._mainGame.MyPlanet.AddBody(bd);
                }
            }

            if (e.KeyData == Keys.Add)
            {
                this.MainGame.MyPlanet.Gravity += 5d;
            }

            if (e.KeyData == Keys.Subtract)
            {
                this.MainGame.MyPlanet.Gravity -= 5d;
            }

            if (e.KeyData == Keys.C)
            {
                this.Clear();
            }

            if (e.KeyData == Keys.R)
            {
                this.InitializeBodies();
            }

            if (e.KeyData == Keys.P)
            {
                this._mainGame.Paused();
            }
        }