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
Keeper(const Real & size_in,const Real & frame_in,ColorId frame_col_in,ColorId table_col_in)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
~Keeper()29 Keeper::~Keeper() {}
30
TakeOffBoard(Ball * b)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
IsOffBoard(Ball *)42 int Keeper::IsOffBoard(Ball * /*b*/) {
43 return 0;
44 }
45
GetBack(Ball * b)46 Ball *Keeper::GetBack(Ball *b) {
47 return b;
48 }
49
GameWasReset()50 void Keeper::GameWasReset() {
51 off_count = 0;
52 }
53
54 ///////////////////////////////////////////////////////////
55
56 extern double world_x, world_y;
57
58 //
59 // Klasse LinePocket - Objekte werden in Zeile am unteren Bildrand geworfen
60 //
61
LineKeeper(const Real & height,const Real & frame,ColorId frame_col,ColorId table_col,int mode_in)62 LineKeeper::LineKeeper(const Real &height, const Real &frame, ColorId frame_col, ColorId table_col, int mode_in) : Keeper(height,frame,frame_col, table_col)
63 {
64 Real ypos=(mode_in&UPPER_FLAG)?0.0:(double)(MaxY()-size);
65
66 mode = mode_in;
67 if (mode&CLOSE_LEFT) {
68 wall1 = new Wall(frame,ypos,frame,ypos+size);
69 }
70 else wall1 = 0;
71 if (mode&CLOSE_RIGHT) {
72 wall2 = new Wall(MaxX()-frame,ypos,MaxX()-frame,ypos+size);
73 }
74 else wall2 = 0;
75 }
76
~LineKeeper()77 LineKeeper::~LineKeeper()
78 {
79 if (wall1) delete wall1;
80 if (wall2) delete wall2;
81 }
82
Draw()83 void LineKeeper::Draw() {
84
85 if (mode&UPPER_FLAG) {
86 SetBgColor(table_col);
87 FillRectangle( 0.0, 0.0, MaxX(), size );
88 SetBgColor(frame_col);
89 FillRectangle( 0.0, 0.0, MaxX(), frame );
90 FillRectangle( 0.0, size-frame, MaxX(), frame );
91 if (mode&CLOSE_LEFT)
92 FillRectangle( 0.0, 0.0, frame, size);
93 if (mode&CLOSE_RIGHT)
94 FillRectangle( MaxX()-frame, 0.0, frame, size);
95 }
96 else {
97 SetBgColor(table_col);
98 FillRectangle( 0.0, MaxY()-size, MaxX(), size );
99 SetBgColor(frame_col);
100 FillRectangle( 0.0, MaxY()-size, MaxX(), frame );
101 FillRectangle( 0.0, MaxY()-frame, MaxX(), frame );
102 if (mode&CLOSE_LEFT)
103 FillRectangle( 0.0, MaxY()-size, frame, size);
104 if (mode&CLOSE_RIGHT)
105 FillRectangle( MaxX()-frame, MaxY()-size, frame, size);
106 }
107 }
108
PlaceOffBoard(Ball * b)109 void LineKeeper::PlaceOffBoard( Ball *b ) {
110 Real to; // Endpunkt f�r aktuelle Kugel in der Pocketline
111 Real from; // Startpunkt f�r aktuelle Kugel in der Pocketline
112 Real vx; // Startgeschwindigkeit, damit Kugel in Punkt to liegenbleibt
113
114 to = Real((off_count*2+1))*g->GetNormalBallSize()+frame;
115 // from = world_x - Real(40-off_count*2)*g->GetNormalBallSize();
116 from = world_x - 2.0*g->GetNormalBallSize();
117 vx = sqrt( 2.*fabs((to-from)*b->a) );
118
119 b->p = Vec2( from, world_y-size/2. );
120 b->SetV( Vec2(-vx,RealZero) );
121 }
122
123 //
124 // Klasse StackKeeper - Objekte werden in Zeile am rechten Bildrand geworfen
125 //
126
StackKeeper(const Real & width,const Real & frame,ColorId frame_col,ColorId table_col,int mode_in)127 StackKeeper::StackKeeper(const Real &width, const Real &frame, ColorId frame_col, ColorId table_col,int mode_in) : Keeper(width,frame,frame_col,table_col)
128 {
129 Real xpos=(mode_in&LEFT_FLAG)?0.0:(double)(MaxX()-size);
130
131 mode = mode_in;
132 if (mode&CLOSE_TOP) {
133 wall1 = new Wall(xpos,frame,xpos+size,frame);
134 }
135 else wall1 = 0;
136 if (mode&CLOSE_BOT) {
137 wall2 = new Wall(xpos,MaxY()-frame,xpos+size,MaxY()-frame);
138 }
139 else wall2 = 0;
140 }
141
~StackKeeper()142 StackKeeper::~StackKeeper()
143 {
144 if (wall1) delete wall1;
145 if (wall2) delete wall2;
146 }
147
Draw()148 void StackKeeper::Draw() {
149 if (mode&LEFT_FLAG) {
150 SetBgColor(table_col);
151 FillRectangle( 0.0, 0.0, size, MaxY() );
152 SetBgColor(frame_col);
153 FillRectangle( 0.0, 0.0, frame, MaxY() );
154 FillRectangle( size-frame,0.0, frame, MaxY() );
155 if (mode&CLOSE_TOP)
156 FillRectangle( 0.0, 0.0, size, frame);
157 if (mode&CLOSE_BOT)
158 FillRectangle( 0.0, MaxY()-frame, size, frame);
159 }
160 else {
161 SetBgColor(table_col);
162 FillRectangle( MaxX()-size, 0.0, size, MaxY() );
163 SetBgColor(frame_col);
164 FillRectangle( MaxX()-size, 0.0, frame, MaxY() );
165 FillRectangle( MaxX()-frame,0.0, frame, MaxY() );
166 if (mode&CLOSE_TOP)
167 FillRectangle( MaxX()-size, 0.0, size, frame);
168 if (mode&CLOSE_BOT)
169 FillRectangle( MaxX()-size, MaxY()-frame, size, frame);
170 }
171 }
172
PlaceOffBoard(Ball * b)173 void StackKeeper::PlaceOffBoard( Ball *b ) {
174 Real to; // Endpunkt f�r aktuelle Kugel in der Pocketline
175 Real from; // Startpunkt f�r aktuelle Kugel in der Pocketline
176 Real vy; // Startgeschwindigkeit, damit Kugel in Punkt to liegenbleibt
177
178 to = world_y - (Real(off_count*2+1)*g->GetNormalBallSize()+frame);
179 from = Real(40-off_count*2)*g->GetNormalBallSize();
180 vy = sqrt( fabs((to-from)*b->a) );
181
182 b->p = Vec2( world_x-size/2., from );
183 b->SetV( Vec2(RealZero,vy) );
184 }
185
186