Qtの飛行機大戦

29588 ワード

小さな試合で、c++の飛行機大戦を書いたが、個人的にはあまり満足していない.
第1はQtの学习に対してまだとても初歩的で、第2はc++の継承の思想に対してとても良いことがありません
3つ目は命名規範があまりよくないことです.
だから今回のプログラムは参考にします.
コードは次のとおりです.
プロジェクトファイル
#-------------------------------------------------
#
# Project created by QtCreator 2019-06-02T11:17:26
#
#-------------------------------------------------

QT       += core gui
QT +=multimedia

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = projectplany01
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES += \
        background.cpp \
        bossplany.cpp \
        eneumplany.cpp \
        gameover.cpp \
        main.cpp \
        myplany.cpp \
        name.cpp \
        playbuttle.cpp \
        playwindow.cpp \
        srengine.cpp \
        widget.cpp

HEADERS += \
        background.h \
        bossplany.h \
        eneumplany.h \
        gameover.h \
        myplany.h \
        name.h \
        playbuttle.h \
        playwindow.h \
        srengine.h \
        widget.h

FORMS += \
        widget.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += \
    image.qrc
RC_ICONS=a.ico

main.cpp
#include "widget.h"
#include 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    return a.exec();
}

初期インタフェースwidget
#ifndef WIDGET_H
#define WIDGET_H
#include 
#include
#include
#include
#include
#include
#include"name.h"
#include
#include"srengine.h"
namespace Ui {
class Widget;
}
//    
class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = nullptr);
    void paintEvent(QPaintEvent *e);
    ~Widget();
private slots:
    void change();
    void help();
    void leardboardslots();
private:
    Ui::Widget *ui;
    playwindow *play_window;
    QLabel *label;
    name *play_name;
    QWidget *leard_widget;
    SREngine *srengine;
};

