merge the formfield patch from ooo-build
[ooovba.git] / goodies / source / inv / invader1.cxx
blob07f302ce45cd59b7d08846d29b3b63de04b138c2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: invader1.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_goodies.hxx"
33 #include <stdlib.h>
34 #include <vcl/msgbox.hxx>
35 #include <tools/datetime.hxx>
37 #include "invader.hxx"
38 #include "monst.hxx"
39 #include "shapes.hxx"
40 #include "expl.hxx"
41 #include "waves.hxx"
42 #include "score.hxx"
43 #include "strings.hrc"
46 void MyWindow::Kollision()
48 Rectangle aRect;
49 long nStart = nScore;
50 long nRockets = pMunition->Count();
52 long nWert;
54 unsigned long i;
55 for(i=0; i<pBombe->Count(); i++)
57 //Kollision Bombe->Mauer pr�fen
58 aRect = pBombe->GetKoll(i);
59 if(pWall->Kollision(aRect,FALSE))
60 pBombe->SetDelete(i);
61 //Kollision Bombe->Fighter pr�fen
62 if(pFighter->Kollision(pBombe->GetKoll(i),pExplosion))
64 bFightDest = TRUE;
65 pBombe->SetDelete(i);
69 for(i=0; i<pMunition->Count(); i++)
71 //Kollision Muniton->Gegner pr�fen
72 aRect = pMunition->GetKoll(i);
73 nWert = pGegner->Kollision(aRect,pExplosion);
74 if(nWert != -1)
76 nScore += nWert;
77 pMunition->SetDelete(i);
79 //Kollision Muniton->Mauer pr�fen
80 aRect = pMunition->GetKoll(i);
81 if(pWall->Kollision(aRect,FALSE))
82 pMunition->SetDelete(i);
84 //Kollision Munition->Bombe pr�fen
85 aRect = pMunition->GetKoll(i);
86 if(pBombe->Kollision(aRect,pExplosion))
87 pMunition->SetDelete(i);
90 for(i=0; i<pGegner->Count();i++)
93 //Kollision Gegner->Mauer pr�fen
94 aRect = pGegner->GetKoll(i);
95 pWall->Kollision(aRect,TRUE);
96 //Kollision Gegner->Fighter pr�fen
97 aRect = pGegner->GetKoll(i);
98 if(pFighter->Kollision(aRect,pExplosion))
100 bFightDest = TRUE;
101 pGegner->ClearAll();
102 pBombe->ClearAll();
107 pBombe->RemoveBomben();
108 nWert = pMunition->RemoveMunition();
109 if( nWert != nRockets)
110 pScoreWindow->SetRockets(nWert);
112 if(nScore > nStart)
113 pScoreWindow->SetScore(nScore);
115 if(pGegner->RemoveGegner())
117 bEndLevel = TRUE;
118 pBombe->ClearAll();
119 pMunition->ClearAll();
122 if(bFightDest)
124 pBombe->ClearAll();
125 pMunition->ClearAll();
126 pGegner->ClearAll();
129 if(pExplosion->RemoveExpl() && (bEndLevel || bFightDest))
131 if(!bWaitDlg)
132 aWaitDlgTimer.Start();
134 /*String aString;
135 if(!bFightDest)
137 aString = String(ResId(STR_GRAT1,GetResMgr()));
138 aString += String(nLevel);
139 aString += String(ResId(STR_GRAT2,GetResMgr()));
141 if(!pBox)
143 bWaitDlg = TRUE;
144 pBox = new MessBox(GetParent(),WinBits(WB_OK),String(ResId(STR_APP_TITLE,GetResMgr())),aString);
145 ProgStatus=FALSE;
146 SetBackground(Wallpaper( Color( COL_WHITE ) ) );
148 aWaitDlgTimer.Start();
149 return;
152 SetBackground();
153 ProgStatus=TRUE;
154 delete pBox;
155 pBox = 0L;
156 nLevel++;
157 GrabFocus();
159 else
161 nFighter--;
162 pScoreWindow->SetLives(nFighter);
163 if(nFighter > 0)
165 aString = String(ResId(STR_FIGHTDEST1,GetResMgr()));
166 aString += String(nFighter);
167 aString += String(ResId(STR_FIGHTDEST2,GetResMgr()));
169 else
171 aString = String(ResId(STR_GAMEOVER,GetResMgr()));
174 BOOL aDummyStatus;
176 if(!pBox)
178 pBox = new MessBox(this,WinBits(WB_OK),String(ResId(STR_APP_TITLE,GetResMgr())),aString);
179 aDummyStatus = ProgStatus;
180 //ProgStatus=FALSE;
181 SetBackground(Wallpaper( Color( COL_WHITE ) ) );
183 aWaitDlgTimer.Start();
185 return;
188 if(nFighter == 0)
190 ProgStatus = FALSE;
191 nLevel = 1;
192 nFighter = 3;
193 pGegner->SetRandWert(200);
194 pGegner->SetDown(10);
196 if(bTimeHigh)
197 nTimeOut = TIMEHIGH;
198 else
199 nTimeOut = TIMELOW;
202 SetBackground();
203 //ProgStatus=aDummyStatus;
204 delete pBox;
205 pBox = 0L;
206 GrabFocus();
208 if(!ProgStatus)
210 StartPhase = 1;
211 if (nScore > nHighScore)
213 String aString;
214 aString = String(ResId(STR_HIGHSCORE1,GetResMgr()));
215 aString += String(nScore);
216 aString += String(ResId(STR_HIGHSCORE2,GetResMgr()));
217 aString += String(nHighScore);
218 aString += String(ResId(STR_HIGHSCORE3,GetResMgr()));
219 nHighScore = nScore;
220 if(!pBox)
222 pBox = new MessBox(this,WinBits(WB_OK),String(ResId(STR_APP_TITLE,GetResMgr())),aString);
223 Paint(Rectangle(Point(0,0),Point(640,480)));
224 SetBackground(Wallpaper( Color( COL_WHITE ) ) );
226 aWaitDlgTimer.Start();
229 SetBackground();
230 delete pBox;
231 pBox = 0L;
232 GrabFocus();
234 nScore = 0;
239 InitLevel();*/
243 void MyWindow::InitLevel()
245 bStartLevel = TRUE;
246 long nWert;
248 aPaintTimer.SetTimeout(1000);
249 nStartLevel = 0;
250 pFighter->Init();
251 pMunition->ClearAll();
252 pBombe->ClearAll();
253 pWall->ClearAll();
254 pGegner->ClearAll();
255 bAuseModus = FALSE;
256 nAuseCount = 0;
257 pGegner->SetAuseMode(FALSE);
259 pScoreWindow->SetRockets(5);
260 pScoreWindow->SetLives(nFighter);
261 pScoreWindow->SetScore(nScore);
262 pScoreWindow->SetLevel(nLevel);
264 if(nLevel > 1)
266 pGegner->SetRandWert(pGegner->GetRandWert()+10);
267 nTimeOut -= 2;
268 if(nTimeOut <= 0)
269 nTimeOut = 1;
272 if(nLevel == 10 || nLevel == 20 || nLevel == 30 || nLevel >= 40)
274 pGegner->SetDown(pGegner->GetDown()+2);
275 if(pGegner->GetDown() > 30)
276 pGegner->SetDown(30);
279 nWert = nLevel;
280 while( nWert > WAVES )
281 nWert -= WAVES;
283 if(!( nLevel % 10 ))
285 if(!bGetFighter)
287 nFighter++;
288 pScoreWindow->SetLives(nFighter);
289 bGetFighter = TRUE;
292 else
293 bGetFighter = FALSE;
295 long nGegner;
296 long nDummy;
298 if(nLevel < WAVES*2)
300 nGegner = waves[nWert-1][0];
301 nDummy = nGegner;
302 for(long i=0; i<nGegner; i++)
303 if ( nLevel > 10 ) pGegner->InsertGegner((USHORT)waves[nWert-1][i*3+1],
304 (USHORT)waves[nWert-1][i*3+2],
305 (USHORT)waves[nWert-1][i*3+3]);
306 else if ( waves[nWert-1][i*3+1] < 4 ) pGegner->InsertGegner((USHORT)waves[nWert-1][i*3+1],
307 (USHORT)waves[nWert-1][i*3+2],
308 (USHORT)waves[nWert-1][i*3+3]);
309 else nDummy--;
313 else
315 if(levelpuf[0] != nLevel)
316 RandomLevel();
317 else
319 for(long i=0; i<levelpuf[1]; i++)
320 pGegner->InsertGegner(levelpuf[i*3+2],levelpuf[i*3+3],levelpuf[i*3+4]);
322 nGegner = levelpuf[1];
323 nDummy = nGegner;
326 BYTE nMauer;
327 Point aPoint;
329 if(nLevel < WAVES*2)
330 nMauer = (BYTE)waves[nWert-1][nGegner*3+1];
331 else
332 nMauer = 0xff;
333 if(nMauer & 0x01)
335 aPoint = Point(0,340);
336 pWall->InsertWall(aPoint);
338 if(nMauer & 0x02)
340 aPoint = Point(32,340);
341 pWall->InsertWall(aPoint);
343 if(nMauer & 0x04)
345 aPoint = Point(64,340);
346 pWall->InsertWall(aPoint);
348 if(nMauer & 0x08)
350 aPoint = Point(96,340);
351 pWall->InsertWall(aPoint);
353 if(nMauer & 0x10)
355 aPoint = Point(128,340);
356 pWall->InsertWall(aPoint);
358 if(nMauer & 0x20)
360 aPoint = Point(160,340);
361 pWall->InsertWall(aPoint);
363 if(nMauer & 0x40)
365 aPoint = Point(192,340);
366 pWall->InsertWall(aPoint);
368 if(nMauer & 0x80)
370 aPoint = Point(224,340);
371 pWall->InsertWall(aPoint);
373 if(nLevel < WAVES*2)
374 nMauer = (BYTE)waves[nWert-1][nGegner*3+2];
375 else
376 nMauer = 0xff;
377 if(nMauer & 0x01)
378 pWall->InsertWall(Point(256,340));
379 if(nMauer & 0x02)
380 pWall->InsertWall(Point(288,340));
381 if(nMauer & 0x04)
382 pWall->InsertWall(Point(320,340));
383 if(nMauer & 0x08)
384 pWall->InsertWall(Point(352,340));
385 if(nMauer & 0x10)
386 pWall->InsertWall(Point(384,340));
387 if(nMauer & 0x20)
388 pWall->InsertWall(Point(416,340));
389 if(nMauer & 0x40)
390 pWall->InsertWall(Point(448,340));
391 if(nMauer & 0x80)
392 pWall->InsertWall(Point(480,340));
393 if(nLevel < WAVES*2)
394 nMauer = (BYTE)waves[nWert-1][nGegner*3+3];
395 else
396 nMauer = 0xff;
397 if(nMauer & 0x01)
398 pWall->InsertWall(Point(512,340));
399 if(nMauer & 0x02)
400 pWall->InsertWall(Point(544,340));
401 if(nMauer & 0x04)
402 pWall->InsertWall(Point(576,340));
403 if(nMauer & 0x08)
404 pWall->InsertWall(Point(608,340));
406 nGegner = nDummy;
410 void MyWindow::RandomLevel()
412 Time aTime;
414 srand(aTime.GetTime() % 1000);
416 long nPos = ranpos[0];
417 while(!pGegner->Count())
419 for(long i=0; i<nPos ;i++)
422 int nRan = rand() % 40;
424 if(nRan < 3)
425 pGegner->InsertGegner(GEGNER5,ranpos[i*2+1],ranpos[i*2+2]);
426 if(nRan > 2 && nRan < 9)
427 pGegner->InsertGegner(GEGNER4,ranpos[i*2+1],ranpos[i*2+2]);
428 if(nRan > 8 && nRan < 16)
429 pGegner->InsertGegner(GEGNER3,ranpos[i*2+1],ranpos[i*2+2]);
430 if(nRan > 15 && nRan < 27)
431 pGegner->InsertGegner(GEGNER2,ranpos[i*2+1],ranpos[i*2+2]);
432 if(nRan > 26 && nRan < 41)
433 pGegner->InsertGegner(GEGNER1,ranpos[i*2+1],ranpos[i*2+2]);
437 levelpuf[0] = nLevel;
438 levelpuf[1] = pGegner->Count();
439 unsigned long i;
440 for(i=0; i<pGegner->Count(); i++)
442 levelpuf[i*3+2] = pGegner->GegType(i);
443 levelpuf[i*3+3] = pGegner->GegnerX(i);
444 levelpuf[i*3+4] = pGegner->GegnerY(i);