예제 #1
0
파일: PolarBear.cs 프로젝트: peges/hungry
        public override void Update(double time)
        {
            // Basic movement behavior:
            Player p = _RenderSet.Scene.Game.Player1;

            if (p != null)
            {
                if (JumpTimer.Elapsed.TotalSeconds >= JumpIntervalVaried)
                {
                    IsAttacking = true;
                    AttackTimer.Restart();
                    float randy = 1.0f + JumpVeloVariance * (float)R.NextDouble();
                    float dx    = (float)p.PositionWorldX - (float)PositionWorldX;
                    dx = 0.75f * dx / Math.Max(1.0f, dx);
                    var velocity = new Microsoft.Xna.Framework.Vector2(dx, 1.5f) * Body.Mass * randy;
                    Body.ApplyLinearImpulse(velocity);
                    JumpIntervalVaried = JumpInterval + R.NextDouble() * JumpIntervalVariance;
                    JumpTimer.Restart();
                    PlayAnimation(AnimationSwipe);
                }
                if (AttackTimer.Elapsed.TotalSeconds >= AttackInterval)
                {
                    IsAttacking = false;
                }
                if (AnimationCurrent == AnimationSwipe && FrameCurrent == _AnimationCurrent.Frames[_AnimationCurrent.Frames.Length - 1] && _FrameTimer.Elapsed.TotalMilliseconds > FrameCurrent.FrameTime)
                {
                    System.Diagnostics.Debug.Print("" + (p.PositionWorld - PositionWorld).Length);
                    if ((p.PositionWorld - PositionWorld).Length < 0.3f)                     // coordinate system a bit off?
                    {
                        p.OnInflictDamage(this, 1);
                    }

                    PlayAnimation(AnimationWalk);
                }

                // Only move towards the player if we're not attacking
                if (!IsAttacking)
                {
                    float targetx = (float)p.PositionWorldX - (float)PositionWorldX;
                    targetx             = 1.5f * targetx / Math.Max(1.0f, targetx);
                    Body.LinearVelocity = new Microsoft.Xna.Framework.Vector2(targetx, Body.LinearVelocity.Y);
                    _TileX = Math.Sign(targetx);
                }
            }
            base.Update(time);
        }
예제 #2
0
파일: Spidey.cs 프로젝트: peges/hungry
        bool HandleOnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
        {
            Player p                    = _RenderSet.Scene.Game.Player1;
            object world_object         = fixtureB.Body.UserData;
            bool   collided_with_player = p != null && fixtureB.Body == p.Body;
            bool   collided_with_bullet = world_object is BasicBullet;

            if (collided_with_player || collided_with_bullet)
            {
                if (fixtureB.Body.LinearVelocity.Length() > 2.0f)
                {
                    Derez();
                }
            }
            if (collided_with_player)
            {
                if (p.Body.LinearVelocity.Length() < 0.2f)
                {
                    p.OnInflictDamage(this, 1);
                }
            }
            return(true);
        }