1 #ifndef _global_h
2 # include "global.h"
3 #endif
4
5 #ifndef _game_h
6 # include "game.h"
7 #endif
8 #ifndef _wall_h
9 # include "wall.h"
10 #endif
11 #ifndef _ball_h
12 # include "ball.h"
13 #endif
14 #ifndef _graph_h
15 # include "graph.h"
16 #endif
17 #ifndef _keeper_h
18 # include "keeper.h"
19 #endif
20
21 #ifdef DEBUG
22 # define SHOW_INFO
23 #endif
24
25
26 Game *g=0L; // globaler Zeiger auf das Spiel-Objekt
27
28
Game(double wx,double wy)29 Game::Game(double wx, double wy) {
30 x1=x2=0;
31 y1=y2=0;
32 keeper = 0;
33
34 InitGraphic(wx,wy);
35 floor = 0;
36 #ifdef TEST_STATIC_COLORS
37 AddStatColor( "Red" );
38 AddStatColor( "Magenta" );
39 AddStatColor( "Blue" );
40 AddStatColor( "Cyan" );
41 AddStatColor( "Green" );
42 AddStatColor( "Yellow" );
43 AddStatColor( "Red1" );
44 AddStatColor( "Magenta1" );
45 AddStatColor( "Blue1" );
46 AddStatColor( "Cyan1" );
47 AddStatColor( "Green1" );
48 AddStatColor( "Yellow1" );
49 AddStatColor( "Red2" );
50 AddStatColor( "Magenta2" );
51 AddStatColor( "Blue2" );
52 AddStatColor( "Cyan2" );
53 AddStatColor( "Green2" );
54 AddStatColor( "Yellow2" );
55 #endif
56 SetCursorColor( "PaleTurquoise" );
57
58 #ifdef __TURBOC__
59
60 unsigned size;
61
62 size = imagesize( getmaxx()/2, 8, getmaxx(), oy );
63 buffer = malloc(size);
64 if (!buffer) exit(-1);
65 #endif
66 running_balls=0;
67 }
68
~Game()69 Game::~Game() {
70 if (keeper) delete keeper;
71 if (x1) delete x1;
72 if (y1) delete y1;
73 if (x2) delete x2;
74 if (y2) delete y2;
75 }
76
GetPresetA()77 const Real & Game::GetPresetA() const { return PresetA; }
GetPresetHaft()78 const Real & Game::GetPresetHaft() const { return PresetHaft; }
GetSlowGranularity()79 const Real & Game::GetSlowGranularity() const { return SlowGranularity; }
GetNormalBallSize()80 const Real & Game::GetNormalBallSize() const { return NormalBallSize; }
81
GetChargeGranularity()82 const Real & Game::GetChargeGranularity() const { return ChargeGranularity; }
GetChargeSpeed()83 const Real & Game::GetChargeSpeed() const { return ChargeSpeed; }
GetMaxCharge()84 const Real & Game::GetMaxCharge() const { return MaxCharge; }
GetShootTime()85 const Real & Game::GetShootTime() const { return ShootTime; }
86
Edge(int i)87 Vec2 Game::Edge(int i) const {
88 switch(i&0x3) {
89 case 0: return Vec2(AreaOffX(), AreaOffY() );
90 case 1: return Vec2(AreaOffX()+AreaWidth(), AreaOffY() );
91 case 2: return Vec2(AreaOffX()+AreaWidth(), AreaOffY()+AreaHeight() );
92 default: return Vec2(AreaOffX(), AreaOffY()+AreaHeight() );
93 }
94 }
Mid(int i)95 Vec2 Game::Mid(int i) const {
96 switch(i&0x3) {
97 case 0: return Vec2(AreaOffX()+AreaWidth()/2.0, AreaOffY() );
98 case 1: return Vec2(AreaOffX()+AreaWidth(), AreaOffY()+AreaHeight()/2.0 );
99 case 2: return Vec2(AreaOffX()+AreaWidth()/2.0, AreaOffY()+AreaHeight() );
100 default: return Vec2(AreaOffX(), AreaOffY()+AreaHeight()/2.0 );
101 }
102 }
103
InitPlayground()104 void Game::InitPlayground() {
105 y1 = new YWall( 0.0, MaxX(), 0.0 );
106 x1 = new XWall( MaxX(), 0.0, MaxY() );
107 y2 = new YWall( 0.0, MaxX(), MaxY() );
108 x2 = new XWall( 0.0, 0.0, MaxY() );
109 // x2 = new XWall( 2.0, 0, MaxY() );
110 }
111
DrawBackground()112 void Game::DrawBackground() const {
113 #ifdef __TURBOC__
114 setfillstyle(SOLID_FILL,(int)GetAllocatedPixel("black"));
115 bar(0,0,getmaxx(),getmaxy());
116 #endif
117 SetBgColor( floor );
118 FillRectangle( 0.0, 0.0, MaxX(), MaxY() );
119
120 if (keeper) keeper->Draw();
121 }
122
ExposeRedraw()123 void Game::ExposeRedraw() const {
124 DrawBackground();
125 DynObj::ForAllDyn(&DynObj::Redraw);
126 }
127
ResizeRedraw()128 void Game::ResizeRedraw() const {
129 }
130
ShowInfo(char * str)131 void Game::ShowInfo( char *str ) const {
132 #ifndef __TURBOC__
133 printf( "%s\n", str );
134 #else
135
136 getimage( getmaxx()/2, 8, getmaxx(), oy, buffer );
137 putimage( getmaxx()/2, 0, buffer, COPY_PUT );
138 setfillstyle( SOLID_FILL, getbkcolor() );
139 bar(getmaxx()/2,oy-8,getmaxx(),oy-1);
140 outtextxy( getmaxx()/2, oy-8, str );
141 #endif
142 }
143
IsSelectable(Ball *)144 int Game::IsSelectable(Ball * /* b */) {
145 return 1;
146 }
147
ResetGame()148 void Game::ResetGame() {
149 if (keeper) keeper->GameWasReset();
150 }
151
152 #ifndef SHOW_INFO
153
ShootBall(Ball *)154 void Game::ShootBall( Ball * ) {}
PressedBall(Ball *)155 void Game::PressedBall( Ball * ) {}
TouchedBall(Ball *)156 void Game::TouchedBall( Ball * ) {}
HitWall(Ball *)157 void Game::HitWall( Ball * ) {}
StartBall(Ball *)158 void Game::StartBall( Ball * ) { running_balls++; }
StopBall(Ball *)159 void Game::StopBall( Ball * ) {
160 running_balls--;
161 if (!running_balls) AllBallsStopped();
162 }
InPocket(Ball *)163 void Game::InPocket( Ball * ) { ClickPocket(); }
AllBallsStopped()164 void Game::AllBallsStopped() {}
165
166 #else
167
ShootBall(Ball * b)168 void Game::ShootBall( Ball *b ) {
169 char buffer[30];
170
171 sprintf( buffer, "### ShootBall(%d)", b->Object::id );
172 ShowInfoIf(buffer);
173 }
174
PressedBall(Ball * b)175 void Game::PressedBall(Ball *b) {
176 char buffer[30];
177
178 sprintf( buffer, "... PressedBall(%d)", b->Object::id );
179 ShowInfoIf(buffer);
180 }
181
TouchedBall(Ball * b)182 void Game::TouchedBall(Ball *b) {
183 char buffer[30];
184
185 sprintf( buffer, "... TouchedBall(%d)", b->Object::id );
186 ShowInfoIf(buffer);
187 }
188
HitWall(Ball * b)189 void Game::HitWall(Ball *b) {
190 char buffer[30];
191
192 sprintf( buffer, "... HitWall(%d)", b->Object::id );
193 ShowInfoIf(buffer);
194 }
195
StartBall(Ball * b)196 void Game::StartBall( Ball *b ) {
197 char buffer[30];
198
199 sprintf( buffer, "... StartBall(%d)", b->Object::id );
200 ShowInfoIf(buffer);
201 running_balls++;
202 }
203
StopBall(Ball * b)204 void Game::StopBall( Ball *b ) {
205 char buffer[30];
206
207 sprintf( buffer, "... StopBall(%d)", b->Object::id );
208 ShowInfoIf(buffer);
209 running_balls--;
210 if (!running_balls) AllBallsStopped();
211 }
212
InPocket(Ball * b)213 void Game::InPocket( Ball *b ) {
214 char buffer[30];
215
216 sprintf( buffer, "### InPocket(%d)", b->Object::id );
217 ShowInfoIf(buffer);
218 ClickPocket();
219 }
220
AllBallsStopped()221 void Game::AllBallsStopped() {
222 ShowInfoIf("### AllBallsStopped");
223 }
224
225 #endif
226