1 /* 2 SPDX-FileCopyrightText: 1998-2001 Andreas Zehender <az@azweb.de> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #ifndef __MY_MAIN_VIEW_H 8 #define __MY_MAIN_VIEW_H 9 10 #include <QGraphicsScene> 11 #include <QGraphicsView> 12 #include <QList> 13 #include <QRandomGenerator> 14 #include <QTimerEvent> 15 #include <QWidget> 16 17 18 class KToggleAction; 19 class KActionCollection; 20 class QGraphicsSimpleTextItem; 21 22 #include "dialogs.h" 23 #include "sprites.h" 24 class Ai; 25 26 #ifdef sun 27 #undef sun 28 #endif 29 30 class MyMainView:public QWidget 31 { 32 Q_OBJECT 33 public: 34 explicit MyMainView(QWidget *parent = nullptr); 35 ~MyMainView() override; 36 37 static KToggleAction *pauseAction; 38 void setActionCollection(KActionCollection *a); 39 40 public Q_SLOTS: 41 void newRound(); 42 void newGame(); 43 void togglePause( ); 44 void pause(); 45 void resume(); 46 void start(); 47 void stop(); 48 void gameSetup(); 49 void closeSettings(); 50 void readConfig(); 51 void writeConfig(); 52 Q_SIGNALS: 53 void hitPoints(int pn,int hp); 54 void energy(int pn,int en); 55 void wins(int pn,int w); 56 void setStatusText(const QString & str,int id); 57 58 protected: 59 void resizeEvent(QResizeEvent *event) override; 60 void timerEvent(QTimerEvent *event) override; 61 void keyPressEvent(QKeyEvent *event) override; 62 void keyReleaseEvent(QKeyEvent *event) override; 63 void focusOutEvent (QFocusEvent * /*event*/) override; 64 bool readSprites(); 65 SConfig modifyConfig(const SConfig &conf); 66 void moveShips(); 67 void moveBullets(); 68 void moveMines(); 69 void moveExplosions(); 70 void calculatePowerups(); 71 void collisions(); 72 private: 73 KActionCollection *actionCollection; 74 75 QGraphicsScene field; 76 QGraphicsView view; 77 78 SConfig customConfig,config; 79 80 int timerID; 81 bool playerKeyPressed[2][PlayerKeyNum]; 82 bool bulletShot[2]; 83 bool minePut[2]; 84 bool waitForStart; 85 double gameEnd; 86 double timeToNextPowerup; 87 88 // SVG sprites 89 QSvgRenderer* svgrender; 90 // This could probably be gotten rid of, but it'll be kind of a pain 91 QString powerupelements[PowerupSprite::PowerupNum]; 92 93 QMap<int, QList<QString> > animation; 94 95 ShipSprite *ship[2]; 96 SunSprite *sun; 97 QGraphicsSimpleTextItem *textSprite; 98 99 QList<BulletSprite*> *bullets[2]; 100 QList<MineSprite*> *mines[2]; 101 QList<ExplosionSprite*> explosions; 102 QList<PowerupSprite*> powerups; 103 104 QRandomGenerator random; 105 106 //Ai 107 Ai *ai[2]; 108 109 }; 110 111 #endif 112