0

I have been working on creating my first game, (PONG), using C++ and SDL. I have been following a tutorial online and have gotten about half way through. I am now confused from the syntax in the code which also gives me an error. I'm not aware of this use of code.

if (Contact contact = CheckPaddleCollision(ball, paddleOne)**;**
                contact.type != CollisionType::None)
            {
                // Ball operates on its own data . ball.CollideWithPaddle/ball.velocity.x
                ball.CollideWithPaddle(contact);
            }
            else if (contact = CheckPaddleCollision(ball, paddleTwo);
                contact.type != CollisionType::None)
            {
                ball.CollideWithPaddle(contact);
            }

I do not understand why there is a semicolon before a closing parenthesis. I really don't understand this use of code. I am used to seeing a bool after an if statement. These to if statements do not build for me ; was this a mistake in source code? Any help explaining this code with be of great help.

Source code for the program can be found here. https://code.austinmorlan.com/austin/pong/src/branch/master/Main.cpp

Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
Anthony
  • 33
  • 5
  • 4
    This appears to be C++, not C. – Drew Dormann Jun 22 '21 at 17:44
  • Looks like the writer it working to constrain the scope of `contact`. – user4581301 Jun 22 '21 at 17:47
  • 2
    Check the [docs for `if` in C++](https://en.cppreference.com/w/cpp/language/if), especially the 3rd/4th form `attr(optional) if constexpr(optional) ( init-statement(optional) condition ) ...` - in detail described [here](https://en.cppreference.com/w/cpp/language/if#If_Statements_with_Initializer) – CherryDT Jun 22 '21 at 17:48
  • Thanks people for all the help. There's a lot more to learn for me in C++. – Anthony Jun 22 '21 at 19:13

0 Answers0