Esempio n. 1
0
        protected void UpdateBat()
        {
            Vector2 rightStick = mCurrControllerState.ThumbSticks.Right;

            if (!mCurrControllerState.IsConnected)
            {
                if (mCurrKeyboardState.IsKeyDown(mAttackEast))
                {
                    rightStick.X += +1f;
                }

                if (mCurrKeyboardState.IsKeyDown(mAttackWest))
                {
                    rightStick.X += -1f;
                }

                if (mCurrKeyboardState.IsKeyDown(mAttackNorth))
                {
                    rightStick.Y += +1f;
                }

                if (mCurrKeyboardState.IsKeyDown(mAttackSouth))
                {
                    rightStick.Y += -1f;
                }

                if (rightStick.Length() > 0.1f)
                {
                    rightStick.Normalize();
                }
            }

            if (rightStick.Length() > .25)
            {
                if (bats.Count <= 4)
                {
                    Vector2 offset2d = mFixture.Body.Position + rightStick * 1f;
                    //Vector3 offset3d = new Vector2(offset2d.X, offset2d.Y, 0);
                    SwordSlash newSwordSlash = new SwordSlash(mPhysicsWorld, offset2d);
                    newSwordSlash.setRotation(rightStick);
                    newSwordSlash.SetPosition(offset2d); // it's lame, but this set after-the-fact may be necessary
                    newSwordSlash.SetVelocity(mFixture.Body.LinearVelocity);
                    bats.Add(newSwordSlash);
                    GetGameWorld().AddGameObject(newSwordSlash);
                }
                else
                {
                    SwordSlash apply = bats.ElementAt(0);
                    apply.setAngularVelocity(bats.ElementAt(2), bats.ElementAt(1));
                    bats.RemoveAt(0);

                    /* bats.ForEach(delegate(SwordSlash curr)
                     {
                         if (curr.isTimedOut())
                         {
                             bats.Remove(curr);
                         }

                     });*/
                    //bats.RemoveAt(0);
                }
            }
        }
 public void setAngularVelocity(SwordSlash old, SwordSlash current)
 {
     float difference = current.batRotation - old.batRotation;
     difference /= 5000f;
     mFixture.Body.AngularVelocity = difference;
 }