File: keeper.C

package info (click to toggle)
flying 6.20-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 752 kB
  • ctags: 1,873
  • sloc: cpp: 10,966; makefile: 189
file content (185 lines) | stat: -rw-r--r-- 4,684 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#ifndef _global_h
#	include "global.h"
#endif

#ifndef _ball_h
#	include "ball.h"
#endif
#ifndef _wall_h
#	include "wall.h"
#endif
#ifndef _keeper_h
#	include "keeper.h"
#endif
#ifndef _game_h
#	include "game.h"
#endif
#ifndef _graph_h
#	include "graph.h"
#endif

Keeper::Keeper(const Real &size_in, const Real &frame_in, ColorId frame_col_in, ColorId table_col_in) {
	size  = size_in;
	frame = frame_in;
	frame_col = frame_col_in;
	table_col = table_col_in;
	off_count = 0;
}

Keeper::~Keeper() {}

void Keeper::TakeOffBoard(Ball *b) {
	b->Draw();		// Ball an aktueller Position l�schen
	b->GoUnlocked();
	g->InPocket(b);

	PlaceOffBoard(b);

	off_count++;
	b->Draw();		// Ball an neuer Position setzen
}

int Keeper::IsOffBoard(Ball * /*b*/) {
	return 0;
}

Ball *Keeper::GetBack(Ball *b) {
	return b;
}

void Keeper::GameWasReset() {
	off_count = 0;
}

///////////////////////////////////////////////////////////

extern double	world_x, world_y;

//
// Klasse LinePocket -  Objekte werden in Zeile am unteren Bildrand geworfen
//

LineKeeper::LineKeeper(const Real &height, const Real &frame, ColorId frame_col, ColorId table_col, int mode_in) : Keeper(height,frame,frame_col, table_col)
{
Real	ypos=(mode_in&UPPER_FLAG)?0.0:(double)(MaxY()-size);

	mode = mode_in;
	if (mode&CLOSE_LEFT) {
			wall1 = new Wall(frame,ypos,frame,ypos+size);
	}
	else	wall1 = 0;
	if (mode&CLOSE_RIGHT) {
			wall2 = new Wall(MaxX()-frame,ypos,MaxX()-frame,ypos+size);
	}
	else	wall2 = 0;
}

LineKeeper::~LineKeeper()
{
	if (wall1)	delete wall1;
	if (wall2)	delete wall2;
}

void LineKeeper::Draw() {

	if (mode&UPPER_FLAG) {
		SetBgColor(table_col);
		FillRectangle( 0.0, 0.0, MaxX(), size );
		SetBgColor(frame_col);
		FillRectangle( 0.0, 0.0,  MaxX(), frame );
		FillRectangle( 0.0, size-frame, MaxX(), frame );
		if (mode&CLOSE_LEFT)
				FillRectangle( 0.0, 0.0,  frame, size);
		if (mode&CLOSE_RIGHT)
				FillRectangle( MaxX()-frame, 0.0,  frame, size);
	}
	else {
		SetBgColor(table_col);
		FillRectangle( 0.0, MaxY()-size, MaxX(), size );
		SetBgColor(frame_col);
		FillRectangle( 0.0, MaxY()-size,  MaxX(), frame );
		FillRectangle( 0.0, MaxY()-frame, MaxX(), frame );
		if (mode&CLOSE_LEFT)
				FillRectangle( 0.0, MaxY()-size,  frame, size);
		if (mode&CLOSE_RIGHT)
				FillRectangle( MaxX()-frame, MaxY()-size,  frame, size);
	}
}

void LineKeeper::PlaceOffBoard( Ball *b ) {
Real	to;		// Endpunkt f�r aktuelle Kugel in der Pocketline
Real	from;		// Startpunkt f�r aktuelle Kugel in der Pocketline
Real	vx;		// Startgeschwindigkeit, damit Kugel in Punkt to liegenbleibt

	to		= Real((off_count*2+1))*g->GetNormalBallSize()+frame;
//	from	= world_x - Real(40-off_count*2)*g->GetNormalBallSize();
	from  = world_x - 2.0*g->GetNormalBallSize();
	vx		= sqrt( 2.*fabs((to-from)*b->a) );

	b->p = Vec2( from, world_y-size/2. );
	b->SetV( Vec2(-vx,RealZero) );
}

//
// Klasse StackKeeper -  Objekte werden in Zeile am rechten Bildrand geworfen
//

StackKeeper::StackKeeper(const Real &width, const Real &frame, ColorId frame_col, ColorId table_col,int mode_in) : Keeper(width,frame,frame_col,table_col)
{
Real	xpos=(mode_in&LEFT_FLAG)?0.0:(double)(MaxX()-size);

	mode = mode_in;
	if (mode&CLOSE_TOP) {
			wall1 = new Wall(xpos,frame,xpos+size,frame);
	}
	else	wall1 = 0;
	if (mode&CLOSE_BOT) {
			wall2 = new Wall(xpos,MaxY()-frame,xpos+size,MaxY()-frame);
	}
	else	wall2 = 0;
}

StackKeeper::~StackKeeper()
{
	if (wall1)		delete wall1;
	if (wall2)		delete wall2;
}

void StackKeeper::Draw() {
	if (mode&LEFT_FLAG) {
		SetBgColor(table_col);
		FillRectangle( 0.0, 0.0, size,  MaxY() );
		SetBgColor(frame_col);
		FillRectangle( 0.0, 0.0, frame, MaxY() );
		FillRectangle( size-frame,0.0, frame, MaxY() );
		if (mode&CLOSE_TOP)
				FillRectangle( 0.0, 0.0,  size, frame);
		if (mode&CLOSE_BOT)
				FillRectangle( 0.0, MaxY()-frame, size, frame);
	}
	else {
		SetBgColor(table_col);
		FillRectangle( MaxX()-size, 0.0, size,  MaxY() );
		SetBgColor(frame_col);
		FillRectangle( MaxX()-size, 0.0, frame, MaxY() );
		FillRectangle( MaxX()-frame,0.0, frame, MaxY() );
		if (mode&CLOSE_TOP)
				FillRectangle( MaxX()-size, 0.0,  size, frame);
		if (mode&CLOSE_BOT)
				FillRectangle( MaxX()-size, MaxY()-frame, size, frame);
	}
}

void StackKeeper::PlaceOffBoard( Ball *b ) {
Real	to;		// Endpunkt f�r aktuelle Kugel in der Pocketline
Real	from;		// Startpunkt f�r aktuelle Kugel in der Pocketline
Real	vy;		// Startgeschwindigkeit, damit Kugel in Punkt to liegenbleibt

	to		= world_y - (Real(off_count*2+1)*g->GetNormalBallSize()+frame);
	from	= Real(40-off_count*2)*g->GetNormalBallSize();
	vy		= sqrt( fabs((to-from)*b->a) );

	b->p = Vec2( world_x-size/2., from );
	b->SetV( Vec2(RealZero,vy) );
}