// put the proper #include's here // void GetMouse( Point & pt ) returns (immediately) and fills its argument, // passed by reference, with the coordinates of the mouse pointer // at the time of the function call. The function has another form, // void GetMouse( int & x , int & y ). // // Reminder: struct Point { // int h; // x-coordinate // int v; // y-coordinate // }; // // bool Button() returns (immediately) the status of the mouse button // at the moment of the call, true if down, false if up. // DEMO 0: // The mote's direction of movement is determined by the current // position of the mouse pointer. The mote always moves towards the // pointer position. int main(){ BigSquarePair(); int x = 200, y = 200, r = 3; int vx = 0, vy = 0; int velocity = 1; // the number of pixels traveled in one tick // Velocities greater than 1 lead to a funny bug. // See if you can fix it :-) . // cout << "Enter mote speed (1-10): "; // cin >> velocity; cout << "\nDirect the mote with the mouse,\n"; cout << "Click the mouse button to finish.\n\n"; while( ! Button() ){ // while the button is up Point pt; GetMouse( pt ); // fill pt with mouse pointer coords // Figure out the next movement. // The code below makes the horizontal and // vertical movements indepedent. if( x > pt.h ) vx = -velocity; else if( x < pt.h ) vx = velocity; else vx = 0; if( y > pt.v ) vy = -velocity; else if( y < pt.v ) vy = velocity; else vy = 0; SetForeColor( 255, 255, 255 ); // erase mote PaintCircle( x, y, r ); x += vx; // update position y += vy; if( x < 0 ) // wrap around the screen if going x = 400; // beyond the screen margins else if( x > 400 ) x = 0; if( y < 0 ) y = 400; else if( y > 400 ) y = 0; SetForeColor( 0, 0, 255 ); // draw mote PaintCircle( x, y, r ); Delay( 50 ); } PressReturn(); return 0; }