public HitType LookForHits(Dictionary <Bone, BoneData> segments, int playerId)
        {
            DateTime cur     = DateTime.Now;
            HitType  allHits = HitType.None;

            // Zero out score if necessary
            if (!this.scores.ContainsKey(playerId))
            {
                this.scores.Add(playerId, 0);
            }

            foreach (var pair in segments)
            {
                for (int i = 0; i < this.things.Count; i++)
                {
                    HitType hit   = HitType.None;
                    Thing   thing = this.things[i];
                    switch (thing.State)
                    {
                    case ThingState.Bouncing:
                    case ThingState.Falling:
                    {
                        var     hitCenter       = new System.Windows.Point(0, 0);
                        double  lineHitLocation = 0;
                        Segment seg             = pair.Value.GetEstimatedSegment(cur);
                        if (thing.Hit(seg, ref hitCenter, ref lineHitLocation))
                        {
                            double fMs = 1000;
                            if (thing.TimeLastHit != DateTime.MinValue)
                            {
                                fMs = cur.Subtract(thing.TimeLastHit).TotalMilliseconds;
                                thing.AvgTimeBetweenHits = (thing.AvgTimeBetweenHits * 0.8) + (0.2 * fMs);
                            }

                            thing.TimeLastHit = cur;

                            // Bounce off head and hands
                            if (seg.IsCircle())
                            {
                                // Bounce off of hand/head/foot
                                thing.BounceOff(
                                    hitCenter.X,
                                    hitCenter.Y,
                                    seg.Radius,
                                    pair.Value.XVelocity / this.targetFrameRate,
                                    pair.Value.YVelocity / this.targetFrameRate);

                                if (fMs > 100.0)
                                {
                                    hit |= HitType.Hand;
                                }
                            }
                            else
                            {
                                // Bounce off line segment
                                double velocityX = (pair.Value.XVelocity * (1.0 - lineHitLocation)) + (pair.Value.XVelocity2 * lineHitLocation);
                                double velocityY = (pair.Value.YVelocity * (1.0 - lineHitLocation)) + (pair.Value.YVelocity2 * lineHitLocation);

                                thing.BounceOff(
                                    hitCenter.X,
                                    hitCenter.Y,
                                    seg.Radius,
                                    velocityX / this.targetFrameRate,
                                    velocityY / this.targetFrameRate);

                                if (fMs > 100.0)
                                {
                                    hit |= HitType.Arm;
                                }
                            }

                            if (this.gameMode == GameMode.TwoPlayer)
                            {
                                if (thing.State == ThingState.Falling)
                                {
                                    //thing.State = ThingState.Bouncing;
                                    thing.State      = ThingState.Dissolving;
                                    thing.TouchedBy  = playerId;
                                    thing.Hotness    = 1;
                                    thing.FlashCount = 0;
                                }
                                else if (thing.State == ThingState.Bouncing)
                                {
                                    if (thing.TouchedBy != playerId)
                                    {
                                        if (seg.IsCircle())
                                        {
                                            thing.TouchedBy = playerId;
                                            thing.Hotness   = Math.Min(thing.Hotness + 1, 4);
                                        }
                                        else
                                        {
                                            hit |= HitType.Popped;
                                            this.AddToScore(thing.TouchedBy, 5 << (thing.Hotness - 1), thing.Center);
                                        }
                                    }
                                }
                            }
                            else if (this.gameMode == GameMode.Solo)
                            {
                                if (seg.IsCircle())
                                {
                                    if (thing.State == ThingState.Falling)
                                    {
                                        //thing.State = ThingState.Bouncing;
                                        thing.State      = ThingState.Dissolving;
                                        thing.TouchedBy  = playerId;
                                        thing.Hotness    = 1;
                                        thing.FlashCount = 0;
                                    }
                                    else if ((thing.State == ThingState.Bouncing) && (fMs > 100.0))
                                    {
                                        hit |= HitType.Popped;
                                        int points = (pair.Key.Joint1 == JointType.FootLeft ||
                                                      pair.Key.Joint1 == JointType.FootRight)
                                                                 ? 10
                                                                 : 5;
                                        this.AddToScore(
                                            thing.TouchedBy,
                                            points,
                                            thing.Center);
                                        thing.TouchedBy = playerId;
                                    }
                                }
                            }

                            this.things[i] = thing;

                            if (thing.AvgTimeBetweenHits < 8)
                            {
                                hit |= HitType.Popped | HitType.Squeezed;
                                if (this.gameMode != GameMode.Off)
                                {
                                    this.AddToScore(playerId, 1, thing.Center);
                                }
                            }
                        }
                    }

                    break;
                    }

                    if ((hit & HitType.Popped) != 0)
                    {
                        thing.State     = ThingState.Dissolving;
                        thing.Dissolve  = 0;
                        thing.XVelocity = thing.YVelocity = 0;
                        thing.SpinRate  = (thing.SpinRate * 6) + 0.2;
                        this.things[i]  = thing;
                    }

                    allHits |= hit;
                }
            }

            return(allHits);
        }
Ejemplo n.º 2
0
        public HitType LookForHits(Dictionary <Bone, BoneData> segments, int playerId)
        {
            DateTime cur     = DateTime.Now;
            HitType  allHits = HitType.None;

            // Zero out score if necessary
            if (!scores.ContainsKey(playerId))
            {
                scores.Add(playerId, 0);
            }

            foreach (var pair in segments)
            {
                for (int i = 0; i < things.Count; i++)
                {
                    HitType hit   = HitType.None;
                    Thing   thing = things[i];
                    switch (thing.state)
                    {
                    case ThingState.Bouncing:
                    case ThingState.Falling:
                    {
                        var     ptHitCenter     = new Point(0, 0);
                        double  lineHitLocation = 0;
                        Segment seg             = pair.Value.GetEstimatedSegment(cur);
                        if (thing.Hit(seg, ref ptHitCenter, ref lineHitLocation))
                        {
                            double fMs = 1000;
                            if (thing.timeLastHit != DateTime.MinValue)
                            {
                                fMs = cur.Subtract(thing.timeLastHit).TotalMilliseconds;
                                thing.avgTimeBetweenHits = thing.avgTimeBetweenHits * 0.8 + 0.2 * fMs;
                            }
                            thing.timeLastHit = cur;

                            // Bounce off head and hands
                            if (seg.IsCircle())
                            {
                                // Bounce off of hand/head/foot
                                thing.BounceOff(ptHitCenter.X, ptHitCenter.Y, seg.radius,
                                                pair.Value.xVel / targetFrameRate, pair.Value.yVel / targetFrameRate);

                                if (fMs > 100.0)
                                {
                                    hit |= HitType.Hand;
                                }
                            }
                            else          // Bonce off line segment
                            {
                                double xVel = pair.Value.xVel * (1.0 - lineHitLocation) + pair.Value.xVel2 * lineHitLocation;
                                double yVel = pair.Value.yVel * (1.0 - lineHitLocation) + pair.Value.yVel2 * lineHitLocation;

                                thing.BounceOff(ptHitCenter.X, ptHitCenter.Y, seg.radius,
                                                xVel / targetFrameRate, yVel / targetFrameRate);

                                if (fMs > 100.0)
                                {
                                    hit |= HitType.Arm;
                                }
                            }

                            if (gameMode == GameMode.TwoPlayer)
                            {
                                if (thing.state == ThingState.Falling)
                                {
                                    thing.state      = ThingState.Bouncing;
                                    thing.touchedBy  = playerId;
                                    thing.hotness    = 1;
                                    thing.flashCount = 0;
                                }
                                else if (thing.state == ThingState.Bouncing)
                                {
                                    if (thing.touchedBy != playerId)
                                    {
                                        if (seg.IsCircle())
                                        {
                                            thing.touchedBy = playerId;
                                            thing.hotness   = Math.Min(thing.hotness + 1, 4);
                                        }
                                        else
                                        {
                                            hit |= HitType.Popped;
                                            AddToScore(thing.touchedBy, 5 << (thing.hotness - 1), thing.center);
                                        }
                                    }
                                }
                            }
                            else if (gameMode == GameMode.Solo)
                            {
                                if (seg.IsCircle())
                                {
                                    if (thing.state == ThingState.Falling)
                                    {
                                        thing.state      = ThingState.Bouncing;
                                        thing.touchedBy  = playerId;
                                        thing.hotness    = 1;
                                        thing.flashCount = 0;
                                    }
                                    else if ((thing.state == ThingState.Bouncing) && (fMs > 100.0))
                                    {
                                        hit |= HitType.Popped;
                                        AddToScore(thing.touchedBy,
                                                   (pair.Key.joint1 == JointID.FootLeft || pair.Key.joint1 == JointID.FootRight) ? 10 : 5,
                                                   thing.center);
                                        thing.touchedBy = playerId;
                                    }
                                }
                            }

                            things[i] = thing;

                            if (thing.avgTimeBetweenHits < 8)
                            {
                                hit |= HitType.Popped | HitType.Squeezed;
                                if (gameMode != GameMode.Off)
                                {
                                    AddToScore(playerId, 1, thing.center);
                                }
                            }
                        }
                    }
                    break;
                    }

                    if ((hit & HitType.Popped) != 0)
                    {
                        thing.state     = ThingState.Dissolving;
                        thing.dissolve  = 0;
                        thing.xVelocity = thing.yVelocity = 0;
                        thing.spinRate  = thing.spinRate * 6 + 0.2;
                        things[i]       = thing;
                    }
                    allHits |= hit;
                }
            }
            return(allHits);
        }