예제 #1
0
파일: Cue.cs 프로젝트: rumkugel13/EightBall
        public override void OnUpdate(float elapsedSeconds)
        {
            base.OnUpdate(elapsedSeconds);

            if (!this.poweringUp)
            {
                if (Kadro.Input.KeyboardInput.IsKeyDown(Keys.Left))
                {
                    this.Transform.Rotation -= this.resolutionsPerSecond * elapsedSeconds;
                    this.Transform.Position  = VectorExtensions.Rotate(this.Transform.Position, -this.resolutionsPerSecond * elapsedSeconds, focusPosition - offset);
                }

                if (Kadro.Input.KeyboardInput.IsKeyDown(Keys.Right))
                {
                    this.Transform.Rotation += this.resolutionsPerSecond * elapsedSeconds;
                    this.Transform.Position  = VectorExtensions.Rotate(this.Transform.Position, this.resolutionsPerSecond * elapsedSeconds, focusPosition - offset);
                }

                if (MouseInput.OnMouseMoved())
                {
                    float targetAngle = (GameScene.ActiveScene.ViewToWorld(MouseInput.PositionVector) - focusPosition + offset).PerpRight().ToPolar();
                    //targetAngle = MathExtensions.LerpAngle(this.Transform.Rotation, targetAngle, 1.0f * elapsedSeconds);
                    this.Transform.Rotation = targetAngle;
                    this.Transform.Position = VectorExtensions.Rotate(focusPosition, targetAngle, focusPosition - offset);
                }

                if (Kadro.Input.KeyboardInput.OnKeyDown(Keys.Space))
                {
                    this.poweringUp = true;

                    // add constant velocity to move back
                    RigidBody r = this.Components.Get <RigidBodyComponent>().RigidBody;
                    r.AddVelocityChange(VectorExtensions.AngleToVector2(this.Transform.Rotation).PerpLeft() * this.poweringUpVelocity * elapsedSeconds);
                }
            }

            if (this.poweringUp && Kadro.Input.KeyboardInput.IsKeyDown(Keys.Space))
            {
                this.timeSinceStart += elapsedSeconds;
            }

            if ((this.poweringUp && Kadro.Input.KeyboardInput.OnKeyUp(Keys.Space)) || this.timeSinceStart > this.releaseTime)
            {
                // release
                this.timeSinceStart = 0f;
                this.releasing      = true;
                RigidBody r = this.Components.Get <RigidBodyComponent>().RigidBody;
                r.Velocity        = Vector2.Zero;
                r.AngularVelocity = 0;
            }

            if (this.releasing)
            {
                // accelerate cue until it hits the ball
                RigidBody r = this.Components.Get <RigidBodyComponent>().RigidBody;
                r.AddForce(-VectorExtensions.AngleToVector2(this.Transform.Rotation).PerpLeft() * this.releaseForce * elapsedSeconds);
            }
        }