#endif // WIDGET_H
#include "widget.h"
#include "ui_widget.h"
//    cha
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
     play_window=new playwindow;
    play_name= new name;
    play_name->setWindowFlag(Qt::WindowStaysOnTopHint);
    play_name->show();
    ui->setupUi(this);
    this->resize(800,600);
    this->setWindowFlag(Qt::FramelessWindowHint);//       
    ui->pushButton->resize(140,50);
    ui->pushButton->setFlat(true);
    ui->pushButton_2->setFlat(true);
    ui->pushButton_2->resize(140,50);
    ui->pushButton_3->setFlat(true);
    ui->pushButton_3->resize(140,50);
    ui->pushButton_4->resize(140,50);
    ui->pushButton_4->setFlat(true);
    connect(ui->pushButton_2,&QPushButton::clicked,this,&QWidget::close);
    connect(ui->pushButton,&QPushButton::clicked,this,&Widget::change);
    connect(ui->pushButton_3,&QPushButton::clicked,this,&Widget::help);
    connect(ui->pushButton_4,&QPushButton::clicked,this,&Widget::leardboardslots);
    //srengine = new SREngine;
}
//   
void Widget::paintEvent(QPaintEvent *e)
{
    QPainter p(this);
    p.drawPixmap(0,0,width(),height(),QPixmap(":/new/prefix1/Image/68396.jpg"));
}
void Widget::help()
{
    label= new QLabel;
    label->resize(450,400);
    label->setWindowFlag(Qt::WindowStaysOnTopHint,true);
    label->setWindowTitle(QStringLiteral("  "));
    label->setText(QStringLiteral("              1.0  

w a s d " " z boss
")); label->show(); } // void Widget::leardboardslots() { leard_widget= new QWidget; leard_widget->setWindowTitle(QStringLiteral(" ")); leard_widget->resize(400,400); QFile *f= new QFile("D:/1.txt"); int x=140; int y=100; QString s; if(!f->open(QIODevice::ReadWrite|QIODevice::Text)) { qDebug()<atEnd()) { QByteArray line = f->read(1); if(QString(line)!='
') s.push_back(line); } qDebug()<close(); delete f; leard_widget->show(); } Widget::~Widget() { delete ui; } // void Widget::change() { this->hide(); play_window->show(); }

ゲームインタフェースコード:
#include "playwindow.h"
#include
#include
playwindow::playwindow()
{
    game_over= new class gameover;
    this->resize(WINDOWWIDTH,WINDOWLONG);//    
    back_ground=new background;//  
    this->setScene(back_ground);
    setWindowTitle(QStringLiteral("    "));
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//     
    setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    connect(back_ground,&background::plant_shape,this,&playwindow::gameover);
}
//    
void playwindow::gameover()
{
    back_ground->addItem(game_over);
    this->setEnabled(false);
}

playwindow::~playwindow()
{
   delete back_ground;
}
#ifndef PLAYWINDOW_H
#define PLAYWINDOW_H
#include
#include"background.h"
#include"gameover.h"
//    
const int WINDOWWIDTH=1800;//    
const int WINDOWLONG=1000;//    
class playwindow:public QGraphicsView
{
    Q_OBJECT
public:
    ~playwindow();
    playwindow();
private:
background *back_ground;//    
class gameover *game_over;
public slots:
void gameover();
};

#endif // PLAYWINDOW_H

ゲームの背景といくつかの論理
#ifndef BACKGROUND_H
#define BACKGROUND_H
#include
#include
#include"myplany.h"
#include"eneumplany.h"
#include
#include
#include
#include"bossplany.h"
//   
struct grade{
    int left;
    int right;
    int leve;
};
class background:public QGraphicsScene
{
    Q_OBJECT
public:
    background();
    ~background();
    myplany *my_plany;//    
    QVector eneum_plany;//  
    grade leave;
private:
    void drawBackground(QPainter *painter, const QRectF &rect);
    void timerEvent(QTimerEvent *event);
     void produce_eneumplany();
     bool plany_impact();
     void eneum_shape();
     void myplany_shape(eneumplany &eneum_plany);
     void boss_initia();
signals:
     void plant_shape();
private:
     bool judge_eneumplany();
     bool judge_eneumplany_init;
     void delete_eneum_plany();
     void delete_shape_buttle();
     int n;
     int boss_n;
     QMediaPlayer *music;
     bossplany *boss_plany;
     bool boss_judge;

};

#endif // BACKGROUND_H
#include "background.h"
#include
#include
background::background()
{
    leave.left=1;
    leave.right=10;
    leave.leve=1;
    my_plany=new myplany;//  
    judge_eneumplany_init=true;
    addItem(my_plany);
    startTimer(50);
    produce_eneumplany();
    n=startTimer(10);
    music= new QMediaPlayer(this);
    connect(music,SIGNAL(positionChanged(qint64)),this,SLOT(postitionChanged(qint64)));
    music->setMedia(QUrl::fromLocalFile("D:\\music\\1111.mp3"));
    music->setVolume(60);
    music->play();
    boss_n=0;
    boss_judge=false;
}
background::~background()
{
    delete music;
    delete my_plany;
    delete boss_plany;
}
//    
void background::drawBackground(QPainter *painter, const QRectF &rect)
{
    painter->drawPixmap(0,0,1800,1000,QPixmap(":/new/prefix1/Image/background.png"));

}
//      
void background::timerEvent(QTimerEvent *event)
{
    //             
       plany_impact();
       //        
    if(judge_eneumplany()&&judge_eneumplany_init&&boss_judge==false)
    {
        produce_eneumplany();
    }
    boss_initia();
    //          
    if(my_plany->blood==0&&my_plany->life)
    {
        my_plany->image=":/new/prefix1/Image/bigairplane3.png";//    
        judge_eneumplany_init=false;
        //      
        QFile *f=new QFile("D:/1.txt");
        if(!f->open(QIODevice::ReadWrite | QIODevice::Text|QIODevice::Append)) {
        qDebug()<mark<close();
      delete f;
      my_plany->life=false;
      plant_shape();
    }
    //        
    eneum_shape();
     //               
    for(auto be=eneum_plany.begin();be!=eneum_plany.end();be++)
    {
    myplany_shape(**be);
    }
    //          
    if(event->timerId()==n)
    delete_shape_buttle();
}
//    
void background::produce_eneumplany()
{
    srand((unsigned)time(NULL));
    int value=0;//      
    value=rand()%leave.right+leave.left;
    for(int i=0;imark+=10*value;//  
}
//    
bool background::plany_impact()
{
    for(auto a:eneum_plany)
    {
        if(my_plany->plany_x>=a->plany_x+10&&my_plany->plany_x<=a->plany_x+50&&my_plany->plany_y<=a->plany_y+70
                &&my_plany->plany_y>=a->plany_y+10)
        {
            my_plany->blood--;
            a->blood--;
        }
    }
    return false;
}
//          
void background::eneum_shape()
{
    bool break_judge=false;
    for(auto a=my_plany->play_buttle.begin();a!=my_plany->play_buttle.end();a++)
    {
        for(auto b=eneum_plany.begin();b!=eneum_plany.end();b++)
        {
            if(a->buttle_x>=(*b)->plany_x&&a->buttle_x<=(*b)->plany_x+60&&
                    a->buttle_y<=(*b)->plany_y+80&&a->buttle_y>=(*b)->plany_y)
            {
                if((*b)->blood==0)
                {
                    (*b)->life=false;
                    (*b)->image=":/new/prefix1/Image/bigairplane3.png";
                    (*b)->eneum_buttle.clear();
                    eneum_plany.erase(b);//    
                    break_judge=true;
                    my_plany->mark+=20;//   20
                    break;
                }
                  (*b)->blood--;
                  my_plany->play_buttle.erase(a);//      
                  break_judge=true;
                  break;
            }
        }
        if(break_judge)
        {
            break;
        }
    }
}
//          
bool background::judge_eneumplany()
{
 qDebug()<life))
          continue;
         else
         {
            return false;
         }
     }
     boss_n++;
     eneum_plany.clear();
     return true;
}
//        
void background::delete_shape_buttle()
{
    for(auto a:eneum_plany)
    {
        for(auto be=a->eneum_buttle.begin();be!=a->eneum_buttle.end();be++)
        {
            for(auto be1=my_plany->play_buttle.begin();be1!=my_plany->play_buttle.end();be1++)
            {
                if(be->buttle_x>=be1->buttle_x-40&&be->buttle_x<=be1->buttle_x+40&&
                        be->buttle_y>=be1->buttle_y+20)
                {
                    my_plany->play_buttle.erase(be1);
                    a->eneum_buttle.erase(be);
                    break;
                }
            }
            break;
        }
    }
}
//            
void background::myplany_shape(eneumplany &eneum_plany)
{
         for(auto be1=(eneum_plany).eneum_buttle.begin();be1!=(eneum_plany).eneum_buttle.end();be1++)
         {
             if(be1->buttle_x>=my_plany->plany_x&&be1->buttle_x<=my_plany->plany_x+60&&
                     be1->buttle_y>=my_plany->plany_y&&be1->buttle_y<=my_plany->plany_y+80)
             {
                my_plany->blood--;
                (eneum_plany).eneum_buttle.erase(be1);
                break;
             }
         }
}
//boss   
void background::boss_initia()
{
    if(boss_n==10)
    {
        my_plany->blood=10;
        boss_plany =new bossplany(*(my_plany));//    
        this->addItem(boss_plany);
        boss_n++;
        boss_plany->life=true;
        boss_judge=true;
     }
    else {
        if(boss_n>=1&&boss_judge==true)
        {
            if(boss_plany->blood==0)
            {
                delete boss_plany;
                boss_judge=false;
                my_plany->mark+=5000;
            }
        }
    }
}












プレイヤー機
#ifndef MYPLANY_H
#define MYPLANY_H
#include//   Qobject
#include
#include
#include
#include
#include"playbuttle.h"
#include
//     
class myplany:public QGraphicsObject
{
    Q_OBJECT
public:
    myplany();
    //       
 //  
     int blood;
     QString image;
     int plany_x;
     int plany_y;
     QList play_buttle;//  
     int mark;//  
      bool life;
      int skill;
private:
     QRectF
      boundingRect() const;
     void keyPressEvent(QKeyEvent *event);
     void  keyReleaseEvent(QKeyEvent* event);
     void paint(QPainter *painter,const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr);
     void timerEvent(QTimerEvent *event);
     //         
      bool w_judge;
      bool s_judge;
      bool a_judge;
      bool d_judge;
      bool space_judge;
      bool z_judge;
      void produce_eneumplany();
private:
      int time1;
      int time2;
      static const int buttle_speed=35;
      int speed;
signals:
      void skill_z();
};

#endif // MYPLANY_H
#include "myplany.h"
#include
#include
const int PLANYBOUNDARY_X=1750;
const int PLANYBOUNDARY_Y=930;
myplany::myplany()
{
  plany_x=900;
  plany_y=900;
  w_judge=false;
  s_judge=false;
  a_judge=false;
  d_judge=false;
  z_judge=false;
  space_judge=false;
  speed=29;
  blood=10;
  skill=10;
  time1=startTimer(20);//     
  setFlag(QGraphicsItem::ItemIsFocusable);//      
  image=":/new/prefix1/Image/myplane.png";
  mark=0;
  life =true;
}
QRectF myplany::boundingRect() const
{
    qreal penwidth=1;
    return QRectF(0,0,1800,1000);
}
//        
void myplany::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->drawPixmap(plany_x,plany_y,60,80,QPixmap(image));
    //  
    for(auto be=play_buttle.begin();be!=play_buttle.end();be++)
    {
        painter->drawPixmap(be->buttle_x,be->buttle_y,20,20,QPixmap(":/new/prefix1/Image/Bomb4.png"));
    }
    //  
    painter->setPen(Qt::blue);
    QFont font;
    font.setPixelSize(50);
    painter->setFont(font);
    painter->drawText(1530,800,QStringLiteral("  : "));
    painter->drawText(1650,800,QString::number(mark));
    update();
    //  
    painter->setPen(Qt::white);
    painter->drawRect(1500,900,10*20,20);
    painter->setBrush(QBrush(Qt::blue));
    if(skill>0)
    painter->drawRect(1500,950,this->skill*20,20);
    //  
    painter->setBrush(Qt::white);
    painter->setPen(Qt::white);
    painter->drawRect(1500,900,10*20,20);
    painter->setBrush(QBrush(Qt::red));
    painter->drawRect(1500,900,this->blood*20,20);
    update();
}
//      
void myplany::keyPressEvent(QKeyEvent *event)
{
  switch(event->key())
  {case Qt::Key_W:
      w_judge=true;
 break;
  case Qt::Key_S:
      s_judge=true;
     break;
  case Qt::Key_A:
       a_judge=true;
      break;
  case Qt::Key_D:
        d_judge=true;
      break;
  case Qt::Key_Space:
      space_judge=true;
      break;
  case Qt::Key_Z:
      z_judge=true;
      break;
  }
}
void myplany::keyReleaseEvent(QKeyEvent *event)
{
    switch(event->key())
    {case Qt::Key_W:
        w_judge=false;
   break;
    case Qt::Key_S:
        s_judge=false;
         break;
    case Qt::Key_A:
         a_judge=false;
        break;
    case Qt::Key_D:
          d_judge=false;
        break;
    case Qt::Key_Space:
        space_judge=false;
        break;
    }
}
//     
void myplany::timerEvent(QTimerEvent *event)
{

//       
for(auto be=play_buttle.begin();be!=play_buttle.end();be++)
{
    be->buttle_y-=buttle_speed;//  
    if(be->buttle_y<0)
    {
        play_buttle.erase(be);
        break;
    }
}
//        
if(space_judge)
{
  PlayButtle playbuttle(plany_x+25,plany_y);
  play_buttle.push_back(playbuttle);
}
mark+=10;//  0.1  10 
if(w_judge)
{
    plany_y-=speed;
    if(plany_y<0)
        plany_y=0;
}
if(s_judge)
{
    plany_y+=speed;
    if(plany_y>PLANYBOUNDARY_Y)
    {
        plany_y=PLANYBOUNDARY_Y;
    }
}
if(a_judge)
{
      plany_x-=speed;
      if(plany_x<0)
          plany_x=0;
}
if(d_judge)
{
      plany_x+=speed;
      if(plany_x>PLANYBOUNDARY_X)
          plany_x=PLANYBOUNDARY_X;
}
if(z_judge)
{
    skill-=2;
    emit skill_z();
    z_judge=false;
}
}

プレイヤー弾丸
#ifndef PLAYBUTTLE_H
#define PLAYBUTTLE_H
#include
#include
class PlayButtle:public QGraphicsRectItem
{
public:
    PlayButtle(int a,int b);
    PlayButtle(const PlayButtle&a);
    ~PlayButtle();
    PlayButtle& operator=(PlayButtle &a);
    int buttle_x;
    int buttle_y;
    QPainterPath shape()const;
    static const int speed =10;
};

#endif // PLAYBUTTLE_H
#include "playbuttle.h"
#include
PlayButtle::PlayButtle(int a,int b)
{
buttle_x=a;
buttle_y=b;
}

PlayButtle::PlayButtle(const PlayButtle &a)
{
    buttle_x=a.buttle_x;
    buttle_y=a.buttle_y;
}

PlayButtle::~PlayButtle()
{

}

PlayButtle &PlayButtle::operator=(PlayButtle &a)
{
    buttle_x=a.buttle_x;
    buttle_y=a.buttle_y;
    return *this;
}
QPainterPath PlayButtle::shape() const
{
    QPainterPath p;
    p.addRect(buttle_x,buttle_y,20,20);
    return p;
}



敵機
#ifndef ENEUMPLANY_H
#define ENEUMPLANY_H
#include
#include
#include"playbuttle.h"
#include
#include
#include
#include
class eneumplany:public QGraphicsObject
{
public:
    eneumplany(int x=0,int y=0,int c=0);
    eneumplany(const eneumplany&);//      
    ~eneumplany();
   void operator=(const eneumplany &);//=    
public:
    QRectF boundingRect()const;
    void paint(QPainter *painter,const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr);
    void timerEvent(QTimerEvent *event);
     QPainterPath shape() const;
     int plany_x;
     int plany_y;
     QString image;
    int blood;//  
     bool life;//     
     QList eneum_buttle;//    
      int speed;
private:
   int x_speed;
    int val_random;//               
   int explode_judge;//            
};

#endif // ENEUMPLANY_H
#include "eneumplany.h"
#include
#include
eneumplany::eneumplany(int x,int y,int c)
{
 plany_x=x;
 plany_y=y;
 val_random=c;
 startTimer(300);
 srand(val_random);
 this->speed=rand()%10+30;
 blood=5;
 life=true;
 explode_judge=0;
 image=":/new/prefix1/Image/enemyplane.png";
}
//      
eneumplany::eneumplany(const eneumplany &a)
{
    this->plany_x=a.plany_x;
    this->plany_y=a.plany_y;
}

eneumplany::~eneumplany()
{

}
//  =   
void eneumplany::operator=(const eneumplany &a)
{
    this->plany_x=a.plany_x;
    this->plany_y=a.plany_y;
}
//       
QRectF eneumplany::boundingRect() const
{
    return QRectF(0,0,1800,1000);
}
//      
void eneumplany::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    //  
    if(life)
    {painter->drawPixmap(plany_x,plany_y,60,80,QPixmap(image));
    }
    //        
    if(!life&&explode_judge!=50)
    {
        painter->drawPixmap(plany_x,plany_y,60,80,QPixmap(image));
        explode_judge++;
    }
    //  
    if(life)
    for(auto be=eneum_buttle.begin();be!=eneum_buttle.end();be++)
    {
        painter->drawPixmap(be->buttle_x,be->buttle_y,20,30,QPixmap(":/new/prefix1/Image/mybullet.png"));
         be->buttle_y+=be->speed;//      
    }
    update();
   }
