예제 #1
0
        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                    bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, false);

            // Gradually fade in or out depending on whether we are covered by the pause screen.
            if (coveredByOtherScreen)
            {
                pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1);
            }
            else
            {
                pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0);
            }

            if (!otherScreenHasFocus)
            {
                m_paused = false;
            }

            if (!m_paused)
            {
                /* Update Ball */
                if (m_ball.Ball_State == BallState.Active)
                {
                    m_ball.Update(m_player1.Texture_Data, m_player2.Texture_Data);
                }

                if (m_ball.Ball_State == BallState.DeadBall)
                {
                    balldie.Play();
                    if (m_ball.Ball_Dir == Direction.Right)
                    {
                        m_ball.Init_x = m_ball.X_Pos;
                        m_ball.Init_y = m_ball.Y_Pos;
                        m_ball.ResetBall(50.0f, -50.0f);
                        m_player_1_score += 1;
                    }
                    else if (m_ball.Ball_Dir == Direction.Left)
                    {
                        m_ball.Init_x = m_ball.X_Pos;
                        m_ball.Init_y = m_ball.Y_Pos;
                        m_ball.ResetBall(140.0f, 210.0f);
                        m_player_2_score += 1;
                    }
                    m_ball.X_Pos = 512;
                    m_ball.Y_Pos = (int)HelperUtils.GetRandomNumber(0.0, 608.0f);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
            {
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            }

            /*  LOAD TEXTURES, SOUNDS AND FONTS */
            ScreenTexture = new Texture2D(ScreenManager.GraphicsDevice, 1, 1);
            ScreenTexture.SetData(new Color[] { Color.White });
            paddle = content.Load <Texture2D>("Pong\\Textures\\pongpaddle");
            ball   = content.Load <Texture2D>("Pong\\Textures\\pongball");

            pause     = content.Load <SoundEffect>("DuckHunt\\Sounds\\pause");
            paddlehit = content.Load <SoundEffect>("Pong\\Sounds\\paddlehit");
            wallhit   = content.Load <SoundEffect>("Pong\\Sounds\\wallbounce");
            balldie   = content.Load <SoundEffect>("Pong\\Sounds\\deadball");

            m_score_fnt = content.Load <SpriteFont>("Fonts\\hugenesfont");

            /* Create Players */
            m_player1 = new Paddle(0, paddle, boxrec);
            m_player2 = new Paddle(1, paddle, boxrec);

            CollisionData[] temp = new CollisionData[4];

            temp[0] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X, HelperUtils.SafeBoundary.Y + -81, 1024, 80));
            temp[1] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X, HelperUtils.SafeBoundary.Y + 613, 1024, 80));
            temp[2] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X + -81, HelperUtils.SafeBoundary.Y, 80, 612));
            temp[3] = new CollisionData(new Rectangle(HelperUtils.SafeBoundary.X + 1024, HelperUtils.SafeBoundary.Y, 80, 612));

            /* Create Ball */
            m_ball = new PongBall(temp, paddlehit, wallhit);
            m_ball.AddAnimation(new Sprite(ball));
            m_ball.SetCurrentAnimation(0);
            m_ball.X_Pos = ScreenManager.GraphicsDevice.Viewport.Width / 2;
            m_ball.Y_Pos = (int)HelperUtils.GetRandomNumber(HelperUtils.SafeBoundary.Y, HelperUtils.SafeBoundary.Height - ball.Height);

            // A real game would probably have more content than this sample, so
            // it would take longer to load. We simulate that by delaying for a
            // while, giving you a chance to admire the beautiful loading screen.
            Thread.Sleep(1000);

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }
예제 #3
0
파일: Ball.cs 프로젝트: Dyn0mite/Pong
        /// <summary>
        /// Given a Velocity magnitude that we want to achieve, it generates two velocity components
        /// </summary>
        private float[] GenerateVelocities(float vel_magnitude, float min, float max)
        {
            float angle;

            float[] velocities = new float[2];

            angle = (float)HelperUtils.GetRandomNumber(min, max);

            // Generate X velocity
            velocities[0] = (float)(vel_magnitude * Math.Cos(angle * (Math.PI / 180)));

            // Generate Y velocity
            velocities[1] = (float)(vel_magnitude * Math.Sin(angle * (Math.PI / 180)));

            return(velocities);
        }
예제 #4
0
파일: PongBall.cs 프로젝트: Dyn0mite/Pong
        public PongBall(CollisionData[] boundary, SoundEffect paddlehit, SoundEffect wallhit)
        {
            m_hitwall       = wallhit;
            m_paddlehit     = paddlehit;
            m_scrn_boundary = boundary;
            m_animList      = new List <Drawable>();

            if (HelperUtils.GetRandomNumber(0.0, 10.0) < 5.01)
            {
                ResetBall(50.0f, -50.0f);
            }
            else
            {
                ResetBall(140.0f, 210.0f);
            }
        }
