User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Game Development section within the Software Development category of DaniWeb, a massive community of 423,214 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,883 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Game Development advertiser: Programming Forums

Breakout Ball bouncing physics

Join Date: Jan 2008
Location: USA East Cost
Posts: 389
Reputation: CoolGamer48 is on a distinguished road 
Rep Power: 1
Solved Threads: 37
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Whiz

Re: Breakout Ball bouncing physics

  #10  
May 11th, 2008
Hey,

I have some code for bouncing. It works well most of the time but there are some issues at times. Does this look good?

  1. if(m_position.y+m_height >= paddle->GetY() && m_position.y <= paddle->GetY() + paddle->GetHeight() && m_position.x+m_width/2 > paddle->GetX() && m_position.x+m_width/2 < paddle->GetX() + paddle->GetWidth())
  2. {
  3. m_velocity.x += paddle->GetMoveX()*(0.25);
  4. m_velocity.y *= (-1);
  5. }
  6. else if(m_position.x+m_width >= paddle->GetX() && m_position.x <= paddle->GetX() + paddle->GetWidth() && m_position.y+m_height/2 > paddle->GetY() && m_position.y+m_height/2 < paddle->GetY() + paddle->GetWidth())
  7. {
  8. m_velocity.x *= (-1);
  9. m_velocity.y -= paddle->GetSpeed()*(0.15);
  10. }

The code's in C++, and the scope is within the ball class. So things like m_position and m_width refer to the ball, and paddle->GetX() and paddle->GetWidth() refer to the paddle. if you'd like me to give it in more basic pseudo code let me know.
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
Reply With Quote  
All times are GMT -4. The time now is 9:01 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC