1 #ifndef _global_h
2 # include "global.h"
3 #endif
4
5 #ifndef _hockey_h
6 # include "hockey.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
InitTable()27 void Hockey::InitTable() {
28 mid = Vec2( AreaOffX()+AreaWidth()/2.0, AreaOffY()+AreaHeight()/2.0 );
29 post[0][0] = new StaticBall( AreaOffX(),AreaOffY()+(AreaHeight()-GoalSize)/2.0 );
30 post[0][1] = new StaticBall( AreaOffX(),AreaOffY()+(AreaHeight()+GoalSize)/2.0 );
31 // goal[0] = new Goal( post[0][0]->P(), post[0][1]->P() );
32 goal[0] = new Goal( Vec2( AreaOffX()-GetNormalBallSize(), AreaOffY() ),
33 Vec2( AreaOffX()-GetNormalBallSize(), AreaOffY()+AreaHeight() ) );
34 post[1][0] = new StaticBall( AreaOffX()+AreaWidth(),AreaOffY()+(AreaHeight()-GoalSize)/2.0 );
35 post[1][1] = new StaticBall( AreaOffX()+AreaWidth(),AreaOffY()+(AreaHeight()+GoalSize)/2.0 );
36 // goal[1] = new Goal( post[1][0]->P(), post[1][1]->P() );
37
38 goal[1] = new Goal( Vec2( AreaOffX()+AreaWidth()+GetNormalBallSize(), AreaOffY() ),
39 Vec2( AreaOffX()+AreaWidth()+GetNormalBallSize(), AreaOffY()+AreaHeight() ) );
40
41 w[0][0] = new Wall( post[0][0]->P(), Edge(0) );
42 w[0][1] = new Wall( Edge(0), Edge(1) );
43 w[0][2] = new Wall( Edge(1), post[1][0]->P() );
44
45 w[1][0] = new Wall( post[0][1]->P(), Edge(3) );
46 w[1][1] = new Wall( Edge(3), Edge(2) );
47 w[1][2] = new Wall( Edge(2), post[1][1]->P() );
48 }
49
50
InitArea(double wx,double wy)51 void Hockey::InitArea( double wx, double wy ) {
52 area_width = wx;
53 area_height = wy;
54 area_off_x = (MaxX()-area_width)/2.;
55 area_off_y = (MaxY()-GoalHeight-area_height)/2.;
56 }
57
58
Hockey(double wx,double wy)59 Hockey::Hockey(double wx, double wy) :
60 Game(wx+2.*FrameOffset,wy+2.*FrameOffset+GoalHeight)
61 {
62 goal[0] = goal[1] = 0;
63
64 InitArea(wx,wy);
65
66 table_col = SetMainBgColor( "white" );
67 red_bg_col = AddBgColor( "red" );
68 blue_bg_col = AddBgColor( "blue" );
69 table_dark_col = AddBgColor( "gainsboro" );
70
71 disc_col = AddBallColor( "black" );
72 hand_col = AddBallColor( "MidnightBlue" );
73
74 table_col = CreateColorMix( 0, table_dark_col, 3 );
75 floor = AddStatColor( "black" );
76
77 AddShadeColor( "White", 1, 1 );
78 SetCursorColor( "brown" );
79
80 keeper = new LineKeeper(GoalHeight,GoalFrame,blue_bg_col,table_col,CLOSE_LEFT|CLOSE_RIGHT);
81
82 mdisc = 0;
83 mhand = 0;
84 disc = hand1 = hand2 = 0;
85 disc_in_goal = 0;
86 }
87
~Hockey()88 Hockey::~Hockey() {
89 int i,j;
90
91 if (goal[0]) {
92 for (i=0;i<2;i++) {
93 delete goal[i];
94 for (j=0;j<2;j++) delete post[i][j];
95 for (j=0;j<3;j++) delete w[i][j];
96 }
97 }
98 if (mdisc) delete mdisc;
99 if (mhand) delete mhand;
100
101 if (disc) delete disc;
102 if (hand1) delete hand1;
103 if (hand2) delete hand2;
104 }
105
106
GetPresetA()107 const Real & Hockey::GetPresetA() const { return PresetA;}
GetPresetHaft()108 const Real & Hockey::GetPresetHaft() const { return PresetHaft; }
GetSlowGranularity()109 const Real & Hockey::GetSlowGranularity() const { return SlowGranularity; }
110
GetNormalBallSize()111 const Real & Hockey::GetNormalBallSize() const { return DiscRadius; }
112
AreaOffX()113 const Real Hockey::AreaOffX() const { return area_off_x; }
AreaOffY()114 const Real Hockey::AreaOffY() const { return area_off_y; }
AreaWidth()115 const Real Hockey::AreaWidth() const { return area_width; }
AreaHeight()116 const Real Hockey::AreaHeight() const { return area_height; }
117
118
119
InitPlayground()120 void Hockey::InitPlayground() {
121 mdisc = new DiscMover( DiscRadius );
122 mdisc->Init();
123 DBG2(UnixTrace, "Hockey: Radius set back from %g to %g\n",
124 (double)DiscRadius, (double)mdisc->GetActRadius() );
125 DiscRadius = mdisc->GetActRadius();
126
127 mhand = new DiscMover( HandRadius );
128 mhand->Init();
129 DBG2(UnixTrace, "Hockey: Radius set back from %g to %g\n",
130 (double)HandRadius, (double)mhand->GetActRadius() );
131 HandRadius = mhand->GetActRadius();
132
133 Game::InitPlayground();
134 InitTable();
135
136 disc = new Ball( mid, DiscRadius, DiscWeight );
137 disc->state = new BallState( mdisc, disc_col, disc->P() );
138
139 hand1 = new Ball( AreaOffX()+AreaWidth()/4., AreaOffY()+AreaHeight()/2.0,
140 0.0, 0.0, HandRadius, HandWeight );
141 hand1->state = new BallState( mhand, hand_col, hand1->P() );
142 hand1->type = Object::HandObj;
143
144 hand2 = new Ball( AreaOffX()+AreaWidth()*3./4., AreaOffY()+AreaHeight()/2.0,
145 0.0, 0.0, HandRadius, HandWeight );
146 hand2->state = new BallState( mhand, hand_col, hand2->P() );
147 hand2->type = Object::HandObj;
148 }
149
150
DrawBackground()151 void Hockey::DrawBackground() const {
152 int i;
153 Game::DrawBackground();
154
155 SetBgColor( table_col );
156 FillRectangle( AreaOffX(), AreaOffY(), AreaWidth(), AreaHeight() );
157 FillRectangle( post[0][0]->PX()-GetNormalBallSize(), post[0][0]->PY(),
158 AreaWidth()+2.*GetNormalBallSize(), GoalSize );
159
160 SetBgColor( blue_bg_col ); FillCircle( mid, 10.0 );
161 SetBgColor( table_col ); FillCircle( mid, 9.5 );
162 SetBgColor( blue_bg_col );
163 FillRectangle( AreaOffX()+AreaWidth()/2.0-0.25,AreaOffX(),0.5,AreaHeight() );
164 SetBgColor( red_bg_col ); FillCircle( mid, 3.0 );
165
166 for (i=0;i<4;i++) {
167 Vec2 cmid = (mid+Edge(i))/2.0;
168 SetBgColor( blue_bg_col ); FillCircle( cmid, 5.0 );
169 SetBgColor( table_col ); FillCircle( cmid, 4.5 );
170 }
171 SetBgColor( blue_bg_col );
172 FillRectangle( AreaOffX()+AreaWidth()/4.0-0.25,AreaOffX(),0.5,AreaHeight() );
173 FillRectangle( AreaOffX()+AreaWidth()*3.0/4.0-0.25,AreaOffX(),0.5,AreaHeight() );
174 SetBgColor( red_bg_col );
175 for (i=0;i<4;i++) {
176 FillCircle( (mid+Edge(i))/2.0, 2.0 );
177 }
178 }
179
180
InPocket(Ball * b)181 void Hockey::InPocket( Ball *b ) {
182 Game::InPocket(b);
183 if (b==disc) {
184 disc_in_goal = 1;
185 }
186 }
187
StopBall(Ball * b)188 void Hockey::StopBall( Ball *b ) {
189 Game::StopBall(b);
190 if (b==disc && disc_in_goal) {
191 disc_in_goal = 0;
192
193 Real to; // Endpunkt f�r aktuelle Kugel in der Pocketline
194 Real from; // Startpunkt f�r aktuelle Kugel in der Pocketline
195 Real vy; // Startgeschwindigkeit, damit Kugel in Mitte (to) liegenbleibt
196
197 to = AreaOffY() + AreaHeight() / 2.0;
198 from = AreaOffY() + AreaHeight() - g->GetNormalBallSize()/2.0;
199 vy = sqrt( 2.0*fabs((to-from)*b->a) );
200
201 b->SetP( Vec2( AreaOffX() + AreaWidth()/2.0, from ) );
202 b->SetV( Vec2(RealZero,-vy) );
203 }
204 }
205
206 //
207
TestHockey(double s)208 TestHockey::TestHockey(double s) :
209 Hockey(), shot_speed(s)
210 {
211 w[0] = 0;
212 }
213
~TestHockey()214 TestHockey::~TestHockey() {
215 if (w[0]) for(int i=0;i<4;i++) delete w[i];
216 }
217
GetPresetA()218 const Real &TestHockey::GetPresetA() const { return PresetA; }
GetSlowGranularity()219 const Real &TestHockey::GetSlowGranularity() const { return SlowGranularity; }
220
221 #if (0)
InitTable()222 void TestHockey::InitTable() {
223 w[0] = new Wall( AreaOffX(), AreaOffY(),
224 AreaOffX()+AreaWidth(), AreaOffY() );
225 w[1] = new Wall( AreaOffX()+AreaWidth(), AreaOffY(),
226 AreaOffX()+AreaWidth(), AreaOffY()+AreaHeight() );
227 w[2] = new Wall( AreaOffX()+AreaWidth(), AreaOffY()+AreaHeight(),
228 AreaOffX(), AreaOffY()+AreaHeight() );
229 w[3] = new Wall( AreaOffX(), AreaOffY()+AreaHeight(),
230 AreaOffX(), AreaOffY() );
231 }
232 #endif
233
InitPlayground()234 void TestHockey::InitPlayground() {
235 mdisc = new DiscMover( DiscRadius );
236 mdisc->Init();
237 DBG2(UnixTrace, "Hockey: Radius set back from %g to %g\n",
238 (double)DiscRadius, (double)mdisc->GetActRadius() );
239 DiscRadius = mdisc->GetActRadius();
240
241 InitTable();
242
243 disc = new Ball( Mid(3), DiscRadius, DiscWeight );
244 disc->state = new BallState( mdisc, disc_col, disc->P() );
245 disc->v = Vec2(shot_speed,RealZero);
246 }
247
248