예제 #5
0
        public DuckHuntBall(int x, int y, CollisionData [] boundary)
        {
            m_init_x        = x;
            m_init_y        = y;
            m_scrn_boundary = boundary;
            m_animList      = new List <Drawable>();

            if (HelperUtils.GetRandomNumber(0.0, 10.0) < 5.01)
            {
                ResetBall(30.0f, 50.0f);
            }
            else
            {
                ResetBall(140.0f, 160.0f);
            }
        }
예제 #6
0
        public void Reset()
        {
            m_paused         = false;
            m_player_1_score = 0;
            m_player_2_score = 0;

            if (HelperUtils.GetRandomNumber(0.0, 10.0) < 5.01)
            {
                m_ball.ResetBall(50.0f, -50.0f);
            }
            else
            {
                m_ball.ResetBall(140.0f, 210.0f);
            }
            m_ball.X_Pos = ScreenManager.GraphicsDevice.Viewport.Width / 2;
            m_ball.Y_Pos = (int)HelperUtils.GetRandomNumber(HelperUtils.SafeBoundary.Y, HelperUtils.SafeBoundary.Height - ball.Height);

            m_player1.InitPaddle();
            m_player2.InitPaddle();
        }
예제 #7
0
파일: Clouds.cs 프로젝트: Dyn0mite/Pong
        public void Reset()
        {
            Sprite temp;
            int    tnum = 0;

            if (m_player == 0)
            {
                for (int i = 0; i < m_num / 2; i++, tnum++)
                {
                    temp                         = new Sprite();
                    temp.Texture                 = m_textures[tnum];
                    temp.X_Pos                   = (float)HelperUtils.GetRandomNumber(-412 - HelperUtils.SafeBoundary.X, HelperUtils.SafeBoundary.X + -m_textures[tnum].Width);
                    temp.Y_Pos                   = (float)HelperUtils.GetRandomNumber(HelperUtils.SafeBoundary.Y, HelperUtils.SafeBoundary.Y + 200);
                    m_clouds[i]                  = new Cloud();
                    m_clouds[i].m_used           = false;
                    m_clouds[i].m_cloud          = new LinearXYMover(temp, 2 * HelperUtils.SafeBoundary.X + 1024, (int)temp.Y_Pos, 1.0f);
                    m_clouds[i].m_collision_rect = new Rectangle((int)temp.X_Pos + m_textures[tnum].Width / 4, (int)temp.Y_Pos + m_textures[tnum].Height / 2, m_textures[tnum].Width / 2, 4);
                    m_clouds[i].m_coldata        = new CollisionData((int)temp.X_Pos, (int)temp.Y_Pos, m_textures[tnum],
                                                                     new Rectangle(0, 0, m_textures[tnum].Width, m_textures[tnum].Height), m_clouds[i].m_cloud.Origin,
                                                                     m_clouds[i].m_cloud.Scale, m_clouds[i].m_cloud.Rotation, m_clouds[i].m_cloud.Effects);
                }
                tnum = 0;

                for (int i = m_num / 2; i < m_num; i++, tnum++)
                {
                    temp                         = new Sprite();
                    temp.Texture                 = m_textures[tnum];
                    temp.X_Pos                   = (float)HelperUtils.GetRandomNumber(-412 - HelperUtils.SafeBoundary.X, HelperUtils.SafeBoundary.X + -m_textures[tnum].Width);
                    temp.Y_Pos                   = (float)HelperUtils.GetRandomNumber(HelperUtils.SafeBoundary.Y, HelperUtils.SafeBoundary.Y + 200);
                    m_clouds[i]                  = new Cloud();
                    m_clouds[i].m_used           = false;
                    m_clouds[i].m_cloud          = new LinearXYMover(temp, 2 * HelperUtils.SafeBoundary.X + 1024, (int)temp.Y_Pos, 1.0f);
                    m_clouds[i].m_collision_rect = new Rectangle((int)temp.X_Pos + m_textures[tnum].Width / 4, (int)temp.Y_Pos + m_textures[tnum].Height / 2, m_textures[tnum].Width / 2, 4);
                    m_clouds[i].m_coldata        = new CollisionData((int)temp.X_Pos, (int)temp.Y_Pos, m_textures[tnum],
                                                                     new Rectangle(0, 0, m_textures[tnum].Width, m_textures[tnum].Height), m_clouds[i].m_cloud.Origin,
                                                                     m_clouds[i].m_cloud.Scale, m_clouds[i].m_cloud.Rotation, m_clouds[i].m_cloud.Effects);
                }
            }
            else if (m_player == 1)
            {
                for (int i = 0; i < m_num / 2; i++, tnum++)
                {
                    temp                         = new Sprite();
                    temp.Texture                 = m_textures[tnum];
                    temp.X_Pos                   = (float)HelperUtils.GetRandomNumber(HelperUtils.SafeBoundary.X + 1024, HelperUtils.SafeBoundary.X + 1024 + 412);
                    temp.Y_Pos                   = (float)HelperUtils.GetRandomNumber(HelperUtils.SafeBoundary.Y, HelperUtils.SafeBoundary.Y + 200);
                    m_clouds[i]                  = new Cloud();
                    m_clouds[i].m_used           = false;
                    m_clouds[i].m_cloud          = new LinearXYMover(temp, -m_textures[tnum].Width - 2 * HelperUtils.SafeBoundary.X, (int)temp.Y_Pos, 1.0f);
                    m_clouds[i].m_collision_rect = new Rectangle((int)temp.X_Pos + m_textures[tnum].Width / 4, (int)temp.Y_Pos + m_textures[tnum].Height / 2, m_textures[tnum].Width / 2, 4);
                    m_clouds[i].m_coldata        = new CollisionData((int)temp.X_Pos, (int)temp.Y_Pos, m_textures[tnum],
                                                                     new Rectangle(0, 0, m_textures[tnum].Width, m_textures[tnum].Height), m_clouds[i].m_cloud.Origin,
                                                                     m_clouds[i].m_cloud.Scale, m_clouds[i].m_cloud.Rotation, m_clouds[i].m_cloud.Effects);
                }

                tnum = 0;

                for (int i = m_num / 2; i < m_num; i++, tnum++)
                {
                    temp                         = new Sprite();
                    temp.Texture                 = m_textures[tnum];
                    temp.X_Pos                   = (float)HelperUtils.GetRandomNumber(HelperUtils.SafeBoundary.X + 1024, HelperUtils.SafeBoundary.X + 1024 + 412);
                    temp.Y_Pos                   = (float)HelperUtils.GetRandomNumber(HelperUtils.SafeBoundary.Y, HelperUtils.SafeBoundary.Y + 200);
                    m_clouds[i]                  = new Cloud();
                    m_clouds[i].m_used           = false;
                    m_clouds[i].m_cloud          = new LinearXYMover(temp, -m_textures[tnum].Width - 2 * HelperUtils.SafeBoundary.X, (int)temp.Y_Pos, 1.0f);
                    m_clouds[i].m_collision_rect = new Rectangle((int)temp.X_Pos + m_textures[tnum].Width / 4, (int)temp.Y_Pos + m_textures[tnum].Height / 2, m_textures[tnum].Width / 2, 4);
                    m_clouds[i].m_coldata        = new CollisionData((int)temp.X_Pos, (int)temp.Y_Pos, m_textures[tnum],
                                                                     new Rectangle(0, 0, m_textures[tnum].Width, m_textures[tnum].Height), m_clouds[i].m_cloud.Origin,
                                                                     m_clouds[i].m_cloud.Scale, m_clouds[i].m_cloud.Rotation, m_clouds[i].m_cloud.Effects);
                }
            }

            m_state = DrawableState.Active;
        }
