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
InitTable()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
InitArea(double wx,double wy)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
Curling(double wx,double wy)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 red_bg_col = AddBgColor( "red" );
58 blue_bg_col = AddBgColor( "blue" );
59
60 table_dark_col = AddBgColor( "gainsboro" );
61 table_col = CreateColorMix( 0, table_dark_col, 3 );
62 floor = AddStatColor( "black" );
63
64 curl_col[0] = AddBallColor( "Maroon" );
65 curl_col[1] = AddBallColor( "MediumAquamarine" );
66
67 AddShadeColor( "White", 1, 1 );
68 SetCursorColor( "brown" );
69
70 keeper = new LineKeeper(KeeperHeight,KeeperFrame,blue_bg_col,table_col);
71
72 mcurl = 0;
73 curl[0][0] = 0;
74 }
75
~Curling()76 Curling::~Curling() {
77 int i,j;
78
79 if (goal) {
80 delete goal;
81 for (j=0;j<3;j++) delete w[j];
82 }
83 if (mcurl) delete mcurl;
84
85 if (curl[0][0]) {
86 for (i=0;i<TEAMS;i++) {
87 for (j=0;j<CURLS;j++) delete curl[i][j];
88 }
89 }
90 }
91
92
GetPresetA()93 const Real & Curling::GetPresetA() const { return PresetA;}
GetPresetHaft()94 const Real & Curling::GetPresetHaft() const { return PresetHaft; }
GetSlowGranularity()95 const Real & Curling::GetSlowGranularity() const { return SlowGranularity; }
96
GetNormalBallSize()97 const Real & Curling::GetNormalBallSize() const { return CurlRadius; }
98
AreaOffX()99 const Real Curling::AreaOffX() const { return area_off_x; }
AreaOffY()100 const Real Curling::AreaOffY() const { return area_off_y; }
AreaWidth()101 const Real Curling::AreaWidth() const { return area_width; }
AreaHeight()102 const Real Curling::AreaHeight() const { return area_height; }
103
104
105
InitPlayground()106 void Curling::InitPlayground() {
107 mcurl = new DiscMover( CurlRadius );
108 mcurl->Init();
109 DBG2(UnixTrace, "Curling: Radius set back from %g to %g\n",
110 (double)CurlRadius, (double)mcurl->GetActRadius() );
111 CurlRadius = mcurl->GetActRadius();
112
113
114 // Game::InitPlayground();
115 InitTable();
116
117 for (int i=0;i<TEAMS;i++) {
118 for (int j=0;j<CURLS;j++) {
119 switch(i) {
120 case 0: curl_p[i][j]=Edge(0)+Vec2(CurlRadius+Offset,(2.0*CurlRadius+Offset)*(double)j+CurlRadius+Offset);
121 break;
122 case 1: curl_p[i][j]=Edge(3)+Vec2(CurlRadius+Offset,-(2.0*CurlRadius+Offset)*(double)j-CurlRadius-Offset);
123 break;
124 };
125
126 curl[i][j] = new Ball( curl_p[i][j], CurlRadius, CurlWeight );
127 curl[i][j]->state
128 = new BallState( mcurl, curl_col[i], curl[i][j]->P() );
129 }
130 }
131 }
132
133
DrawBackground()134 void Curling::DrawBackground() const {
135 Game::DrawBackground();
136
137 SetBgColor( table_col );
138 FillRectangle( AreaOffX(), AreaOffY(), AreaWidth(), AreaHeight() );
139
140 SetBgColor( blue_bg_col ); FillCircle( mid, 10.0 );
141 SetBgColor( table_col ); FillCircle( mid, 9.5 );
142 SetBgColor( blue_bg_col );
143 for (int i=1;i<4;i++) {
144 FillRectangle( AreaOffX()+(double)i*AreaWidth()/4.0-0.25,AreaOffX(),0.5,AreaHeight() );
145 }
146 SetBgColor( red_bg_col ); FillCircle( mid, 3.0 );
147
148 #if (0)
149 for (int i=0;i<4;i++) {
150 Vec2 cmid = (mid+Edge(i))/2.0;
151 SetBgColor( blue_bg_col ); FillCircle( cmid, 5.0 );
152 SetBgColor( table_col ); FillCircle( cmid, 4.5 );
153 }
154 SetBgColor( red_bg_col );
155 for (i=0;i<4;i++) {
156 FillCircle( (mid+Edge(i))/2.0, 2.0 );
157 }
158
159 SetBgColor( blue_bg_col );
160 FillRectangle( AreaOffX()+AreaWidth()/4.0-0.25,AreaOffX(),0.5,AreaHeight() );
161 FillRectangle( AreaOffX()+AreaWidth()*3.0/4.0-0.25,AreaOffX(),0.5,AreaHeight() );
162 #endif
163 }
164
ResetGame()165 void Curling::ResetGame() {
166 for (int i=0;i<TEAMS;i++) {
167 for (int j=0;j<CURLS;j++) {
168 curl[i][j]->SetPV( curl_p[i][j] );
169 }
170 }
171 }
172
173