Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

moneal2001

Member Since 02 Dec 2011
Offline Last Active May 06 2013 08:37 PM
-----

Posts I've Made

In Topic: XNA Code Help - Animation Error

24 April 2013 - 11:53 PM

I think it has to do with the override of spriteBatch.Draw that you are using.  yours only seems to take into account where you are drawing the texture

 

you need to use the override that includes the source rectangle(the frame on your spritesheet) as well as the destination rectangle(where the texture is being drawn).


In Topic: Pong Collision Question [XNA]

15 April 2013 - 04:59 PM

actually yes it does work fine that way and better than the way i posted.  the ball still bounces left or right if hitting at the corner of the paddle where it was going behind the paddle if it hit the corner.  Thanks I was really over thinking the problem.


In Topic: Pong Collision Question [XNA]

15 April 2013 - 02:40 PM

thanks stitches i decided to change how i did the if statements just using all possible combinations instead of combining all the intersection checks like i had it.  I do understand the overhead of using new.   and i will add the paddle and small rectangles to the constructor and just assign them when they are needed.  Thanks again.

 

here is my new collision code that works in case anyone might need it:  

 

private void checkPaddleCollision(List<Paddle> paddles)
        {
            CollisionType type = CollisionType.Left;
            bool collide = false;
            
                       

            foreach (Paddle p in paddles)
            {
                

                if(rect.Intersects(p.Bounds))
                {

                    paddle = p;

                    collide = true;
                    int height = rect.Height / 2;
                    int width = rect.Width / 2;

                    topLeft.X = rect.X;
                    topLeft.Y = rect.Y;
                    topLeft.Width = width;
                    topLeft.Height = height;
                    
                    topRight.X = rect.X + width;
                    topRight.Y = rect.Y;
                    topRight.Width = width;
                    topRight.Height = height;

                    bottomLeft.X = rect.X;
                    bottomLeft.Y = rect.Y + height;
                    bottomLeft.Width = width;
                    bottomLeft.Height = height;

                    bottomRight.X = rect.X + width;
                    bottomRight.Y = rect.Y + height;
                    bottomRight.Width = width;
                    bottomRight.Height = height;
                    

                    if(p.Bounds.Intersects(topLeft) && p.Bounds.Intersects(bottomLeft))
                    {
                        type = CollisionType.Left;
                    }
                    else if (p.Bounds.Intersects(topRight) && p.Bounds.Intersects(bottomRight))
                    {
                        type = CollisionType.Right;
                    }
                    else if (p.Bounds.Intersects(topRight) && p.Bounds.Intersects(topLeft))
                    {
                        type = CollisionType.Top;
                    }
                    else if (p.Bounds.Intersects(bottomRight) && p.Bounds.Intersects(bottomLeft))
                    {
                        type = CollisionType.Bottom;
                    }
                    else if (p.Bounds.Intersects(topLeft))
                    {
                        type = CollisionType.Top;
                    }
                    else if (p.Bounds.Intersects(topRight))
                    {
                        type = CollisionType.Top;
                    }
                    else if (p.Bounds.Intersects(bottomLeft))
                    {
                        type = CollisionType.Bottom;
                    }
                    else if (p.Bounds.Intersects(bottomRight))
                    {
                        type = CollisionType.Bottom;
                    }                                    
                }
            }

            if (collide)
            {
                switch (type)
                {
                    case CollisionType.Left:
                        position.X = paddle.Position.X + paddle.Bounds.Width;
                        break;
                    case CollisionType.Right:
                        position.X = paddle.Position.X - texture.Width;
                        break;
                    case CollisionType.Bottom:
                        position.Y = paddle.Position.Y - texture.Height;
                        break;
                    case CollisionType.Top:
                        position.Y = paddle.Position.Y + paddle.Bounds.Height;
                        break;
                }

                if (type == CollisionType.Left || type == CollisionType.Right)
                {
                    direction.X *= -1;
                    direction.Normalize();
                }
                else
                {
                    direction.Y *= -1;
                    direction.Normalize();
                }
            }
        }

In Topic: Pong Collision Question [XNA]

15 April 2013 - 11:25 AM

any one able help with this or should i just rewrite the collision checks


In Topic: Should I post my First Game Project on PSN

15 April 2013 - 11:24 AM

If you mean XBLIG yea i see a quite a few 2d games doing well on there.


PARTNERS