Click here to Skip to main content
15,848,252 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Richard MacCutchan19-Jan-18 2:05
mveRichard MacCutchan19-Jan-18 2:05 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Member 1363226319-Jan-18 2:22
Member 1363226319-Jan-18 2:22 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Richard MacCutchan19-Jan-18 2:23
mveRichard MacCutchan19-Jan-18 2:23 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Member 1363226319-Jan-18 2:54
Member 1363226319-Jan-18 2:54 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Richard MacCutchan19-Jan-18 3:51
mveRichard MacCutchan19-Jan-18 3:51 
AnswerRe: Problem with multiple bouncing balls program in C Pin
Jochen Arndt19-Jan-18 2:07
professionalJochen Arndt19-Jan-18 2:07 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Member 1363226319-Jan-18 2:53
Member 1363226319-Jan-18 2:53 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Jochen Arndt19-Jan-18 3:21
professionalJochen Arndt19-Jan-18 3:21 
Sorry, I missed the number of balls.

But my other notes are still valid (out of bound array access and why not updating with small steps). For timing purposes (slower movement), wait outside the for loop.

I suggest to start with one ball to implement and check the border bouncing. To be realistic, the new directions should be calculated according to the collision angle.

Then proceed with two balls to make it simpler. For collison detection you need another loop (runing from currently processed ball index + 1 to number of balls) to check for collisions like with the borders. Upon a collision you have to set the collision position as new position for both balls and adjust the directions (which requires a flag / state that the other ball has been already processed within the current loop execution). Again, the new directions should be calculated according to the collision angles.

To check the code, you can suppress the drawing and print out the positions and changings instead. Or write them to a text file so that you can inspect it later. For testing it might be also helpful to stop after each step and continue after a key press. So you can check your calculations.
GeneralRe: Problem with multiple bouncing balls program in C Pin
Member 1363226319-Jan-18 3:30
Member 1363226319-Jan-18 3:30 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Jochen Arndt19-Jan-18 3:56
professionalJochen Arndt19-Jan-18 3:56 
AnswerRe: Problem with multiple bouncing balls program in C Pin
Victor Nijegorodov19-Jan-18 22:21
Victor Nijegorodov19-Jan-18 22:21 
AnswerRe: Problem with multiple bouncing balls program in C Pin
Rick York24-Jan-18 8:17
mveRick York24-Jan-18 8:17 
Questionconvert feet and inches to centimeters Pin
nithiin_sai18-Jan-18 15:42
nithiin_sai18-Jan-18 15:42 
SuggestionRe: convert feet and inches to centimeters Pin
Jim Meadors18-Jan-18 16:49
Jim Meadors18-Jan-18 16:49 
AnswerRe: convert feet and inches to centimeters Pin
Victor Nijegorodov18-Jan-18 21:38
Victor Nijegorodov18-Jan-18 21:38 
AnswerRe: convert feet and inches to centimeters Pin
CPallini18-Jan-18 22:47
mveCPallini18-Jan-18 22:47 
AnswerRe: convert feet and inches to centimeters Pin
David Crow19-Jan-18 4:16
David Crow19-Jan-18 4:16 
QuestionStart app without taskbar icon Pin
_Flaviu17-Jan-18 2:56
_Flaviu17-Jan-18 2:56 
AnswerRe: Start app without taskbar icon Pin
Richard MacCutchan17-Jan-18 3:11
mveRichard MacCutchan17-Jan-18 3:11 
AnswerRe: Start app without taskbar icon Pin
Jochen Arndt17-Jan-18 3:20
professionalJochen Arndt17-Jan-18 3:20 
GeneralRe: Start app without taskbar icon Pin
_Flaviu18-Jan-18 2:09
_Flaviu18-Jan-18 2:09 
GeneralRe: Start app without taskbar icon Pin
leon de boer18-Jan-18 2:40
leon de boer18-Jan-18 2:40 
GeneralRe: Start app without taskbar icon Pin
Jochen Arndt18-Jan-18 3:07
professionalJochen Arndt18-Jan-18 3:07 
QuestionTo make an interacting user game on *Tower of hanoi* . Pin
Tarun Jha15-Jan-18 0:58
Tarun Jha15-Jan-18 0:58 
AnswerRe: To make an interacting user game on *Tower of hanoi* . Pin
Jochen Arndt15-Jan-18 1:33
professionalJochen Arndt15-Jan-18 1:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.