Ejemplo n.º 1
0
        bool presentBody_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            int bodyIdToRemove = -1;
            Body bodyToRemove = null;

            if (fixtureB.Body.BodyId == ground.BodyId)
            {
                // it has hit the floor
                bodyIdToRemove = fixtureA.Body.BodyId;
                bodyToRemove = fixtureA.Body;
            }

                foreach (Player player in players.Values)
                {
                    // in 2players co it will add for both players
                    if (fixtureB.Body.BodyId == player.basketId)
                    {
                        bodyIdToRemove = fixtureA.Body.BodyId;
                        bodyToRemove = fixtureA.Body;
                        player.addPoints(1);
                        if (player.getPoints() == targetScore)
                        {
                            gameStopwatch.Stop();
                            if (isHighscore(gameStopwatch.ElapsedMilliseconds))
                            {
                                ExitScreen();
                                HighScoreScreen highScoreScreen = new HighScoreScreen();
                                ScreenManager.AddScreen(highScoreScreen);
                                EnterHighScoreScreen enterHighScoreScreen = new EnterHighScoreScreen(gameStopwatch.ElapsedMilliseconds, maximumTopScorers);
                                ScreenManager.AddScreen(enterHighScoreScreen);

                            }
                            else
                            {
                                ExitScreen();
                                HighScoreScreen highScoreScreen = new HighScoreScreen();
                                ScreenManager.AddScreen(highScoreScreen);

                            }
                        }
                    }
                }

            if (bodyIdToRemove != -1)
            {
                int explosionTime = presentsStopwatch.Elapsed.Milliseconds;

                do
                {
                    if (!explosionTimesLocationsMapping.ContainsKey(explosionTime))
                    {
                        explosionTimesLocationsMapping.Add(explosionTime, new Vector2(bodyToRemove.Position.X - presentSpriteBodyMapping[bodyIdToRemove].Texture.Width / 2, bodyToRemove.Position.Y - presentSpriteBodyMapping[bodyIdToRemove].Texture.Height / 2));
                    }
                    else
                    {
                        explosionTime++;
                    }
                }
                while (explosionTimesLocationsMapping.ContainsKey(explosionTime));

                int removed_index = presentBodies.RemoveAll(body => body.BodyId == bodyIdToRemove) - 1; // remove by condition

                if (removed_index != -1)
                {
                    presentSpriteBodyMapping.Remove(removed_index);
                    bodyToRemove.Dispose();
                    return false;
                }
                return true;

            }
            else
            {
                return true;
            }
        }
Ejemplo n.º 2
0
 void keyboard_ActivationChanged(object sender, EventArgs e)
 {
     String activatedLetter = ((KeyboardLetter)sender).Letter;
     if (activatedLetter.Equals("OK"))
     {
         kinectPongDAL.InsertHighScore(currentName, scoreToEnter, maximumTopScores);
         HighScoreScreen highScoreScreen = new HighScoreScreen();
         ScreenManager.AddScreen(highScoreScreen);
     }
     else if (activatedLetter.Equals("<-"))
     {
         if (currentName.Length > 0)
         {
             currentName = currentName.Remove(currentName.Length - 1);
         }
     }
     else
     {
         currentName += ((KeyboardLetter)sender).Letter;
     }
     ((KeyboardLetter)sender).IsHovered = false;
 }