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

  1. #ifndef _global_h
  2. #    include "global.h"
  3. #endif
  4.  
  5. #ifndef _billard_h
  6. #    include "billard.h"
  7. #endif
  8. #ifndef _wall_h
  9. #    include "wall.h"
  10. #endif
  11. #ifndef _graph_h
  12. #    include "graph.h"
  13. #endif
  14. #ifndef _mover_h
  15. #    include "mover.h"
  16. #endif
  17.  
  18. //
  19. // Voreinstellungen
  20. //
  21.  
  22. void Billard::InitArea( double wx, double wy ) {
  23.     area_width    = wx;
  24.     area_height    = wy;
  25.     if (area_width/2.0>area_height)        area_height = area_width/2.0;
  26.     else                                        area_width  = area_height*2.0;
  27.     area_off_x = (MaxX()-area_width)/2.0;
  28.     area_off_y = (MaxY()-area_height)/2.0;
  29. }
  30.  
  31. int Billard::SelectTable( int col ) {
  32.     if (col<0) {
  33.             if (color_flag>0)        col = color_flag - 1;
  34.             else                        col=((int)(GetCurrentTime()*10))%3;
  35.     }
  36.     if (col>2)    col=1;
  37.  
  38.     switch(col) {
  39.     case 1:
  40.         SetMainBgColor( "rgb:60/90/70" );                // SeaGreen-GlobalBackground
  41.         ResetColor( table_line_col, "rgb:00/50/00" );    // DarkGreen
  42.         ResetColor( table_light_col, "rgb:80/B0/90" );    // LimeGreen
  43.     //    ResetColor( table_dark_col, "MediumForestGreen" );
  44.         SetCursorColor( "PaleTurquoise" );
  45.         break;
  46.     case 2:
  47.         SetMainBgColor( "rgb:80/A0/C0" );        // LightSteelBlue-GlobalBackground
  48.         ResetColor( table_line_col, "rgb:40/50/80" );        // SteelBlue
  49.         ResetColor( table_light_col, "rgb:A0/C0/E0" );    // LightSteelBlue3
  50.     //    ResetColor( table_dark_col, "LightSteelBlue4" );
  51.         SetCursorColor( "Maroon" );
  52.         break;
  53.     case 0:
  54.         SetMainBgColor( "rgb:f0/80/60" );        // coral2-GlobalBackground
  55.         ResetColor( table_line_col, "rgb:78/38/28" );    // coral4
  56.         ResetColor( table_light_col, "rgb:ff/A0/80" );    // LightSalmon2
  57.     //    ResetColor( table_dark_col, "coral3" );
  58.         SetCursorColor( "Navy" );
  59.         break;
  60.     }
  61.     return col;
  62. }
  63.  
  64. void Billard::InitTable() {
  65.     w[0] = new Wall( AreaOffX(),                    AreaOffY(),
  66.                                         AreaOffX()+AreaWidth(), AreaOffY() );
  67.     w[1] = new Wall( AreaOffX()+AreaWidth(),    AreaOffY(),
  68.                                         AreaOffX()+AreaWidth(), AreaOffY()+AreaHeight() );
  69.     w[2] = new Wall( AreaOffX()+AreaWidth(),    AreaOffY()+AreaHeight(),
  70.                                         AreaOffX(),                    AreaOffY()+AreaHeight() );
  71.     w[3] = new Wall( AreaOffX(),                    AreaOffY()+AreaHeight(),
  72.                                         AreaOffX(),                    AreaOffY() );
  73. }
  74.  
  75. Billard::Billard(double wx, double wy) :
  76.     Game(wx+2.0*FrameOffset,wy+2.0*FrameOffset)
  77. {
  78.     for (int i=0;i<4;i++)    w[i]=0;
  79.  
  80.     InitArea(wx- 2.0*FrameOffset,wy- 2.0*FrameOffset);
  81.  
  82.     table_col            = SetMainBgColor( "SeaGreen" );    // GlobalBackground
  83.  
  84.     outer_cushion_col    = AddStatColor( "black" );
  85.     marker_col            = AddStatColor( "brown" );
  86.  
  87.     table_line_col        = AddBgColor( "DarkGreen" );
  88.     table_light_col    = AddBgColor( "LimeGreen" );
  89. //    table_dark_col        = AddBgColor( "MediumForestGreen" );
  90.  
  91.     table_col         = CreateColorMix( 0, table_light_col, 3 );
  92.  
  93.     inner_cushion_col = CreateColorMix( table_line_col, table_light_col, 15 );
  94.  
  95. //    floor = AddStatColor( "LightGoldenrod" );
  96.     floor = CreateColorMix( table_line_col, 0 );
  97.  
  98.     AddShadeColor( "White", 1, 1 );
  99.  
  100.     m = 0;
  101. }
  102.  
  103. Billard::~Billard() {
  104.     for (int i=0;i<4;i++)        if (w[i])        delete w[i];
  105.  
  106.     if (m) {
  107.         delete m;
  108.         m=0;
  109.     }
  110. }
  111.  
  112. const Real & Billard::GetPresetA() const {
  113.     return PresetA;
  114. }
  115.  
  116. const Real & Billard::GetPresetHaft() const {
  117.     return PresetHaft;
  118. }
  119.  
  120. const Real & Billard::GetSlowGranularity() const {
  121.     return SlowGranularity;
  122. }
  123.  
  124. const Real Billard::AreaOffX() const        { return area_off_x; }
  125. const Real Billard::AreaOffY() const        { return area_off_y; }
  126. const Real Billard::AreaWidth() const        { return area_width; }
  127. const Real Billard::AreaHeight() const        { return area_height; }
  128.  
  129. const Real Billard::PAreaOffX() const        { return area_off_x-InnerCushion; }
  130. const Real Billard::PAreaOffY() const        { return area_off_y-InnerCushion; }
  131. const Real Billard::PAreaWidth() const        { return area_width+2.0*InnerCushion; }
  132. const Real Billard::PAreaHeight() const    { return area_height+2.0*InnerCushion; }
  133.  
  134. const Real Billard::TAreaOffX() const
  135.                             { return area_off_x-InnerCushion-OuterCushion; }
  136. const Real Billard::TAreaOffY() const
  137.                             { return area_off_y-InnerCushion-OuterCushion; }
  138. const Real Billard::TAreaWidth() const
  139.                             { return area_width+2.0*(InnerCushion+OuterCushion); }
  140. const Real Billard::TAreaHeight() const
  141.                             { return area_height+2.0*(InnerCushion+OuterCushion); }
  142.  
  143. void Billard::InitPlayground() {
  144.     if (!m) {
  145.         m = new ShadedBallMover( GetNormalBallSize() );
  146.         m->Init();
  147.     }
  148.     Game::InitPlayground();
  149. #ifdef DEBUG
  150.     if (debug&ShowLight) {
  151.         m->CreateLightWindow();
  152.     }
  153. #endif
  154. }
  155.  
  156. void Billard::DrawMarker( const Real &midx, const Real &midy, const Real &ox, const Real &oy ) const {
  157. Vec2    v1( midx   , midy+oy );
  158. Vec2    v2( midx-ox, midy    );
  159. Vec2    v3( midx   , midy-oy );
  160. Vec2    v4( midx+ox, midy    );
  161.  
  162.     FillPoly( 4, &v1, &v2, &v3, &v4 );
  163. }
  164.  
  165. void Billard::DrawBackground() const {
  166. double i;
  167.  
  168.     Game::DrawBackground();
  169.  
  170.     SetBgColor( outer_cushion_col );
  171.     FillRectangle( TAreaOffX(), TAreaOffY(), TAreaWidth(), TAreaHeight() );
  172.  
  173.     SetBgColor(inner_cushion_col);
  174.     FillRectangle( PAreaOffX(), PAreaOffY(), PAreaWidth(), PAreaHeight() );
  175.  
  176.     SetBgColor( table_col );
  177.     FillRectangle( AreaOffX(), AreaOffY(), AreaWidth(), AreaHeight() );
  178.  
  179. #if (0)
  180.     {
  181.     int    px1 = w2n*(AreaOffX());
  182.     int    py1 = w2n*(AreaOffY());
  183.     int    px2 = w2n*(AreaOffX()+AreaWidth());
  184.     int    py2 = w2n*(AreaOffY()+AreaHeight());
  185.     int    px  = px2-px1;
  186.     int    py  = py2-py1;
  187.     int    pts = px*py;
  188.  
  189.         SetBgColor(table_light_col);
  190.         for (int i=pts/8;i>0;i--) {
  191.             XDrawPoint(dpy,win,gc_current,px1+rand()%px,py1+rand()%py);
  192.         }
  193.     }
  194. #endif
  195.  
  196. double    outer = PAreaOffY()-TAreaOffY();
  197.     SetBgColor( marker_col );
  198.     for (i=1;i<8;i++) {
  199.         DrawMarker( AreaOffX()+AreaWidth()*i/8.0, TAreaOffY()+outer/2.0,
  200.                                                                             outer/8.0, outer/4.0 );
  201.         DrawMarker( AreaOffX()+AreaWidth()*i/8.0, TAreaOffY()+TAreaHeight()-outer/2,
  202.                                                                             outer/8.0, outer/4.0 );
  203.     }
  204.     for (i=1;i<4;i++) {
  205.         DrawMarker( TAreaOffX()+outer/2.0, AreaOffY()+AreaHeight()*i/4.0,
  206.                                                                         outer/4.0, outer/8.0 );
  207.         DrawMarker( TAreaOffX()+TAreaWidth()-outer/2.0, AreaOffY()+AreaHeight()*i/4.0,
  208.                                                                         outer/4.0, outer/8.0 );
  209.     }
  210. }
  211.