Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I made a Game like Peggle Deluxe using C# and XNA for lerning.

I have 2 rectangles a ball and a square field. The ball gets shoot out with a cannon and if the Ball hits the Square the Square disapears and the Ball flys away.But the Ball doesent spring of realistically, it sometimes flys away in a different direction or gets stuck on the edge.

Thads my Code at the moment:

public void Update(Ball b, Deadline dl) 

    ArrayList listToDelete = new ArrayList(); 
    foreach (Field aField in allFields) 
        if (aField.square.Intersects(b.ballhere)) 
            Punkte = Punkte + 100; 

            float distanceX = Math.Abs(b.ballhere.X - aField.square.X); 
            float distanceY = Math.Abs(b.ballhere.Y - aField.square.Y); 

            if (distanceX < distanceY) 
                b.myMovement.X = -b.myMovement.X; 
                b.myMovement.Y = -b.myMovement.Y; 


It changes the X or Y axis depending on how the ball hits the Square but not everytimes.

What could cause the problem?

Thanks for your answer.

Greetings from Switzerland.

share|improve this question

closed as off-topic by Josh Petrie Dec 19 '13 at 2:02

  • This question does not appear to be about game development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

This question appears to be off-topic because it is about debugging your code for you. – Josh Petrie Dec 19 '13 at 2:02

Browse other questions tagged or ask your own question.