예제 #8
0
        // Release another ball on the screen only when there isnt already two in play
        public void ReleaseDuck()
        {
            if (m_duck_count > 0)
            {
                if (m_pongballs[0].Ball_State == BallState.DeadBall ||
                    m_pongballs[0].Ball_State == BallState.Limbo)
                {
                    if (HelperUtils.GetRandomNumber(0.0, 10.0) < 5.01)
                    {
                        m_pongballs[0].ResetBall(30.0f, 50.0f);
                    }
                    else
                    {
                        m_pongballs[0].ResetBall(140.0f, 160.0f);
                    }

                    if ((m_pongballs[0].X_Vel > 0 && m_pongballs[0].Y_Vel < 0) || (m_pongballs[0].X_Vel < 0 && m_pongballs[0].Y_Vel < 0))
                    {
                        m_pongballs[0].SetCurrentAnimation(1);
                    }
                    else
                    {
                        m_pongballs[0].SetCurrentAnimation(0);
                    }

                    SetCurrentDucktoBlink(0);
                    m_pongballs[0].Ball_State = BallState.Active;

                    if (m_pongballs[1].Ball_State == BallState.DeadBall && !Intermission())
                    {
                        m_pongballs[1].Ball_State = BallState.Limbo;
                    }
                }
                else if (m_pongballs[1].Ball_State == BallState.DeadBall ||
                         m_pongballs[1].Ball_State == BallState.Limbo)
                {
                    if (HelperUtils.GetRandomNumber(0.0, 10.0) < 5.01)
                    {
                        m_pongballs[1].ResetBall(30.0f, 50.0f);
                    }
                    else
                    {
                        m_pongballs[1].ResetBall(140.0f, 160.0f);
                    }
                    if ((m_pongballs[1].X_Vel > 0 && m_pongballs[1].Y_Vel < 0) || (m_pongballs[1].X_Vel < 0 && m_pongballs[1].Y_Vel < 0))
                    {
                        m_pongballs[1].SetCurrentAnimation(1);
                    }
                    else
                    {
                        m_pongballs[1].SetCurrentAnimation(0);
                    }

                    SetCurrentDucktoBlink(1);
                    m_pongballs[1].Ball_State = BallState.Active;

                    if (m_pongballs[0].Ball_State == BallState.DeadBall && !Intermission())
                    {
                        m_pongballs[0].Ball_State = BallState.Limbo;
                    }
                }
            }
        }