//    
void eneumplany::timerEvent(QTimerEvent *event)
{
   //    
   if(life)
   {srand(val_random);
   x_speed=rand()%60-40;
   plany_x+=x_speed;
   plany_y+=speed;}
   if(plany_x<=0)
   {
       plany_x=0;
   }
   if(plany_x>=1740)
   {
       plany_x=1740;
   }
   //      ,       
   if(plany_y>=1000)
   {
       life=false;
       blood=0;
   }
   //      
      PlayButtle buttle(plany_x+20,plany_y+80);
      for(auto be=eneum_buttle.begin();be!=eneum_buttle.end();be++)
      {
           be->buttle_y+=be->speed;
      }

      eneum_buttle.push_back(buttle);
      if(eneum_buttle.front().buttle_y>1800)//          
      {
          eneum_buttle.pop_front();
      }
}
QPainterPath eneumplany::shape() const
{
    QPainterPath p;
    p.addRect(plany_x,plany_y,60,80);
    return p;
}


死亡画面
#ifndef GAMEOVER_H
#define GAMEOVER_H
#include
#include
#include
#include
class gameover:public QGraphicsObject
{
    Q_OBJECT
public:
    gameover();
    QRectF boundingRect()const;
    void paint(QPainter *painter,const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr);
    void timerEvent(QTimerEvent *event);
private:

signals:
    void show_mainwindow();

};

