Jump to content
  • Advertisement
Sign in to follow this  
RedRabbit

SDL Bouncing Ball?

This topic is 5457 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Thats a prety broad question. Do you mean like animation, or physics? If you have the core concepts down, animation should be no harder than comming up with the algorithm.

You can either do this by having individual files for the cells, or by making one giant animation strip.

Share this post


Link to post
Share on other sites
sorry for the broad scope of the question. I mean the physics/code. Im working on a pong clone and have everything working as i want (just 2 paddles that move up and down and stop at the edges of the board.) All i need now is the ball! Tho ive given it thought and I think itll be the hardest part. So once again, can any1 help? :)

Share this post


Link to post
Share on other sites
hm, pong with physics could be interestng....

unlike with a real physics engine, pong changes the x velocity of the ball depending on how long the game has been going. the y velocity is dependant on where the ball hits the paddle.

distance of the vector component= velocity of the vector component multiplied by the change in time.

the change in time is usualy the time it takes to complete one cycle of the game.

Do a little research on bounding rectangles, that should help when you get to collision detection.

Share this post


Link to post
Share on other sites
On our SDL Tutorials page, if you scroll down you'll see we have a link to a bouncing penguin demo, with source. You can grab the penguin and chuck him around the box, and he bounces. It's pretty neat :)


Ryan

Share this post


Link to post
Share on other sites
Or, hes just new with sdl and he doesn't know what to do with the ball. I don't think he needs any of those fancy things with real physics...

Share this post


Link to post
Share on other sites

class Ball
{
public:

int x,y;
int xvel,yvel;

void Update();
bool Collide_W_Paddle();
}

Ball::Update()
{
x += xvel;
y += yvel;

if(Collide_W_Paddle())
xvel = -xvel;
}




something like this should give you an idea. make a Ball instance, and each frame call Update() on it. you can search the forums or the articles section to learn how collision works.

Share this post


Link to post
Share on other sites
maybe i just dont know how to ask questions lol....im making a pong clone and need a ball in it (as you know)....i dont know of any function to draw a ball in SDL. so is there any1 that knows of such a function? collision/physics question has already been answered :-P just need a ball...thanks :) (sorry again for my horrible question asking abilities lol)

Share this post


Link to post
Share on other sites
Well, do you have paddles? If so, how did you display them? The same method can be used to display your ball. Simply create a bitmap with an image of a ball in it (use a paint program to draw a circle!) and then use SDL_LoadBMP to load the bitmap, and then SDL_BlitSurface to display it.

That's how you display any image, with the standard SDL library.


Ryan

Share this post


Link to post
Share on other sites
yea i made paddles already. just didnt know if u could draw a circle....i wasnt going to use a bitmap for the circle but will that be the best way?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!