Exemple #1
0
 public Puck(Game game)
     : base(game)
 {
     // TODO: Construct any child components here
     table = new Table(game);
     Initialize();
 }
        public static bool CheckPuckWallCollision(Rectangle rectangle, Puck puck, Table table)
        {
            int intDistanceLeftX = Math.Abs(rectangle.Left - (int)puck.CenterX);
            int intDistanceRightX = Math.Abs(rectangle.Right - (int)puck.CenterX);
            int intDistanceTopY = Math.Abs(rectangle.Top - (int)puck.CenterY);
            int intDistanceBottomY = Math.Abs(rectangle.Bottom - (int)puck.CenterY);

            int intDistanceTopGoalLeftX = Math.Abs(table.TopGoal.Left - (int)puck.CenterX);
            int intDistanceTopGoalRightX = Math.Abs(table.TopGoal.Right - (int)puck.CenterX);
            int intDistanceTopGoalBottomY = Math.Abs(table.TopGoal.Bottom - (int)puck.CenterY);

            int intDistanceBottomGoalLeftX = Math.Abs(table.BottomGoal.Left - (int)puck.CenterX);
            int intDistanceBottomGoalRightX = Math.Abs(table.BottomGoal.Right - (int)puck.CenterX);
            int intDistanceBottomGoalTopY = Math.Abs(table.BottomGoal.Top - (int)puck.CenterY);
            if (intDistanceLeftX <= puck.Radius)
            {
                PuckHitsWallCollision(puck, "Side");
                return true;
            }
            if (intDistanceRightX <= puck.Radius)
            {
                PuckHitsWallCollision(puck, "Side");
                return true;
            }
            if (intDistanceTopY <= puck.Radius)
            {

                if (table.TopGoal.Contains((int)puck.CenterX, (int)puck.Y) && intDistanceTopGoalBottomY <= puck.Radius)
                {

                        puck.CenterX = 0;
                        puck.CenterY = 0;
                        table.GoalA = true;
                        return true;

                }

                PuckHitsWallCollision(puck, "");
                return true;
            }
            if (intDistanceBottomY <= puck.Radius)
            {
                if (table.BottomGoal.Contains((int)puck.CenterX, ((int)puck.CenterY + puck.Radius)) && intDistanceBottomGoalTopY <= puck.Radius)
                {

                        puck.CenterX = 0;
                        puck.CenterY = 0;
                        table.GoalB = true;
                        return true;
                }
                PuckHitsWallCollision(puck, "");
                return true;
            }
            return false;
        }
Exemple #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            game = this;
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            mainMenuScreen = new MainMenuScreen(game);
            cursor = new Cursor(game);
            table = new Table(game);
            puck = new Puck(game);
            paddle = new Paddle(game);
        }