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

  1. #ifndef _global_h
  2. #    include "global.h"
  3. #endif
  4.  
  5. #ifndef _curling_h
  6. #    include "curling.h"
  7. #endif
  8. #ifndef _arcs_h
  9. #    include "arcs.h"
  10. #endif
  11. #ifndef _ball_h
  12. #    include "ball.h"
  13. #endif
  14. #ifndef _goal_h
  15. #    include "goal.h"
  16. #endif
  17. #ifndef _wall_h
  18. #    include "wall.h"
  19. #endif
  20. #ifndef _graph_h
  21. #    include "graph.h"
  22. #endif
  23. #ifndef _mover_h
  24. #    include "mover.h"
  25. #endif
  26.  
  27. //#undef CURLS
  28. //#define CURLS 1
  29.  
  30. void Curling::InitTable() {
  31.     mid = Vec2( AreaOffX()+AreaWidth()*7.0/8.0, AreaOffY()+AreaHeight()/2.0 );
  32.     goal= new Goal(    Vec2( AreaOffX()+AreaWidth(), AreaOffY() ),
  33.                             Vec2( AreaOffX()+AreaWidth(), AreaOffY()+AreaHeight() ) );
  34.  
  35.     w[0] = new Wall( Edge(2), Edge(3) );
  36.     w[1] = new Wall( Edge(3), Edge(0) );
  37.     w[2] = new Wall( Edge(0), Edge(1) );
  38. }
  39.  
  40.  
  41. void Curling::InitArea( double wx, double wy ) {
  42.     area_width  = wx;
  43.     area_height = wy;
  44.     area_off_x = (MaxX()-area_width)/2.;
  45.     area_off_y = (MaxY()-KeeperHeight-area_height)/2.;
  46. }
  47.  
  48.  
  49. Curling::Curling(double wx, double wy) :
  50.     Game(wx+2.*FrameOffset,wy+2.*FrameOffset + KeeperHeight)
  51. {
  52.     goal = 0;
  53.  
  54.     InitArea(wx,wy);
  55.  
  56.     table_col            = SetMainBgColor( "white" );
  57.     black_bg_col        = AddBgColor( "black" );
  58.     red_bg_col            = AddBgColor( "red" );
  59.     blue_bg_col            = AddBgColor( "blue" );
  60.  
  61.     curl_col[0]            = AddBallColor( "Maroon" );
  62.     curl_col[1]            = AddBallColor( "MediumAquamarine" );
  63.  
  64.     AddShadeColor( "White", 1, 1 );
  65.     SetCursorColor( "brown" );
  66.  
  67.     keeper = new LineKeeper(KeeperHeight,KeeperFrame,blue_bg_col);
  68.  
  69.     mcurl     = 0;
  70.     curl[0][0] = 0;
  71. }
  72.  
  73. Curling::~Curling() {
  74. int i,j;
  75.  
  76.     if (goal) {
  77.         delete goal;
  78.         for (j=0;j<3;j++)            delete w[j];
  79.     }
  80.     if (mcurl)        delete mcurl;
  81.  
  82.     if (curl[0][0]) {
  83.         for (i=0;i<TEAMS;i++) {
  84.             for (j=0;j<CURLS;j++)        delete curl[i][j];
  85.         }
  86.     }
  87. }
  88.  
  89.  
  90. const Real & Curling::GetPresetA() const {    return PresetA;}
  91. const Real & Curling::GetPresetHaft() const {    return PresetHaft; }
  92. const Real & Curling::GetSlowGranularity() const { return SlowGranularity; }
  93.  
  94. const Real & Curling::GetNormalBallSize() const  { return CurlRadius; }
  95.  
  96. const Real Curling::AreaOffX() const            { return area_off_x; }
  97. const Real Curling::AreaOffY() const            { return area_off_y; }
  98. const Real Curling::AreaWidth() const        { return area_width; }
  99. const Real Curling::AreaHeight() const        { return area_height; }
  100.  
  101.  
  102.  
  103. void Curling::InitPlayground() {
  104.     mcurl = new DiscMover( CurlRadius );
  105.     mcurl->Init();
  106.     DBG2(UnixTrace, "Curling: Radius set back from %g to %g\n",
  107.                     (double)CurlRadius, (double)mcurl->GetActRadius() );
  108.     CurlRadius = mcurl->GetActRadius();
  109.  
  110.  
  111. //    Game::InitPlayground();
  112.     InitTable();
  113.  
  114.     for (int i=0;i<TEAMS;i++) {
  115.         for (int j=0;j<CURLS;j++) {
  116.             Vec2    pos;
  117.             switch(i) {
  118.             case 0:    pos=Edge(0)+Vec2(CurlRadius+Offset,(2.0*CurlRadius+Offset)*(double)j+CurlRadius+Offset);
  119.                         break;
  120.             case 1:    pos=Edge(3)+Vec2(CurlRadius+Offset,-(2.0*CurlRadius+Offset)*(double)j-CurlRadius-Offset);
  121.                         break;
  122.             };
  123.  
  124.             curl[i][j] = new Ball( pos, CurlRadius, CurlWeight );
  125.             curl[i][j]->state
  126.                          = new BallState( mcurl, curl_col[i], curl[i][j]->P() );
  127.         }
  128.     }
  129. }
  130.  
  131.  
  132. void Curling::DrawBackground() const {
  133.     Game::DrawBackground();
  134.  
  135.     SetBgColor( table_col );
  136.     FillRectangle( AreaOffX(), AreaOffY(), AreaWidth(), AreaHeight() );
  137.  
  138.     SetBgColor( blue_bg_col );            FillCircle( mid, 10.0 );
  139.     SetBgColor( table_col );         FillCircle( mid, 9.5 );
  140.     SetBgColor( blue_bg_col );
  141.     for (int i=1;i<4;i++) {
  142.         FillRectangle( AreaOffX()+(double)i*AreaWidth()/4.0-0.25,AreaOffX(),0.5,AreaHeight() );
  143.     }
  144.     SetBgColor( red_bg_col );        FillCircle( mid, 3.0 );
  145.  
  146. #if (0)
  147.     for (int i=0;i<4;i++) {
  148.         Vec2    cmid = (mid+Edge(i))/2.0;
  149.         SetBgColor( blue_bg_col );            FillCircle( cmid, 5.0 );
  150.         SetBgColor( table_col );         FillCircle( cmid, 4.5 );
  151.     }
  152.     SetBgColor( red_bg_col );
  153.     for (i=0;i<4;i++) {
  154.         FillCircle( (mid+Edge(i))/2.0, 2.0 );
  155.     }
  156.  
  157.     SetBgColor( blue_bg_col );
  158.     FillRectangle( AreaOffX()+AreaWidth()/4.0-0.25,AreaOffX(),0.5,AreaHeight() );
  159.     FillRectangle( AreaOffX()+AreaWidth()*3.0/4.0-0.25,AreaOffX(),0.5,AreaHeight() );
  160. #endif
  161. }
  162.  
  163.  
  164.