Exemple #1
0
 public bool Scored(SoccerBall ball)
 {
     if (Collision2D.LineIntersection(ball.Position, ball.OldPosition, LeftPost, RightPost))
     {
         NumGoalsScored++;
         return(true);
     }
     return(false);
 }
Exemple #2
0
        public SoccerPitch(int cx, int cy)
        {
            ClientX     = cx;
            ClientY     = cy;
            PlayingArea = new Region(20, 20, cx - 20f, cy - 20f);

            regions = new Region[NumRegionsHorizontal * NumRegionsVertical];
            CreateRegions(PlayingArea.Width / (float)NumRegionsHorizontal, PlayingArea.Height / (float)NumRegionsVertical);

            redGoal = new Goal(new Vector2(PlayingArea.Left, (cy - Configuration.GoalWidth) / 2f),
                               new Vector2(PlayingArea.Left, cy - (cy - Configuration.GoalWidth) / 2f),
                               new Vector2(1, 0));

            blueGoal = new Goal(new Vector2(PlayingArea.Right, (cy - Configuration.GoalWidth) / 2f),
                                new Vector2(PlayingArea.Right, cy - (cy - Configuration.GoalWidth) / 2f),
                                new Vector2(-1, 0));

            ball = new SoccerBall(new Vector2(ClientX / 2.0f, ClientY / 2.0f), Configuration.BallSize, Configuration.BallMass, Walls);

            redTeam  = new SoccerTeam(redGoal, blueGoal, this, SoccerTeam.SoccerColor.Red);
            blueTeam = new SoccerTeam(blueGoal, redGoal, this, SoccerTeam.SoccerColor.Blue);

            redTeam.Opponents  = blueTeam;
            blueTeam.Opponents = redTeam;

            // walls
            var topLeft     = new Vector2(PlayingArea.Left, PlayingArea.Top);
            var topRight    = new Vector2(PlayingArea.Right, PlayingArea.Top);
            var bottomRight = new Vector2(PlayingArea.Right, PlayingArea.Bottom);
            var bottomLeft  = new Vector2(PlayingArea.Left, PlayingArea.Bottom);

            Walls = new List <Wall2D>();
            Walls.Add(new Wall2D(bottomLeft, redGoal.RightPost));
            Walls.Add(new Wall2D(redGoal.LeftPost, topLeft));
            Walls.Add(new Wall2D(topLeft, topRight));
            Walls.Add(new Wall2D(topRight, blueGoal.LeftPost));
            Walls.Add(new Wall2D(blueGoal.RightPost, bottomRight));
            Walls.Add(new Wall2D(bottomRight, bottomLeft));
        }