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: invader.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"
33 #include "invader.hxx"
37 #include "invader.hrc"
38 #include "strings.hrc"
40 #include <svtools/solar.hrc>
41 #include <cppuhelper/servicefactory.hxx>
42 #include <comphelper/processfactory.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <vcl/virdev.hxx>
46 MyWindow::MyWindow(Window
* pParent
, ResMgr
*pResMgr
) :
47 FloatingWindow(pParent
, WB_3DLOOK
| WB_CLOSEABLE
| WB_MOVEABLE
),
79 pBitWelcome2
= ImplLoadImage( WELCOME2
, GetResMgr() );
80 pBitHeros
= ImplLoadImage( HEROS
, GetResMgr() );
81 pBitStarWars
= ImplLoadImage( STARWARS
, GetResMgr() );
82 pBombe
= new Bombe(GetResMgr());
83 pMunition
= new Munition(GetResMgr());
84 pExplosion
= new Explosion(GetResMgr());
85 pWall
= new Wall(GetResMgr());
86 pScoreWindow
= new ScoreWindow(this,WB_BORDER
, GetResMgr());
87 pPauseWindow
= new Window(this, 0);
89 SetOutputSizePixel(Size(WINWIDTH
,WINHEIGHT
));
90 SetText(String(ResId(STR_APP_TITLE
,*GetResMgr())));
92 pPauseWindow
->SetPosSizePixel(Point(100,190),Size(500,50));
93 pPauseWindow
->SetBackground();
95 pScoreWindow
->SetPosSizePixel(Point(0,0),Size(WINWIDTH
,22));
96 Size
aSize(WINWIDTH
,WINHEIGHT
);
97 pFighter
= new Fighter(aSize
, GetResMgr());
98 pGegner
= new Gegner(pFighter
, pBombe
, GetResMgr());
100 pVirtualDevice
= new VirtualDevice(*this);
101 pVirtualDevice
->SetOutputSizePixel(Size( WINWIDTH
, WINHEIGHT
));
105 aPaintTimer
= Timer();
106 aPaintTimer
.SetTimeoutHdl(LINK(this, MyWindow
, PaintTimer
));
107 aPaintTimer
.SetTimeout(nTimeOut
);
110 aWaitDlgTimer
= Timer();
111 aWaitDlgTimer
.SetTimeoutHdl(LINK(this, MyWindow
, StartDlgTimer
));
112 aWaitDlgTimer
.SetTimeout(10);
113 aWaitDlgTimer
.Stop();
115 aPointer
= GetPointer();
121 MyWindow::~MyWindow()
124 delete pVirtualDevice
;
138 void MyWindow::Paint(const Rectangle
&)
143 Size aVSize
= pVirtualDevice
->GetOutputSizePixel();
149 pScoreWindow
->Hide();
150 bMouseMooving
= FALSE
;
152 if( StartPhase
== 1 )
154 const Font
aOldFont( GetFont() );
155 Font
aFont( aOldFont
);
157 SetFillColor( COL_BLACK
);
158 DrawRect(Rectangle(Point(0,0),Point(640,480)));
160 DrawImage(Point(55,78), *pBitStarWars
);
161 DrawImage(Point(53,207), *pBitHeros
);
162 DrawImage(Point(470,400), *(pFighter
->pFight1
));
163 DrawImage(Point(460,290), *(pMunition
->pMunition1
));
164 DrawImage(Point(480,320), *(pMunition
->pMunition1
));
165 DrawImage(Point(470,250), *(pMunition
->pMunition1
));
167 aFont
.SetColor(COL_WHITE
);
168 aFont
.SetFillColor(COL_BLACK
);
171 DrawText(Point(175,170),String(ResId(STR_CHOOSEHERO
, *GetResMgr())));
172 DrawText(Point(98,208),String(ResId(STR_NAME1
, *GetResMgr())));
173 DrawText(Point(98,252),String(ResId(STR_NAME2
, *GetResMgr())));
174 DrawText(Point(98,296),String(ResId(STR_NAME3
, *GetResMgr())));
175 DrawText(Point(98,340),String(ResId(STR_NAME4
, *GetResMgr())));
176 DrawText(Point(98,384),String(ResId(STR_NAME5
, *GetResMgr())));
180 else if(StartPhase
== 2)
182 SetFillColor( COL_WHITE
);
183 DrawRect(Rectangle(Point(0,0),Point(640,480)));
184 DrawImage(Point(19,147), *pBitWelcome2
);
194 pVirtualDevice
->SetFillColor( COL_WHITE
);
195 pVirtualDevice
->SetLineColor();
196 pVirtualDevice
->DrawRect(Rectangle(Point(0,0), Point(aVSize
.Width(),aVSize
.Height())));
200 if ((bMouseMooving
)&&(nDirection
> pFighter
->GetPoint().X()+32))
204 pGegner
->SetAuseMode(FALSE
);
207 else if ((bMouseMooving
)&&(nDirection
< pFighter
->GetPoint().X()))
211 pGegner
->SetAuseMode(FALSE
);
215 if(nAuseCount
> AUSEMODE
)
216 pGegner
->SetAuseMode(TRUE
);
217 pWall
->Paint(*pVirtualDevice
);
218 pGegner
->DrawGegner(pVirtualDevice
,&aPoint
);
219 pFighter
->Paint(*pVirtualDevice
);
220 pMunition
->Paint(*pVirtualDevice
);
221 pBombe
->Paint(*pVirtualDevice
);
222 pExplosion
->Paint(*pVirtualDevice
);
226 bMouseMooving
= FALSE
;
227 Font aOldFont
= pVirtualDevice
->GetFont();
228 Font aFont
= aOldFont
;
232 aFont
.SetColor(COL_RED
);
235 aFont
.SetColor(COL_YELLOW
);
238 aFont
.SetColor(COL_GREEN
);
241 pVirtualDevice
->SetFont(*&aFont
);
242 String aString
= String(ResId(STR_LEVELSTART
, *GetResMgr()));
244 aString
+= String::CreateFromInt32(nLevel
);
246 pVirtualDevice
->DrawText(Point(LEVELTEXTX
,LEVELTEXTY
),aString
);
253 aPaintTimer
.SetTimeout(nTimeOut
);
255 pVirtualDevice
->SetFont(*&aOldFont
);
259 DrawOutDev( Point( 0, 22), aVSize
, Point( 0, 22), aVSize
, *pVirtualDevice
);
264 else pPauseWindow
->DrawText(Point(20,20),String(ResId(STR_PAUSE
, *GetResMgr())));
267 void MyWindow::KeyInput( const KeyEvent
& rKEvent
)
269 if(bEndLevel
|| bFightDest
)
271 rKEvent
.GetKeyCode().GetCode();
272 FloatingWindow::KeyInput(rKEvent
);
277 bMouseMooving
= FALSE
;
278 switch(rKEvent
.GetKeyCode().GetCode())
283 pGegner
->SetAuseMode(FALSE
);
288 pGegner
->SetAuseMode(FALSE
);
291 pMunition
->Start(pFighter
->GetPoint());
306 aPaintTimer
.SetTimeout(nTimeOut
);
312 aPaintTimer
.SetTimeout(nTimeOut
);
320 aPaintTimer
.SetTimeout(nTimeOut
);
331 pPauseWindow
->Hide();
337 SetBackground( Wallpaper( COL_WHITE
) );
338 pPauseWindow
->Show();
339 pPauseWindow
->DrawText(Point(20,20),String(ResId(STR_PAUSE
, *GetResMgr())));
343 FloatingWindow::KeyInput(rKEvent
);
347 IMPL_LINK( MyWindow
, PaintTimer
, Timer
*, EMPTYARG
)
355 IMPL_LINK( MyWindow
, StartDlgTimer
, Timer
*, EMPTYARG
)
359 aWaitDlgTimer
.Stop();
364 aString
= String(ResId(STR_GRAT1
,*GetResMgr()));
365 aString
+= String::CreateFromInt32(nLevel
);
366 aString
+= String(ResId(STR_GRAT2
,*GetResMgr()));
368 pBox
= new MessBox(this,WinBits(WB_OK
),String(ResId(STR_APP_TITLE
,*GetResMgr())),aString
);
371 SetBackground(Wallpaper( Color( COL_WHITE
) ) );
384 pScoreWindow
->SetLives(nFighter
);
387 aString
= String(ResId(STR_FIGHTDEST1
,*GetResMgr()));
388 aString
+= String::CreateFromInt32(nFighter
);
389 aString
+= String(ResId(STR_FIGHTDEST2
,*GetResMgr()));
393 aString
= String(ResId(STR_GAMEOVER
,*GetResMgr()));
397 pGegner
->SetRandWert(200);
398 pGegner
->SetDown(10);
406 pBox
= new MessBox(this,WinBits(WB_OK
),String(ResId(STR_APP_TITLE
,*GetResMgr())),aString
);
408 BOOL aDummyStatus
= ProgStatus
;
410 SetBackground(Wallpaper( Color( COL_WHITE
) ) );
415 ProgStatus
=aDummyStatus
;
422 if (nScore
> nHighScore
)
425 aHSString
= String(ResId(STR_HIGHSCORE1
,*GetResMgr()));
426 aHSString
+= String::CreateFromInt32(nScore
);
427 aHSString
+= String(ResId(STR_HIGHSCORE2
,*GetResMgr()));
428 aHSString
+= String::CreateFromInt32(nHighScore
);
429 aHSString
+= String(ResId(STR_HIGHSCORE3
,*GetResMgr()));
431 pBox
= new MessBox(this,WinBits(WB_OK
),String(ResId(STR_APP_TITLE
,*GetResMgr())),aHSString
);
433 Paint(Rectangle(Point(0,0),Point(640,480)));
434 SetBackground(Wallpaper( Color( COL_WHITE
) ) );
453 void MyWindow::MouseButtonDown(const MouseEvent
& rMEvt
)
455 MessBox
* pMessBox
= 0L;
463 if ((rMEvt
.GetPosPixel().X() >= 57) && (rMEvt
.GetPosPixel().X() <=90))
465 if ((rMEvt
.GetPosPixel().Y() >= 211) && (rMEvt
.GetPosPixel().Y() <= 244))
467 else if ((rMEvt
.GetPosPixel().Y() >= 255) && (rMEvt
.GetPosPixel().Y() <= 288))
469 else if ((rMEvt
.GetPosPixel().Y() >= 299) && (rMEvt
.GetPosPixel().Y() <= 332))
471 else if ((rMEvt
.GetPosPixel().Y() >= 343) && (rMEvt
.GetPosPixel().Y() <= 376))
473 else if ((rMEvt
.GetPosPixel().Y() >= 387) && (rMEvt
.GetPosPixel().Y() <= 420))
478 SetPointer(aPointer
);
483 pMessBox
= new MessBox(this,WinBits(WB_OK
),String(ResId(STR_APP_TITLE
,*GetResMgr())),String(ResId(STR_HERO1
, *GetResMgr())));
488 pMessBox
= new MessBox(this,WinBits(WB_OK
),String(ResId(STR_APP_TITLE
,*GetResMgr())), String(ResId(STR_HERO2
, *GetResMgr())));
493 pMessBox
= new MessBox(this,WinBits(WB_OK
),String(ResId(STR_APP_TITLE
,*GetResMgr())), String(ResId(STR_HERO3
, *GetResMgr())));
498 pMessBox
= new MessBox(this,WinBits(WB_OK
),String(ResId(STR_APP_TITLE
,*GetResMgr())), String(ResId(STR_HERO4
, *GetResMgr())));
503 pMessBox
= new MessBox(this,WinBits(WB_OK
),String(ResId(STR_APP_TITLE
,*GetResMgr())), String(ResId(STR_HERO5
, *GetResMgr())));
507 PlaceDialog(pMessBox
);
511 pScoreWindow
->SetHero(TheHero
);
515 else if (StartPhase
== 2)
519 pScoreWindow
->ShowMe();
527 if((!bStartLevel
) && (!bPause
))
528 pMunition
->Start(pFighter
->GetPoint());
532 void MyWindow::MouseMove(const MouseEvent
& rMEvt
)
536 if ((!ProgStatus
) && ( StartPhase
== 1 ))
539 if ((rMEvt
.GetPosPixel().X() >= 57) && (rMEvt
.GetPosPixel().X() <=90))
541 if ((rMEvt
.GetPosPixel().Y() >= 211) && (rMEvt
.GetPosPixel().Y() <= 244))
543 else if ((rMEvt
.GetPosPixel().Y() >= 255) && (rMEvt
.GetPosPixel().Y() <= 288))
545 else if ((rMEvt
.GetPosPixel().Y() >= 299) && (rMEvt
.GetPosPixel().Y() <= 332))
547 else if ((rMEvt
.GetPosPixel().Y() >= 343) && (rMEvt
.GetPosPixel().Y() <= 376))
549 else if ((rMEvt
.GetPosPixel().Y() >= 387) && (rMEvt
.GetPosPixel().Y() <= 420))
552 if ((Hero
) && (GetPointer() != POINTER_REFHAND
)) SetPointer(POINTER_REFHAND
);
553 else if ((!Hero
) && (GetPointer() != aPointer
)) SetPointer(aPointer
);
555 else if ( ProgStatus
)
557 nDirection
= rMEvt
.GetPosPixel().X();
558 bMouseMooving
= TRUE
;
562 BOOL
MyWindow::Close()
566 pApplication
->Quit();
574 void MyWindow::PlaceDialog(MessBox
* pMessBox
)
578 Point aPos
= GetPosPixel();
579 Size aSize
= GetSizePixel();
580 Size aBoxSize
= pMessBox
->GetOutputSizePixel();
581 aSize
= Size(aSize
.Width()/2 - aBoxSize
.Width()/2,
582 aSize
.Height()/2 - aBoxSize
.Height()/2);
583 pMessBox
->SetPosPixel(
584 Point(aPos
.X()+aSize
.Width(),aPos
.Y()+aSize
.Height()));
591 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>
592 xMSF
= cppu::createRegistryServiceFactory(
593 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "applicat.rdb" ) ), sal_True
);
595 ::comphelper::setProcessServiceFactory( xMSF
);
597 ByteString aRes
= "tfu";
598 ResMgr
*pMyResMgr
= ResMgr::CreateResMgr(aRes
.GetBuffer());
600 MyWindow
aWindow( NULL
, pMyResMgr
);
603 aWindow
.setApplication(this);
615 extern "C" void __cdecl
StartInvader(Window
* pParent
, ResMgr
* pRes
)
617 extern "C" void StartInvader(Window
* pParent
, ResMgr
* pRes
)
620 MyWindow
*pInvaderWin
= new MyWindow(pParent
, pRes
);