home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / flying-6.11 / keeper.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-30  |  4.5 KB  |  182 lines

  1. #ifndef _global_h
  2. #    include "global.h"
  3. #endif
  4.  
  5. #ifndef _ball_h
  6. #    include "ball.h"
  7. #endif
  8. #ifndef _wall_h
  9. #    include "wall.h"
  10. #endif
  11. #ifndef _keeper_h
  12. #    include "keeper.h"
  13. #endif
  14. #ifndef _game_h
  15. #    include "game.h"
  16. #endif
  17. #ifndef _graph_h
  18. #    include "graph.h"
  19. #endif
  20.  
  21. Keeper::Keeper(const Real &size_in, const Real &frame_in, ColorId frame_col_in, ColorId table_col_in) {
  22.     size  = size_in;
  23.     frame = frame_in;
  24.     frame_col = frame_col_in;
  25.     table_col = table_col_in;
  26.     off_count = 0;
  27. }
  28.  
  29. Keeper::~Keeper() {}
  30.  
  31. void Keeper::TakeOffBoard(Ball *b) {
  32.     b->Draw();        // Ball an aktueller Position l÷schen
  33.     b->GoUnlocked();
  34.     g->InPocket(b);
  35.  
  36.     PlaceOffBoard(b);
  37.  
  38.     off_count++;
  39.     b->Draw();        // Ball an neuer Position setzen
  40. }
  41.  
  42. int Keeper::IsOffBoard(Ball * /*b*/) {
  43.     return 0;
  44. }
  45.  
  46. Ball *Keeper::GetBack(Ball *b) {
  47.     return b;
  48. }
  49.  
  50. ///////////////////////////////////////////////////////////
  51.  
  52. extern double    world_x, world_y;
  53.  
  54. //
  55. // Klasse LinePocket -  Objekte werden in Zeile am unteren Bildrand geworfen
  56. //
  57.  
  58. LineKeeper::LineKeeper(const Real &height, const Real &frame, ColorId frame_col, ColorId table_col, int mode_in) : Keeper(height,frame,frame_col, table_col)
  59. {
  60. Real    ypos=(mode_in&UPPER_FLAG)?0.0:(double)(MaxY()-size);
  61.  
  62.     mode = mode_in;
  63.     if (mode&CLOSE_LEFT) {
  64.             wall1 = new Wall(frame,ypos,frame,ypos+size);
  65.     }
  66.     else    wall1 = 0;
  67.     if (mode&CLOSE_RIGHT) {
  68.             wall2 = new Wall(MaxX()-frame,ypos,MaxX()-frame,ypos+size);
  69.     }
  70.     else    wall2 = 0;
  71. }
  72.  
  73. LineKeeper::~LineKeeper()
  74. {
  75.     if (wall1)    delete wall1;
  76.     if (wall2)    delete wall2;
  77. }
  78.  
  79. void LineKeeper::Draw() {
  80.  
  81.     if (mode&UPPER_FLAG) {
  82.         SetBgColor(table_col);
  83.         FillRectangle( 0.0, 0.0, MaxX(), size );
  84.         SetBgColor(frame_col);
  85.         FillRectangle( 0.0, 0.0,  MaxX(), frame );
  86.         FillRectangle( 0.0, size-frame, MaxX(), frame );
  87.         if (mode&CLOSE_LEFT)
  88.                 FillRectangle( 0.0, 0.0,  frame, size);
  89.         if (mode&CLOSE_RIGHT)
  90.                 FillRectangle( MaxX()-frame, 0.0,  frame, size);
  91.     }
  92.     else {
  93.         SetBgColor(table_col);
  94.         FillRectangle( 0.0, MaxY()-size, MaxX(), size );
  95.         SetBgColor(frame_col);
  96.         FillRectangle( 0.0, MaxY()-size,  MaxX(), frame );
  97.         FillRectangle( 0.0, MaxY()-frame, MaxX(), frame );
  98.         if (mode&CLOSE_LEFT)
  99.                 FillRectangle( 0.0, MaxY()-size,  frame, size);
  100.         if (mode&CLOSE_RIGHT)
  101.                 FillRectangle( MaxX()-frame, MaxY()-size,  frame, size);
  102.     }
  103. }
  104.  
  105. void LineKeeper::PlaceOffBoard( Ball *b ) {
  106. Real    to;        // Endpunkt fⁿr aktuelle Kugel in der Pocketline
  107. Real    from;        // Startpunkt fⁿr aktuelle Kugel in der Pocketline
  108. Real    vx;        // Startgeschwindigkeit, damit Kugel in Punkt to liegenbleibt
  109.  
  110.     to        = Real((off_count*2+1))*g->GetNormalBallSize()+frame;
  111. //    from    = world_x - Real(40-off_count*2)*g->GetNormalBallSize();
  112.     from  = world_x - 2.0*g->GetNormalBallSize();
  113.     vx        = sqrt( 2.*fabs((to-from)*b->a) );
  114.  
  115.     b->p = Vec2( from, world_y-size/2. );
  116.     b->SetV( Vec2(-vx,RealZero) );
  117. }
  118.  
  119. //
  120. // Klasse StackKeeper -  Objekte werden in Zeile am rechten Bildrand geworfen
  121. //
  122.  
  123. StackKeeper::StackKeeper(const Real &width, const Real &frame, ColorId frame_col, ColorId table_col,int mode_in) : Keeper(width,frame,frame_col,table_col)
  124. {
  125. Real    xpos=(mode_in&LEFT_FLAG)?0.0:(double)(MaxX()-size);
  126.  
  127.     mode = mode_in;
  128.     if (mode&CLOSE_TOP) {
  129.             wall1 = new Wall(xpos,frame,xpos+size,frame);
  130.     }
  131.     else    wall1 = 0;
  132.     if (mode&CLOSE_BOT) {
  133.             wall2 = new Wall(xpos,MaxY()-frame,xpos+size,MaxY()-frame);
  134.     }
  135.     else    wall2 = 0;
  136. }
  137.  
  138. StackKeeper::~StackKeeper()
  139. {
  140.     if (wall1)        delete wall1;
  141.     if (wall2)        delete wall2;
  142. }
  143.  
  144. void StackKeeper::Draw() {
  145.     if (mode&LEFT_FLAG) {
  146.         SetBgColor(table_col);
  147.         FillRectangle( 0.0, 0.0, size,  MaxY() );
  148.         SetBgColor(frame_col);
  149.         FillRectangle( 0.0, 0.0, frame, MaxY() );
  150.         FillRectangle( size-frame,0.0, frame, MaxY() );
  151.         if (mode&CLOSE_TOP)
  152.                 FillRectangle( 0.0, 0.0,  size, frame);
  153.         if (mode&CLOSE_BOT)
  154.                 FillRectangle( 0.0, MaxY()-frame, size, frame);
  155.     }
  156.     else {
  157.         SetBgColor(table_col);
  158.         FillRectangle( MaxX()-size, 0.0, size,  MaxY() );
  159.         SetBgColor(frame_col);
  160.         FillRectangle( MaxX()-size, 0.0, frame, MaxY() );
  161.         FillRectangle( MaxX()-frame,0.0, frame, MaxY() );
  162.         if (mode&CLOSE_TOP)
  163.                 FillRectangle( MaxX()-size, 0.0,  size, frame);
  164.         if (mode&CLOSE_BOT)
  165.                 FillRectangle( MaxX()-size, MaxY()-frame, size, frame);
  166.     }
  167. }
  168.  
  169. void StackKeeper::PlaceOffBoard( Ball *b ) {
  170. Real    to;        // Endpunkt fⁿr aktuelle Kugel in der Pocketline
  171. Real    from;        // Startpunkt fⁿr aktuelle Kugel in der Pocketline
  172. Real    vy;        // Startgeschwindigkeit, damit Kugel in Punkt to liegenbleibt
  173.  
  174.     to        = world_y - (Real(off_count*2+1)*g->GetNormalBallSize()+frame);
  175.     from    = Real(40-off_count*2)*g->GetNormalBallSize();
  176.     vy        = sqrt( fabs((to-from)*b->a) );
  177.  
  178.     b->p = Vec2( world_x-size/2., from );
  179.     b->SetV( Vec2(RealZero,vy) );
  180. }
  181.  
  182.