1/*
2 Copyright (C) 1998-2001 Andreas Zehender <az@azweb.de>
3
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16*/
17
18#ifndef __MY_MAIN_VIEW_H
19#define __MY_MAIN_VIEW_H
20
21#include <QGraphicsScene>
22#include <QGraphicsView>
23#include <QList>
24#include <QTimerEvent>
25#include <QWidget>
26
27
28#include <krandomsequence.h>
29class KToggleAction;
30class KActionCollection;
31class QGraphicsSimpleTextItem;
32
33#include "dialogs.h"
34#include "sprites.h"
35class Ai;
36
37#ifdef sun
38#undef sun
39#endif
40
41class MyMainView:public QWidget
42{
43 Q_OBJECT
44public:
45 explicit MyMainView(QWidget *parent=0);
46 ~MyMainView();
47
48 static KToggleAction *pauseAction;
49 void setActionCollection(KActionCollection *a);
50
51public slots:
52 void newRound();
53 void newGame();
54 void togglePause( );
55 void pause();
56 void resume();
57 void start();
58 void stop();
59 void gameSetup();
60 void closeSettings();
61 void readConfig();
62 void writeConfig();
63signals:
64 void hitPoints(int pn,int hp);
65 void energy(int pn,int en);
66 void wins(int pn,int w);
67 void setStatusText(const QString & str,int id);
68
69protected:
70 virtual void resizeEvent(QResizeEvent *event);
71 virtual void timerEvent(QTimerEvent *event);
72 virtual void keyPressEvent(QKeyEvent *event);
73 virtual void keyReleaseEvent(QKeyEvent *event);
74 virtual void focusOutEvent (QFocusEvent * /*event*/);
75 bool readSprites();
76 SConfig modifyConfig(SConfig conf);
77 void moveShips();
78 void moveBullets();
79 void moveMines();
80 void moveExplosions();
81 void calculatePowerups();
82 void collisions();
83private:
84 KActionCollection *actionCollection;
85
86 QGraphicsScene field;
87 QGraphicsView view;
88
89 SConfig customConfig,config;
90
91 int timerID;
92 bool playerKeyPressed[2][PlayerKeyNum];
93 bool bulletShot[2];
94 bool minePut[2];
95 bool waitForStart;
96 double gameEnd;
97 double timeToNextPowerup;
98
99// SVG sprites
100 QSvgRenderer* svgrender;
101 // This could probably be gotten rid of, but it'll be kind of a pain
102 QString powerupelements[PowerupSprite::PowerupNum];
103
104 QMap<int, QList<QString> > animation;
105
106 ShipSprite *ship[2];
107 SunSprite *sun;
108 QGraphicsSimpleTextItem *textSprite;
109
110 QList<BulletSprite*> *bullets[2];
111 QList<MineSprite*> *mines[2];
112 QList<ExplosionSprite*> explosions;
113 QList<PowerupSprite*> powerups;
114
115 KRandomSequence random;
116
117//Ai
118 Ai *ai[2];
119
120};
121
122#endif
123