File indexing completed on 2022-09-27 13:19:25

0001 /*
0002     SPDX-FileCopyrightText: 1998-2001 Andreas Zehender <az@azweb.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef __MY_MAIN_VIEW_H
0008 #define __MY_MAIN_VIEW_H
0009 
0010 #include <QGraphicsScene>
0011 #include <QGraphicsView>
0012 #include <QList>
0013 #include <QRandomGenerator>
0014 #include <QTimerEvent>
0015 #include <QWidget>
0016 
0017 
0018 class KToggleAction;
0019 class KActionCollection;
0020 class QGraphicsSimpleTextItem;
0021 
0022 #include "dialogs.h"
0023 #include "sprites.h"
0024 class Ai;
0025 
0026 #ifdef sun
0027 #undef sun
0028 #endif
0029 
0030 class MyMainView:public QWidget
0031 {
0032    Q_OBJECT
0033 public:
0034    explicit MyMainView(QWidget *parent = nullptr);
0035    ~MyMainView() override;
0036 
0037    static KToggleAction *pauseAction;
0038    void setActionCollection(KActionCollection *a);
0039 
0040 public Q_SLOTS:
0041    void newRound();
0042    void newGame();
0043    void togglePause( );
0044    void pause();
0045    void resume();
0046    void start();
0047    void stop();
0048    void gameSetup();
0049    void closeSettings();
0050    void readConfig();
0051    void writeConfig();
0052 Q_SIGNALS:
0053    void hitPoints(int pn,int hp);
0054    void energy(int pn,int en);
0055    void wins(int pn,int w);
0056    void setStatusText(const QString & str,int id);
0057 
0058 protected:
0059    void resizeEvent(QResizeEvent *event) override;
0060    void timerEvent(QTimerEvent *event) override;
0061    void keyPressEvent(QKeyEvent *event) override;
0062    void keyReleaseEvent(QKeyEvent *event) override;
0063    void focusOutEvent (QFocusEvent * /*event*/) override;
0064    bool readSprites();
0065    SConfig modifyConfig(const SConfig &conf);
0066    void moveShips();
0067    void moveBullets();
0068    void moveMines();
0069    void moveExplosions();
0070    void calculatePowerups();
0071    void collisions();
0072 private:
0073    KActionCollection *actionCollection;
0074 
0075    QGraphicsScene field;
0076    QGraphicsView view;
0077 
0078    SConfig customConfig,config;
0079 
0080    int timerID;
0081    bool playerKeyPressed[2][PlayerKeyNum];
0082    bool bulletShot[2];
0083    bool minePut[2];
0084    bool waitForStart;
0085    double gameEnd;
0086    double timeToNextPowerup;
0087 
0088 // SVG sprites
0089    QSvgRenderer* svgrender;
0090    // This could probably be gotten rid of, but it'll be kind of a pain
0091    QString powerupelements[PowerupSprite::PowerupNum];
0092    
0093    QMap<int, QList<QString> > animation;
0094 
0095    ShipSprite *ship[2];
0096    SunSprite *sun;
0097    QGraphicsSimpleTextItem *textSprite;
0098 
0099    QList<BulletSprite*> *bullets[2];
0100    QList<MineSprite*> *mines[2];
0101    QList<ExplosionSprite*> explosions;
0102    QList<PowerupSprite*> powerups;
0103 
0104    QRandomGenerator random;
0105 
0106 //Ai
0107    Ai *ai[2];
0108 
0109 };
0110 
0111 #endif