@@ -58,9 +58,7 @@ void cannonballs::addNew(LOC mouseC, LOC mouseO, double HoldTime ) {
5858 intCannonBallNum++;
5959 clsCannonball tempBall;
6060 tempBall.setValues (radius, mouseO, fire_v, angle, intCannonBallNum);
61- if (intCannonBallNum > 1 ) {
62- if (balls[0 ].isPaused ()) { tempBall.togglePause (); }
63- }
61+ if (global::blnPaused) { tempBall.togglePause (); }
6462 balls.push_back (tempBall);
6563
6664 return ;
@@ -77,6 +75,7 @@ void cannonballs::checkCollisons(uint j) {
7775 // ///////////////////////////////////////////////
7876
7977 BOX A, B;
78+ dblXY ball_a_loc;
8079 dblXY ball_b_loc;
8180 A = balls[j].getBOX ();
8281 if (balls[j].blncheckphysics_ ) {
@@ -85,14 +84,31 @@ void cannonballs::checkCollisons(uint j) {
8584 B = balls[i].getBOX ();
8685 if ( checkOverlap (A, B) ) {
8786 doCollide (j, i);
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 {
91- ball_b_loc.x++;
92- ball_b_loc.y++;
87+ /* * @todo (GamerMan7799#3#): This might work for stopping the balls from overlapping, just need to add a check on which way they are colliding */
88+ #if DEFINED_PUSH_BALLS_OUT_OF_OVERLAP == 1
89+ ball_a_loc = balls[j].getdbLOC ();
90+ ball_b_loc = balls[i].getdbLOC ();
91+ do {
92+ if (A.right <= B.right && A.right >= B.left ) {
93+ ball_a_loc.x --;
94+ ball_b_loc.x ++;
95+ } else if (A.left >= B.left && A.left <= B.right ) {
96+ ball_a_loc.x ++;
97+ ball_b_loc.x --;
98+ }
99+ if (A.top >= B.top && A.top <= B.bottom ) {
100+ ball_a_loc.y ++;
101+ ball_b_loc.y --;
102+ } else if (A.bottom >= B.top && A.bottom <= B.bottom ) {
103+ ball_a_loc.y --;
104+ ball_b_loc.y ++;
105+ }
93106 balls[i].setdbLOC (ball_b_loc);
107+ balls[j].setdbLOC (ball_a_loc);
108+ A = balls[j].getBOX ();
94109 B = balls[i].getBOX ();
95- } while (checkOverlap(A,B)); */
110+ } while (checkOverlap (A,B));
111+ #endif
96112 balls[i].blncheckphysics_ = false ;
97113 balls[j].blncheckphysics_ = false ;
98114 } // end if overlap
@@ -111,12 +127,24 @@ bool cannonballs::checkOverlap(BOX A, BOX B) {
111127 // /
112128 // ///////////////////////////////////////////////
113129
114- if ( A.right < B.left ){ return false ; }
130+ /* * @todo (GamerMan7799#9#): Improve the overlap check to allow pixel-by-pixel detection */
131+
132+ if (A.right <= B.right && A.right >= B.left ) {
133+ if (A.top >= B.top && A.top <= B.bottom ) { return true ; }
134+ else if (A.bottom >= B.top && A.bottom <= B.bottom ) { return true ; }
135+ else { return false ; }
136+ } else if (A.left >= B.left && A.left <= B.right ) {
137+ if (A.top >= B.top && A.top <= B.bottom ) { return true ; }
138+ else if (A.bottom >= B.top && A.bottom <= B.bottom ) { return true ; }
139+ else { return false ; }
140+ } else { return false ; }
141+
142+ /* if( A.right < B.left ){ return false; }
115143 if( A.left > B.right ){ return false; }
116144 if( A.bottom < B.top ){ return false; }
117145 if( A.top > B.bottom ){ return false; }
118146
119- return true ;
147+ return true;*/
120148}
121149/* ****************************************************************************/
122150void cannonballs::doCollide (uint numA, uint numB) {
@@ -408,6 +436,7 @@ char core::handleEvent(SDL_Event* e ) {
408436 return 0 ;
409437 case SDLK_p:
410438 // "pauses" the simulation by preventing ball from updating
439+ global::blnPaused = !(global::blnPaused);
411440 for (int i = 0 ; i < cannonballs::balls.size (); ++i)
412441 { cannonballs::balls[i].togglePause (); }
413442 return 0 ;
@@ -544,23 +573,11 @@ void core::doDragTool(SDL_Event* e) {
544573 }
545574
546575 // if(global::blnDebugMode) { printf("Tool Drag event\n"); }
547- if ( holding && !(cannonballs::balls[ball_num].isPaused ()) ) {
576+ if ( holding && !(cannonballs::balls[ball_num].isPaused ()) && !(global::blnPaused) ) {
548577 cannonballs::balls[ball_num].togglePause ();
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- }
578+ } else if ( !(holding) && !(global::blnPaused) ) {
579+ cannonballs::balls[ball_num].togglePause ();
580+ ball_num = -1 ;
564581 }
565582}
566583/* ****************************************************************************/
0 commit comments