@@ -57,7 +57,7 @@ void cannonballs::addNew(LOC mouseC, LOC mouseO, double HoldTime ) {
5757 mouseO.y = global::config.values .uintScreenHeight - mouseO.y ;
5858 intCannonBallNum++;
5959 clsCannonball tempBall;
60- tempBall.setValues (radius, mouseO,fire_v, angle, intCannonBallNum);
60+ tempBall.setValues (radius, mouseO, fire_v, angle, intCannonBallNum);
6161 if (intCannonBallNum > 1 ) {
6262 if (balls[0 ].isPaused ()) { tempBall.togglePause (); }
6363 }
@@ -85,8 +85,9 @@ void cannonballs::checkCollisons(uint j) {
8585 B = balls[i].getBOX ();
8686 if ( checkOverlap (A, B) ) {
8787 doCollide (j, i);
88- /* ball_b_loc = balls[i].getdbLOC();
89- do {
88+ ball_b_loc = balls[i].getdbLOC ();
89+ /* * @todo (GamerMan7799#9#): This might work for stopping the balls from overlapping, just need to add a check on which way they are colliding */
90+ /* do {
9091 ball_b_loc.x++;
9192 ball_b_loc.y++;
9293 balls[i].setdbLOC(ball_b_loc);
@@ -243,7 +244,7 @@ void cannonballs::doCollide(uint numA, uint numB) {
243244 break ;
244245 case CollideInelastic:
245246 // uses the same equations as below but some energy is lost.
246-
247+
247248 TotalAMomentum = math::vectorMul (TotalAMomentum,
248249 (double )global::physics::kCoefficientRestitution );
249250 TotalBMomentum = math::vectorMul (TotalAMomentum,
@@ -329,6 +330,7 @@ void core::fireRandom() {
329330 LOC mouseo, mousec;
330331 // time delay can be anywhere from 0.25 to 10 seconds
331332 double time_delay = ((rand () % (10000 -250 ) + 250 ) / 1000 );
333+ if (time_delay <= 0.25 ) { time_delay = 0.25 ; }
332334
333335 mouseo.x = rand () % cnfg.uintScreenWidth ;
334336 mouseo.y = rand () % cnfg.uintScreenHeight ;
@@ -361,8 +363,8 @@ char core::handleEvent(SDL_Event* e ) {
361363 if ( e->type == SDL_QUIT ) { return ' q' ; }
362364
363365 if ( e->type == SDL_MOUSEBUTTONDOWN || e->type == SDL_MOUSEBUTTONUP ) {
364- if (e->type == SDL_MOUSEBUTTONDOWN) {holding = true ;}
365- else if (e->type == SDL_MOUSEBUTTONUP) {holding = false ;}
366+ if (e->type == SDL_MOUSEBUTTONDOWN) { holding = true ; }
367+ else if (e->type == SDL_MOUSEBUTTONUP) { holding = false ; }
366368 // there is a mouse-based event, so now we have to check what tool we are using.
367369 // if (global::blnDebugMode) { printf("Mouse event found.\n"); }
368370 switch ( toolbar.getTool () ) {
@@ -500,7 +502,7 @@ void core::doDeleTool(SDL_Event* e) {
500502 if ( e->type == SDL_MOUSEBUTTONDOWN ){
501503 SDL_GetMouseState (¤tmouse.x , ¤tmouse.y );
502504 ball_num = findSelectedBall (currentmouse);
503- if (ball_num == -1 ) {return ;}
505+ if (ball_num == -1 ) { return ; }
504506 cannonballs::balls[ball_num].blnstarted_ = false ;
505507 }
506508}
@@ -534,7 +536,7 @@ void core::doDragTool(SDL_Event* e) {
534536 if (e->type == SDL_MOUSEBUTTONDOWN) { ball_num = findSelectedBall (currentmouse); }
535537 // else if (e->type == SDL_MOUSEBUTTONUP) { ball_num = -1; }
536538
537- if (ball_num == -1 ) {return ;}
539+ if (ball_num == -1 ) { return ; }
538540
539541 if (e->type == SDL_MOUSEMOTION && holding) {
540542 currentmouse.y = global::config.values .uintScreenHeight - currentmouse.y ;
@@ -544,14 +546,21 @@ void core::doDragTool(SDL_Event* e) {
544546 // if(global::blnDebugMode) { printf("Tool Drag event\n"); }
545547 if ( holding && !(cannonballs::balls[ball_num].isPaused ()) ) {
546548 cannonballs::balls[ball_num].togglePause ();
547- } else if (!(holding) && cannonballs::balls[ball_num].isPaused ()
548- && !(cannonballs::balls.back ().isPaused ()) &&
549- !(cannonballs::balls.front ().isPaused ())) {
550- // will only unpause the dragged ball if the other balls are also
551- // unpaused. I check the first and last balls to avoid the chance
552- // that the selected ball is the first or last.
553- cannonballs::balls[ball_num].togglePause ();
554- ball_num = -1 ;
549+ } else if ( !(holding) ) {
550+ // check if the ball is the first or last
551+ if (&cannonballs::balls[ball_num] == &cannonballs::balls.front ()) {
552+ if (!(cannonballs::balls.back ().isPaused ()) &&
553+ cannonballs::balls[ball_num].isPaused ()) {
554+ cannonballs::balls[ball_num].togglePause ();
555+ ball_num = -1 ;
556+ }
557+ } else {
558+ if (!(cannonballs::balls.front ().isPaused ()) &&
559+ cannonballs::balls[ball_num].isPaused ()) {
560+ cannonballs::balls[ball_num].togglePause ();
561+ ball_num = -1 ;
562+ }
563+ }
555564 }
556565}
557566/* ****************************************************************************/
0 commit comments