#endif // GAMEOVER_H
#include "gameover.h"

gameover::gameover()
{
    startTimer(5000);
}

QRectF gameover::boundingRect() const
{
    return QRectF(0,0,1800,1000);
}

void gameover::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->drawPixmap(0,0,1800,1000,QPixmap(":/new/prefix1/Image/425d4c0c0f16c401db1f1[1].jpg"));

}

void gameover::timerEvent(QTimerEvent *event)
{

    emit show_mainwindow();
}


ボス機
#ifndef BOSSPLANY_H
#define BOSSPLANY_H
#include"eneumplany.h"
#include"myplany.h"
class bossplany:public eneumplany
{
    Q_OBJECT
public:
    bossplany(myplany &c);
    QRectF boundingRect()const;
    void paint(QPainter *painter,const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr);
     void timerEvent(QTimerEvent *event);
     bool life;
     QList boss_buttle_1;
     QList boss_buttle_2;
     QList boss_buttle_3;
private:
     int buttly_y_1;//      y
     myplany &my_plany;
     int time1;
     int time2;
     int time3;
     void boss_myplany(QList &boss_buttle);
     void mybuttle_boss();
     void buttle_shape(QList &boss_buttle);
     int x_speed;
     int speed;
public slots:
     void buttle_skill();

};

