示例#1
0
 protected virtual void OnKeysUpdate(double time)
 {
     lock (_Game.UpdateLock)
     {
         KeysUpdateEventArgs args = new KeysUpdateEventArgs(KeysPressed, time);
         if (KeysUpdate != null)
         {
             KeysUpdate(this, args);
         }
         IInputAccepter[] accepters = _Game.InputAccepterGroup;
         for (int i = 0; i < accepters.Length; i++)
         {
             accepters[i].KeysUpdate(this, args);                     // Trickle down arguments
         }
     }
 }
示例#2
0
		protected virtual void OnKeysUpdate (double time)
		{
			//TODO: Not sure if this respects UpdateLock (verify)
			lock(Program.MainUserInputLock)
			{
				KeysUpdateEventArgs args = new KeysUpdateEventArgs (KeysPressed, time);
                if (KeysUpdate != null)
                {
                    KeysUpdate(this, args);
                }
				lock(Program.MainGame.InputAccepterGroupsLock)
				{
					IInputAccepter[] accepters = Program.MainGame.InputAccepterGroup;
					for(int i = 0; i < accepters.Length; i++)
						accepters[i].KeysUpdate(this, args); // Trickle down arguments
				}
			}
		}
示例#3
0
 public KeysUpdateEventArgs KeysUpdate(object sender, KeysUpdateEventArgs e)
 {
     //e.KeysPressedWhen.Clear();
     return e;
 }
示例#4
0
 public KeysUpdateEventArgs KeysUpdate(object sender, KeysUpdateEventArgs e)
 {
     //e.KeysPressedWhen.Clear();
     return(e);
 }
示例#5
0
        public KeysUpdateEventArgs KeysUpdate(object sender, KeysUpdateEventArgs e)
        {
            float fx =
                (e.KeysPressedWhen.Contains (Configuration.KeyLeft) ? -1.0f : 0.0f) +
                (e.KeysPressedWhen.Contains (Configuration.KeyRight) ? 1.0f : 0.0f);
            if (_WieldingGun) {
                _AimAngle =  Math.PI * (
                    (e.KeysPressedWhen.Contains (Configuration.KeyDown) ? -0.25 : 0.0f) +
                    (e.KeysPressedWhen.Contains (Configuration.KeyUp) ? 0.25f : 0.0f));
                if (fx != 0.0f) {
                    _TileX = fx;
                    fx = 0.0f;
                }
            }
            fx *= 5f;
            //vy *= 10f;
            //this.Body.ApplyForce(new Microsoft.Xna.Framework.Vector2(vx * _SpriteBody.Mass, vy * _SpriteBody.Mass));
            var v = new Microsoft.Xna.Framework.Vector2 (fx * 0.5f, Body.LinearVelocity.Y);
            Body.LinearVelocity = Microsoft.Xna.Framework.Vector2.Lerp (Body.LinearVelocity, v, _MovementDamping * (float)e.Time);
            if (Body.LinearVelocity.LengthSquared () > 0.1f) {
                _DampVeloNormal = new Vector3d (Body.LinearVelocity.X, Body.LinearVelocity.Y, 0.0);
                _DampVeloNormal /= Math.Max (5.0, _DampVeloNormal.Length);
            }

            float v__x_mag = Math.Abs (v.X);
            if (!Jumping) {
               if (v__x_mag > VelocityMovementThreshold) {
                    _TileX = v.X > 0.0 ? 1.0 : -1.0;
                    PlayAnimation (AnimationMove);
                } else {
             					if (_WieldingGun) {
                        if(Crouching)
                            PlayAnimation (AnimationAimGunFwdCrouch);
                        else if (e.KeysPressedWhen.Contains (Configuration.KeyUp))
                            PlayAnimation (AnimationAimGunFwdUp);
                        else if (e.KeysPressedWhen.Contains (Configuration.KeyDown))
                            PlayAnimation (AnimationAimGunFwdDown);
                        else
                            PlayAnimation (AnimationAimGunFwd);
                    }
                    else
                        PlayAnimation (AnimationStationary);
                }
                //else
                //	PlayAnimation (AnimationStationary);
                _AnimationNext = null;
            }
            else if(_WieldingGun)
                PlayAnimation(AnimationAimGunFwdJump);

            //Console.WriteLine("On Platform == {0}", OnPlatform);

            // Time tolerance for input controls!
            //OrderedDictionary keytime = new OrderedDictionary();
            foreach(DictionaryEntry de in e.KeysPressedWhen)
            {
                Key k = (Key)de.Key;
                if(k == Configuration.KeyJump)
                {
                    if(Helper.KeyPressedInTime((DateTime)de.Value, DateTime.Now))
                    {
                        Jump ();
                    }
            //					else
            //					{
            //						keytime.Add(de.Key, de.Value);
            //					}
                }
            }
            //e.KeysPressedWhen = keytime;
            return e;
        }
