1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: monst.cxx,v $
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"
35 #include "invader.hrc"
38 #include <vcl/outdev.hxx>
39 #include <tools/time.hxx>
41 Gegner::Gegner(Fighter
* pFig
, Bombe
* pBom
, ResMgr
* pRes
) :
61 pBitMonst1
= ImplLoadImage( MONSTER1
, pRes
);
62 pBitMonst2
= ImplLoadImage( MONSTER2
, pRes
);
63 pBitMonst3
= ImplLoadImage( MONSTER3
, pRes
);
64 pBitMonst4
= ImplLoadImage( MONSTER4
, pRes
);
65 pBitMonst1b
= ImplLoadImage( MONSTER1B
, pRes
);
66 pBitMonst2b
= ImplLoadImage( MONSTER2B
, pRes
);
67 pBitMonst3b
= ImplLoadImage( MONSTER3B
, pRes
);
68 pBitMonst4b
= ImplLoadImage( MONSTER4B
, pRes
);
69 pBitMonst5
= ImplLoadImage( MONSTER5
, pRes
);
70 pBitMonst5a
= ImplLoadImage( MONSTER5A
, pRes
);
71 pBitMonst5b
= ImplLoadImage( MONSTER5B
, pRes
);
73 aOutSize
= pBitMonst1
->GetSizePixel();
95 void Gegner::InsertGegner(long nType
, long x
, long y
)
97 Gegner_Impl
* pWork
= new Gegner_Impl();
99 pWork
->aType
= (enum GegnerType
)nType
;
100 pWork
->aMode
= MOVE1
;
101 pWork
->aXY
= Point(x
,y
);
115 pWork
->nPoints
= 150;
119 pWork
->nPoints
= 225;
123 pWork
->nPoints
= 500;
134 BOOL bNextDown
= FALSE
;
136 for(i
=0; i
<Count(); i
++)
140 SetGegnerPos(i
,Point(GegnerX(i
),GegnerY(i
)+nDown
));
145 SetGegnerPos(i
,Point(GegnerX(i
)+MOVEX
,GegnerY(i
)));
146 if(GegnerX(i
)+MOVEX
+aOutSize
.Width() > nMaxX
)
151 SetGegnerPos(i
,Point(GegnerX(i
)-MOVEX
,GegnerY(i
)));
152 if(GegnerX(i
)-MOVEX
<= 0)
171 void Gegner::DrawGegner(OutputDevice
* pDev
,Point
* pStart
)
175 srand(aTime
.GetTime() % 1000);
177 nMaxX
= pDev
->GetOutputSizePixel().Width()-pStart
->X();
179 for(i
=0; i
<Count();i
++)
184 if(GegMode(i
) == MOVE1
)
186 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
187 pStart
->Y()+GegnerY(i
)),*pBitMonst1
);
190 else if(GegMode(i
) == MOVE2
)
192 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
193 pStart
->Y()+GegnerY(i
)),*pBitMonst1b
);
198 if(GegMode(i
) == MOVE1
)
200 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
201 pStart
->Y()+GegnerY(i
)),*pBitMonst2
);
204 else if(GegMode(i
) == MOVE2
)
206 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
207 pStart
->Y()+GegnerY(i
)),*pBitMonst2b
);
212 if(GegMode(i
) == MOVE1
)
214 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
215 pStart
->Y()+GegnerY(i
)),*pBitMonst3
);
218 else if(GegMode(i
) == MOVE2
)
220 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
221 pStart
->Y()+GegnerY(i
)),*pBitMonst3b
);
226 if(GegMode(i
) == MOVE1
)
228 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
229 pStart
->Y()+GegnerY(i
)),*pBitMonst4
);
232 else if(GegMode(i
) == MOVE2
)
234 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
235 pStart
->Y()+GegnerY(i
)),*pBitMonst4b
);
240 if(GegMode(i
) == MOVE1
)
242 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
243 pStart
->Y()+GegnerY(i
)),*pBitMonst5
);
251 if(GegMode(i
) == MOVE2
)
253 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
254 pStart
->Y()+GegnerY(i
)),*pBitMonst5a
);
262 if(GegMode(i
) == MOVE3
)
264 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
265 pStart
->Y()+GegnerY(i
)),*pBitMonst5b
);
267 pBombe
->InsertBombe(Point(GegnerX(i
),
268 GegnerY(i
)+aOutSize
.Height()/2));
275 if(GegMode(i
) == MOVE4
)
277 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
278 pStart
->Y()+GegnerY(i
)),*pBitMonst5a
);
283 if ( rand() % 5 < 2 )
289 if(GegMode(i
) == MOVE5
)
291 pDev
->DrawImage(Point(pStart
->X()+GegnerX(i
),
292 pStart
->Y()+GegnerY(i
)),*pBitMonst5
);
296 if ( rand() % 5 < 2 )
309 SetKoll(i
,Rectangle(Point(GegnerX(i
)+KOLLXY
,GegnerY(i
)+KOLLXY
),
310 Point(GegnerX(i
)+aOutSize
.Width()-KOLLXY
,
311 GegnerY(i
)+aOutSize
.Height()-KOLLXY
)));
313 if(bAuseMode
&& GegMode(i
) == MOVE1
)
315 if(GegnerX(i
) < pFighter
->GetHalf() &&
316 GegnerX(i
)+aOutSize
.Width() > pFighter
->GetHalf())
317 pBombe
->InsertBombe(Point(pFighter
->GetPoint().X(),
318 GegnerY(i
)+aOutSize
.Height()/2));
325 // NOTE: the two expressions are the same in floatingpoint but not in integer
327 int nRandMax
= RAND_MAX
;
328 if ( nRandMax
< 32767 )
329 nScaledLimit
= GetRandWert() / ( 32767 / nRandMax
);
331 nScaledLimit
= GetRandWert() * ( nRandMax
/ 32767);
333 if(GegType(i
) != GEGNER5
)
335 if(ran
< nScaledLimit
)
336 pBombe
->InsertBombe(Point(GegnerX(i
),
337 GegnerY(i
)+aOutSize
.Height()/2));
339 else if(GegMode(i
) == HIDE
)
341 if(ran
< (nScaledLimit
*3) /2)
353 long Gegner::Kollision(Rectangle
& rRect
, Explosion
* pExpl
)
360 for( i
=0; i
<Count();i
++)
362 aWork
= GegnerKoll(i
);
363 if((aWork
.Left() <= rRect
.Left() && aWork
.Right() >= rRect
.Right()) &&
364 (aWork
.Top() <= rRect
.Top() && aWork
.Bottom() >= rRect
.Bottom()) &&
365 GegMode(i
) != DELETED
)
372 nWert
= GegnerPoints(i
);
374 nWert
+= GegnerPoints(i
);
377 pExpl
->InsertExpl(GegnerPos(i
));
385 BOOL
Gegner::GegnerDest(long nWert
)
388 if(GetObject(nWert
)->nHits
>= GetObject(nWert
)->nMaxHits
)
394 Rectangle
Gegner::GetKoll(long nWert
)
396 return Rectangle(Point(GegnerX(nWert
)+aOutSize
.Width()/2,
397 GegnerY(nWert
)+aOutSize
.Height()),
398 Point(GegnerX(nWert
)+aOutSize
.Width()/2,
399 GegnerY(nWert
)+aOutSize
.Height()));
402 BOOL
Gegner::RemoveGegner()
404 for(long i
=Count()-1; i
>=0; i
--)
406 Gegner_Impl
* pWork
= GetObject(i
);
408 if(pWork
->aMode
== DELETED
)
420 void Gegner::ClearAll()
423 for( i
=0; i
<Count(); i
++ )