#endif // BOSSPLANY_H
#include "bossplany.h"

bossplany::bossplany(myplany &c):my_plany(c)
{
    image=":/new/prefix1/Image/boss9.png";
    blood=250;
    plany_x=500;
    plany_y=0;
    life=false;
    time1=startTimer(200);
    time2=startTimer(1000);
    time3=startTimer(5000);
    x_speed=100;
    speed=50;
}
QRectF bossplany::boundingRect() const
{
    return QRectF(0,0,1800,1000);
}
void bossplany::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    if(blood==0)//  boss  
    {
        life=false;
        image=":/new/prefix1/Image/bigairplane3.png";
    }
     if(life)
     {painter->drawPixmap(plany_x,plany_y,400,400,QPixmap(image));
     for(auto b:boss_buttle_1)
     {
         painter->drawPixmap(b.buttle_x-60,b.buttle_y+100,40,40,QPixmap(":/new/prefix1/Image/Bomb4.png"));
     }
     for(auto b:boss_buttle_2)
     {
         painter->drawPixmap(b.buttle_x+50,b.buttle_y+100,40,40,QPixmap(":/new/prefix1/Image/Bomb4.png"));
     }
     for(auto b:boss_buttle_3)
     {
         painter->drawPixmap(b.buttle_x,b.buttle_y+100,40,80,QPixmap(":/new/prefix1/Image/bossbullet (2).png"));
     }
     // boss   
     QFont font;
     font.setPixelSize(25);
     painter->setFont(font);
     painter->setPen(Qt::blue);
     painter->drawText(0,40,QStringLiteral("Great old one"));
     painter->drawRect(170,20,700,20);
     painter->setBrush(Qt::red);
     painter->drawRect(170,20,7*blood/5,20);
     update();}
}

