hey guys im new to programming c++ some helperz please?

so see i am at lost with apis and programming.

what is an "api" exactly? from what i gather its a set of code in files that operates a graphical or some kind of facility to layer programming code?

cuz i wanna make a small ping pong game and im sorta good in c++ ... i mean i get some small things done. lol.

i can also somewhat operate with sdl but im too lost when it comes to application of physics and stuff in ping pong ... can anyone help me draw out this?

fundamentals of a ping pong game, like:

1.how to do collision efficiently.

2.calculate trijectory in motion for angular reverses of directions

3.how to accurately make the computer "know" where to move without errors

just a LITTLE insight will be appreciated. thanks!
3- set y axis of the ball = to the y axis of the AI.
also how new are you?
API is an Application Programming Interface.

It can generally vary. It can be a standard or a set of functions that interface with other software/hardware.

http://en.wikipedia.org/wiki/Application_programming_interface

If you want to make a basic Ping Pong game, the APIs you'd be most interested in are probably SDL or SMFL.

1) You'd usually check for an overlap in coordinates between the two entities.

2) Not sure what you mean by this. You'll have to elaborate a bit more. If you're looking to reverse the direction of the ball, you can simply multiply it's speed along an axis by -1, depending on the way it's implemented. To keep it simple, I would go with a Cartesian coordinate system and give your entities x and y speeds.

3) Trigonometry would be an easy way. Use trigonometry to work out where the ball will be when it has the same y coordinate as a paddle, providing it continues on the same path. You need to make sure there's margin for error on the AI's part so that it doesn't return the ball every time. An unwinnable game isn't a fun one. This is probably easiest accomplished by making sure that the AI paddle isn't quick enough to reach the ball's target location in every instance.

Hope this helps.
1) You don't have to call them entities. Call them objects, instances or whatever you want. Not sure what you need clarifying. If you check the coordinates of the two objects and they're overlapping then there's a collision. If it's a ball collision, you'd probably use the centre of the ball plus the radius as the position to check.

2) Say your ball is moving to the right side of the screen by 1 pixel per second. Probably not a real scenario, but it's an example. So the ball x speed is 1. It's moving 1 pixel along the x axis. If you want it to move less, it needs to be a negative value, so if you multiply the x speed by -1, it'll become -1 and start moving left. To make it move right again, it's the same operation; multiply by -1. You could make a switch direction function that does this.

3) Any graphical game will require coordinate geometry. Any game will involve maths. I recommend doing some math refreshers as it'll help you out a lot on the way. You wouldn't really need trigonometry if you were to create an CPU paddle that randomly moved. However, if you want it to be semi intelligent then you'll need it. The ball, paddle and ball's position when it meets the paddle's y-axis would form the triangle that you'd need to work out where the paddle should attempt to move to in order to hit the ball.
Topic archived. No new replies allowed.