Esempio n. 1
0
        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;
        }
Esempio n. 2
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;
                    }
                }
            }
        }
Esempio n. 3
0
        public override void Update(CollisionData player1, CollisionData player2)
        {
            if (Ball_State != BallState.DeadBall)
            {
                /* Update Position */
                X_Pos += (int)X_Vel;
                Y_Pos += (int)Y_Vel;

                /* Update current Animation */
                //m_currAnim.Update();

                m_currAnim.X_Pos = X_Pos;
                m_currAnim.Y_Pos = Y_Pos;
                m_currAnim.Scale = Ball_Scale;

                m_currAnimBData = new CollisionData((int)m_currAnim.X_Pos,
                                                    (int)m_currAnim.Y_Pos,
                                                    m_currAnim.Texture,
                                                    m_currAnim.Sprite_Src_Rect,
                                                    m_currAnim.Origin,
                                                    m_currAnim.Scale,
                                                    m_currAnim.Rotation,
                                                    SpriteEffects.None);

                PongBall_Rect       = m_currAnimBData.m_rect;
                m_pongBallTransform = m_currAnimBData.m_transformation;

                /* Detect Collisions */
                if (Ball_State == BallState.Active)
                {
                    // Top of boundary
                    if (m_hit != Direction.Top && PongBall_Rect.Intersects(m_scrn_boundary[0].m_rect))
                    {
                        // Check collision with person

                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[0].m_transformation, m_scrn_boundary[0].m_rect.Width,
                                                        m_scrn_boundary[0].m_rect.Height, m_scrn_boundary[0].m_color_data))
                        {
                            Y_Vel = -Y_Vel;
                            m_hit = Direction.Top;
                            m_hitwall.Play();
                        }
                    }

                    // Bottom of boundary
                    else if (m_hit != Direction.Bottom && PongBall_Rect.Intersects(m_scrn_boundary[1].m_rect)) // Cant hit bottom twice in row
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[1].m_transformation, m_scrn_boundary[1].m_rect.Width,
                                                        m_scrn_boundary[1].m_rect.Height, m_scrn_boundary[1].m_color_data))
                        {
                            Y_Vel = -Y_Vel;
                            m_hit = Direction.Bottom;
                            m_hitwall.Play();
                        }
                    }

                    // Paddle (Player 1)
                    else if (m_hit != Direction.Right && PongBall_Rect.Intersects(player1.m_rect)) // Cant hit p1 paddle twice in a row
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        player1.m_transformation, player1.m_rect.Width,
                                                        player1.m_rect.Height, player1.m_color_data))
                        {
                            X_Vel    = -X_Vel;
                            Ball_Dir = Direction.Right;
                            m_hit    = Direction.Right;
                            m_paddlehit.Play();
                        }
                    }


                    // Paddle (Player 2)
                    else if (m_hit != Direction.Left && PongBall_Rect.Intersects(player2.m_rect)) // Cant hit p2 paddle twice in a row
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        player2.m_transformation, player2.m_rect.Width,
                                                        player2.m_rect.Height, player2.m_color_data))
                        {
                            X_Vel    = -X_Vel;
                            Ball_Dir = Direction.Left;
                            m_hit    = Direction.Left;
                            m_paddlehit.Play();
                        }
                    }

                    // Left of boundary
                    else if (PongBall_Rect.Intersects(m_scrn_boundary[2].m_rect))
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[2].m_transformation, m_scrn_boundary[2].m_rect.Width,
                                                        m_scrn_boundary[2].m_rect.Height, m_scrn_boundary[2].m_color_data))
                        {
                            Ball_State = BallState.DeadBall;
                        }
                    }

                    // Right of boundary
                    else if (PongBall_Rect.Intersects(m_scrn_boundary[3].m_rect))
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[3].m_transformation, m_scrn_boundary[3].m_rect.Width,
                                                        m_scrn_boundary[3].m_rect.Height, m_scrn_boundary[3].m_color_data))
                        {
                            Ball_State = BallState.DeadBall;
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public override void Update(CollisionData p1paddle, CollisionData p2paddle)
        {
            if (Ball_State != BallState.DeadBall && Ball_State != BallState.Limbo)
            {
                /* Update Position */
                X_Pos += (int)X_Vel;
                Y_Pos += (int)Y_Vel;

                /* Update current Animation */
                m_currAnim.Update();

                m_currAnim.X_Pos = X_Pos;
                m_currAnim.Y_Pos = Y_Pos;
                m_currAnim.Scale = Ball_Scale;

                m_currAnimBData = new CollisionData((int)m_currAnim.X_Pos,
                                                    (int)m_currAnim.Y_Pos,
                                                    m_currAnim.Texture,
                                                    m_currAnim.Sprite_Src_Rect,
                                                    m_currAnim.Origin,
                                                    m_currAnim.Scale,
                                                    m_currAnim.Rotation,
                                                    SpriteEffects.None);

                PongBall_Rect       = m_currAnimBData.m_rect;
                m_pongBallTransform = m_currAnimBData.m_transformation;

                /* Detect Collisions */
                if (Ball_State == BallState.Active) // No need to detect for collision if we are outofbounds
                {
                    // Top of boundary
                    if (m_hit != Direction.Top && PongBall_Rect.Intersects(m_scrn_boundary[0].m_rect))
                    {
                        // Check collision with person

                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[0].m_transformation, m_scrn_boundary[0].m_rect.Width,
                                                        m_scrn_boundary[0].m_rect.Height, m_scrn_boundary[0].m_color_data))
                        {
                            Y_Vel = -Y_Vel;
                            m_hit = Direction.Top;
                        }
                    }

                    // Bottom of boundary
                    else if (m_hit != Direction.Bottom && PongBall_Rect.Intersects(m_scrn_boundary[1].m_rect)) // Cant hit bottom twice in row
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[1].m_transformation, m_scrn_boundary[1].m_rect.Width,
                                                        m_scrn_boundary[1].m_rect.Height, m_scrn_boundary[1].m_color_data))
                        {
                            Y_Vel = -Y_Vel;
                            m_hit = Direction.Bottom;
                        }
                    }

                    // Paddle (DuckHuntPlayer 1)
                    else if (m_hit != Direction.Right && PongBall_Rect.Intersects(p1paddle.m_rect)) // Cant hit p1 paddle twice in a row
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        p1paddle.m_transformation, p1paddle.m_rect.Width,
                                                        p1paddle.m_rect.Height, p1paddle.m_color_data))
                        {
                            X_Vel    = -X_Vel;
                            Ball_Dir = Direction.Right;
                            m_hit    = Direction.Right;
                        }
                    }


                    // Paddle (DuckHuntPlayer 2)
                    else if (m_hit != Direction.Left && PongBall_Rect.Intersects(p2paddle.m_rect)) // Cant hit p2 paddle twice in a row
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        p2paddle.m_transformation, p2paddle.m_rect.Width,
                                                        p2paddle.m_rect.Height, p2paddle.m_color_data))
                        {
                            X_Vel    = -X_Vel;
                            Ball_Dir = Direction.Left;
                            m_hit    = Direction.Left;
                        }
                    }

                    /* Out of bounds */

                    // Got past DuckHuntPlayer 1
                    else if (m_hit != Direction.Right && PongBall_Rect.Intersects(m_scrn_boundary[2].m_rect))
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[2].m_transformation, m_scrn_boundary[2].m_rect.Width,
                                                        m_scrn_boundary[2].m_rect.Height, m_scrn_boundary[2].m_color_data))
                        {
                            m_currAnim.Effects = SpriteEffects.None;
                            Ball_State         = BallState.OutofBounds;
                        }
                    }

                    // Got past DuckHuntPlayer 2
                    else if (m_hit != Direction.Left && PongBall_Rect.Intersects(m_scrn_boundary[3].m_rect))
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[3].m_transformation, m_scrn_boundary[3].m_rect.Width,
                                                        m_scrn_boundary[3].m_rect.Height, m_scrn_boundary[3].m_color_data))
                        {
                            m_currAnim.Effects = SpriteEffects.FlipHorizontally;
                            Ball_State         = BallState.OutofBounds;
                        }
                    }

                    /*
                     * for (int i = 0; i < clouds.Length; i++)
                     * {
                     *  if (clouds[i].m_used != true && PongBall_Rect.Intersects(clouds[i].m_collision_rect))
                     *  {
                     *      Y_Vel = -Y_Vel;
                     *      //clouds[i].m_duck_used = true;
                     *      m_hit = Direction.None;
                     *  }
                     * }
                     */
                    if ((X_Vel > 0 && Y_Vel < 0) || (X_Vel < 0 && Y_Vel < 0))
                    {
                        m_currAnim = m_animList[1];
                    }
                    else
                    {
                        m_currAnim = m_animList[0];
                    }

                    if (Ball_Dir == Direction.Right)
                    {
                        m_currAnim.Effects = SpriteEffects.None;
                    }
                    else
                    {
                        m_currAnim.Effects = SpriteEffects.FlipHorizontally;
                    }
                }
                else if (Ball_State == BallState.OutofBounds)
                {
                    if (PongBall_Rect.Intersects(m_scrn_boundary[4].m_rect))
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[4].m_transformation, m_scrn_boundary[4].m_rect.Width,
                                                        m_scrn_boundary[4].m_rect.Height, m_scrn_boundary[4].m_color_data))
                        {
                            Ball_State = BallState.DeadBall;
                        }
                    }
                    else if (PongBall_Rect.Intersects(m_scrn_boundary[5].m_rect))
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[5].m_transformation, m_scrn_boundary[5].m_rect.Width,
                                                        m_scrn_boundary[5].m_rect.Height, m_scrn_boundary[5].m_color_data))
                        {
                            Ball_State = BallState.DeadBall;
                        }
                    }
                    else if (PongBall_Rect.Intersects(m_scrn_boundary[6].m_rect))
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[6].m_transformation, m_scrn_boundary[6].m_rect.Width,
                                                        m_scrn_boundary[6].m_rect.Height, m_scrn_boundary[6].m_color_data))
                        {
                            Ball_State = BallState.DeadBall;
                        }
                    }
                    else if (PongBall_Rect.Intersects(m_scrn_boundary[7].m_rect))
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[7].m_transformation, m_scrn_boundary[7].m_rect.Width,
                                                        m_scrn_boundary[7].m_rect.Height, m_scrn_boundary[7].m_color_data))
                        {
                            Ball_State = BallState.DeadBall;
                        }
                    }
                    else if (PongBall_Rect.Intersects(m_scrn_boundary[8].m_rect))
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[8].m_transformation, m_scrn_boundary[8].m_rect.Width,
                                                        m_scrn_boundary[8].m_rect.Height, m_scrn_boundary[8].m_color_data))
                        {
                            Y_Vel = -Y_Vel;
                            m_hit = Direction.Bottom;
                        }
                    }
                    else if (PongBall_Rect.Intersects(m_scrn_boundary[9].m_rect))
                    {
                        if (HelperUtils.IntersectPixels(m_pongBallTransform, PongBall_Rect.Width,
                                                        PongBall_Rect.Height, m_currAnimBData.m_color_data,
                                                        m_scrn_boundary[9].m_transformation, m_scrn_boundary[9].m_rect.Width,
                                                        m_scrn_boundary[9].m_rect.Height, m_scrn_boundary[9].m_color_data))
                        {
                            Y_Vel = -Y_Vel;
                            m_hit = Direction.Bottom;
                        }
                    }
                }

                m_currAnim.X_Pos = X_Pos;
                m_currAnim.Y_Pos = Y_Pos;
                m_currAnim.Scale = Ball_Scale;
            }
        }