void bossplany::timerEvent(QTimerEvent *event)
{
    if(time1==event->timerId()&&life)
    { //boss   
    plany_x+=speed;
    if(plany_x<=0)
    {
        plany_x=0;
        speed=-speed;
    }
    if(plany_x>=1400)
    {
        plany_x=1400;
        speed=-speed;
    }
//     
    PlayButtle buttle(plany_x+200,plany_y);
    boss_buttle_1.push_back(buttle);
    boss_buttle_2.push_back(buttle);
    for(auto be=boss_buttle_1.begin();be!=boss_buttle_1.end();be++)
    {
        be->buttle_y+=70;
        srand(my_plany.plany_x);
        be->buttle_x+=x_speed;
        if(be->buttle_y>=1000||be->buttle_x<=0||be->buttle_x>=1800)
        {
            boss_buttle_1.erase(be);
            break;
        }
    }
    for(auto be=boss_buttle_2.begin();be!=boss_buttle_2.end();be++)
    {
        be->buttle_y+=70;
        srand(my_plany.plany_x);
        be->buttle_x-=x_speed;
        if(be->buttle_y>=1000||be->buttle_x<=0||be->buttle_x>=1800)
        {
            boss_buttle_2.erase(be);
            break;
        }
        x_speed+=20;
        if(x_speed>=150)
        {
            x_speed=0;
        }
    }
    boss_myplany(boss_buttle_1);
    boss_myplany(boss_buttle_2);
    boss_myplany(boss_buttle_3);
    buttle_shape(boss_buttle_1);
    buttle_shape(boss_buttle_2);
    buttle_shape(boss_buttle_3);
    mybuttle_boss();
    connect(&my_plany,&myplany::skill_z,this,&bossplany::buttle_skill);
    }
    //       
    for(auto be=boss_buttle_3.begin();be!=boss_buttle_3.end();be++)
    {
        be->buttle_y+=80;
        srand(my_plany.plany_x);
        if(be->buttle_y>=1000||be->buttle_x<=0||be->buttle_x>=1800)
        {
            boss_buttle_3.erase(be);
            break;
        }
    }
    if(time2==event->timerId()&&life)
  { PlayButtle buttle(plany_x+200,plany_y);
    boss_buttle_3.push_back(buttle);
    }
    if(time3==event->timerId())
    {
        if(my_plany.skill<10)
        my_plany.skill++;
    }
}
//boss      
void bossplany::boss_myplany(QList &boss_buttle)
{
   for(auto be=boss_buttle.begin();be!=boss_buttle.end();be++)
   {
       if(be->buttle_x>=my_plany.plany_x&&be->buttle_x<=my_plany.plany_x+60&&
               be->buttle_y>=my_plany.plany_y&&be->buttle_y<=my_plany.plany_y+80)
       {
          my_plany.blood--;
         boss_buttle.erase(be);
          break;
       }
   }
}
//        
void bossplany::mybuttle_boss()
{
    for(auto be=my_plany.play_buttle.begin();be!=my_plany.play_buttle.end();be++)
    {
        if(be->buttle_x>plany_x&&be->buttle_xbuttle_y<=400)
        {
            this->blood--;
            my_plany.play_buttle.erase(be);
            break;
        }
    }
}
//    
void bossplany::buttle_shape(QList &boss_buttle)
{
    for(auto be=boss_buttle.begin();be!=boss_buttle.end();be++)
    {
        for(auto be1=my_plany.play_buttle.begin();be1!=my_plany.play_buttle.end();be1++)
        {
            if(be->buttle_x>=be1->buttle_x&&be->buttle_x<=be1->buttle_x+40&&
                    be->buttle_y>=be1->buttle_y+20)
            {
                my_plany.play_buttle.erase(be1);
                boss_buttle.erase(be);
                break;
            }
        }
        break;
    }
}
void bossplany::buttle_skill()
{
    boss_buttle_1.clear();
    boss_buttle_2.clear();
    boss_buttle_3.clear();
}

注意は参考にして、自分で書いたほうがいいです.中にはできることがたくさんあります.