示例#6
0
		protected virtual void OnKeysUpdate (double time)
		{
			lock(_Game.UpdateLock)
			{
				KeysUpdateEventArgs args = new KeysUpdateEventArgs (KeysPressed, time);
                if (KeysUpdate != null)
                {
                    KeysUpdate(this, args);
                }
				IInputAccepter[] accepters = _Game.InputAccepterGroup;
				for(int i = 0; i < accepters.Length; i++)
					accepters[i].KeysUpdate(this, args); // Trickle down arguments
			}
		}
示例#7
0
文件: Player.cs 项目: peges/hungry
        public KeysUpdateEventArgs KeysUpdate(object sender, KeysUpdateEventArgs e)
        {
            float fx =
                (e.KeysPressedWhen.Contains(Configuration.KeyLeft) ? -1.0f : 0.0f) +
                (e.KeysPressedWhen.Contains(Configuration.KeyRight) ? 1.0f : 0.0f);

            if (_WieldingGun)
            {
                _AimAngle = Math.PI * (
                    (e.KeysPressedWhen.Contains(Configuration.KeyDown) ? -0.25 : 0.0f) +
                    (e.KeysPressedWhen.Contains(Configuration.KeyUp) ? 0.25f : 0.0f));
                if (fx != 0.0f)
                {
                    _TileX = fx;
                    fx     = 0.0f;
                }
            }
            fx *= 5f;
            //vy *= 10f;
            //this.Body.ApplyForce(new Microsoft.Xna.Framework.Vector2(vx * _SpriteBody.Mass, vy * _SpriteBody.Mass));
            var v = new Microsoft.Xna.Framework.Vector2(fx * 0.5f, Body.LinearVelocity.Y);

            Body.LinearVelocity = Microsoft.Xna.Framework.Vector2.Lerp(Body.LinearVelocity, v, _MovementDamping * (float)e.Time);

            //Henry: this is my stuff.
            //float v_lin = Body.LinearVelocity.X + fx * 0.15f;

            /*if (v_lin >= 2.0f)
             *      v_lin = 2.0f;
             * if (v_lin <= -2.0f)
             *      v_lin = -2.0f;*/
            //Body.LinearVelocity = new Microsoft.Xna.Framework.Vector2( v_lin, Body.LinearVelocity.Y );

            if (Body.LinearVelocity.LengthSquared() > 0.1f)
            {
                _DampVeloNormal  = new Vector3d(Body.LinearVelocity.X, Body.LinearVelocity.Y, 0.0);
                _DampVeloNormal /= Math.Max(5.0, _DampVeloNormal.Length);
            }

            float v__x_mag = Math.Abs(v.X);

            if (!Jumping)
            {
                if (v__x_mag > VelocityMovementThreshold)
                {
                    _TileX = v.X > 0.0 ? 1.0 : -1.0;
                    PlayAnimation(AnimationMove);
                }
                else
                {
                    if (_WieldingGun)
                    {
                        //Henry: slingshot

                        /*if(Crouching)
                         *      PlayAnimation (AnimationAimGunFwdCrouch);
                         * else if (e.KeysPressedWhen.Contains (Configuration.KeyUp))
                         *      PlayAnimation (AnimationAimGunFwdUp);
                         * else if (e.KeysPressedWhen.Contains (Configuration.KeyDown))
                         *      PlayAnimation (AnimationAimGunFwdDown);
                         * else
                         *      PlayAnimation (AnimationAimGunFwd);*/
                    }
                    else
                    {
                        PlayAnimation(AnimationStationary);
                    }
                }
                //else
                //	PlayAnimation (AnimationStationary);
                _AnimationNext = null;
            }
            //Henry: slingshot
            //else if(_WieldingGun)
            //    PlayAnimation(AnimationAimGunFwdJump);

            //Console.WriteLine("On Platform == {0}", OnPlatform);

            // Time tolerance for input controls!
            //OrderedDictionary keytime = new OrderedDictionary();
            float push_up = 0.0f;

            foreach (DictionaryEntry de in e.KeysPressedWhen)
            {
                Key k = (Key)de.Key;
                if (k == Configuration.KeyJump)
                {
                    if (Helper.KeyPressedInTime((DateTime)de.Value, DateTime.Now))
                    {
                        Jump();
                    }
                    if (Jumping)
                    {
                        push_up  = 1.0f - (float)JumpTimer.Elapsed.TotalSeconds;
                        push_up  = push_up > 0.0f ? push_up : 0.0f;
                        push_up *= push_up;
                    }
//					else
//					{
//						keytime.Add(de.Key, de.Value);
//					}
                }
            }
            Body.ApplyForce(new Microsoft.Xna.Framework.Vector2(0.0f, _SuperJumpAmount * push_up));

            //e.KeysPressedWhen = keytime;
            return(e);
        }