Skip to content

Commit

Permalink
medals add,code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Cirnoo committed Aug 21, 2018
1 parent 9d5a848 commit f8d566d
Show file tree
Hide file tree
Showing 17 changed files with 466 additions and 986 deletions.
332 changes: 0 additions & 332 deletions Flappy-Bird.pro.user

This file was deleted.

655 changes: 373 additions & 282 deletions Makefile

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
5. 随机的bird和background

#### 待完成的部分
3. 自定义Label
1. 自定义Label


*希望能有人给我提一些改进的建议,感谢*
2 changes: 1 addition & 1 deletion bird.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void Bird::frame()
img=(interval)?(ani+timer/interval%3):(ani+1);
logic(state);
DefaultAction();
y=qMin(y,land);
y=y<land?y:land;
vy=qMin(v_min,vy+g);
timer_key_delay++;
}
Expand Down
2 changes: 1 addition & 1 deletion bird.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Bird : public MyObject
~Bird();
void keyPress();
void Drop();
char state;
volatile char state;
QList<QPointer<Pipe>> pipelist;
private:
QPixmap * ani=nullptr;
Expand Down
20 changes: 20 additions & 0 deletions flappy-bird_plugin_import.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is autogenerated by qmake. It imports static plugin classes for
// static plugins specified using QTPLUGIN and QT_PLUGIN_CLASS.<plugin> variables.
#include <QtPlugin>
Q_IMPORT_PLUGIN(DSServicePlugin)
Q_IMPORT_PLUGIN(AudioCaptureServicePlugin)
Q_IMPORT_PLUGIN(QWindowsAudioPlugin)
Q_IMPORT_PLUGIN(QM3uPlaylistPlugin)
Q_IMPORT_PLUGIN(AccessibleFactory)
Q_IMPORT_PLUGIN(QGenericEnginePlugin)
Q_IMPORT_PLUGIN(QNativeWifiEnginePlugin)
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
Q_IMPORT_PLUGIN(QDDSPlugin)
Q_IMPORT_PLUGIN(QICNSPlugin)
Q_IMPORT_PLUGIN(QICOPlugin)
Q_IMPORT_PLUGIN(QJp2Plugin)
Q_IMPORT_PLUGIN(QMngPlugin)
Q_IMPORT_PLUGIN(QTgaPlugin)
Q_IMPORT_PLUGIN(QTiffPlugin)
Q_IMPORT_PLUGIN(QWbmpPlugin)
Q_IMPORT_PLUGIN(QWebpPlugin)
322 changes: 0 additions & 322 deletions flappy_bird.pro.user

This file was deleted.

4 changes: 0 additions & 4 deletions myobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ void MyObject::restart()
void MyObject::DefaultAction()
{
timer++;
if(navi)
{
rot=qRadiansToDegrees(qAtan2(vy,vx));
}
x+=vx; y+=vy;
if(x<-50)
del_flag=true;
Expand Down
14 changes: 6 additions & 8 deletions myobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ class Widget;
class MyObject : public QObject
{
public:
explicit MyObject(QPixmap & _img, double _x=0, double _y=0, double _vx=0,double _vy=0, int _layer=0);
MyObject(QPixmap & _img, double _x=0, double _y=0, double _vx=0,double _vy=0, int _layer=0);
MyObject();
virtual void frame();
virtual void show(QPainter &);
virtual void gameover();
virtual void restart();
virtual void frame(); //每帧调用
virtual void show(QPainter &); //重绘调用
virtual void gameover(); //游戏结束调用
virtual void restart(); //重新开始调用
int layer=0;
double rot=0;
bool navi=false;
int timer=0;
QPixmap * img=nullptr;
double vx=0,vy=0,x=0,y=0;
volatile double vx=0,vy=0,x=0,y=0;
bool hide=false;
bool del_flag=false;
bool task=true;
private:
protected:
void init(QPixmap & _img,double _x,double _y,double _vx=0,double _vy=0,int _layer=0);
void DefaultAction();
Expand Down
25 changes: 24 additions & 1 deletion score.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "score.h"
#include"widget.h"
Score::Score()
Score::Score():new_record(Res::User->res->new_record)
{
auto & p=Res::User;
img=Res::User->res->num[0];
Expand All @@ -27,6 +27,7 @@ void Score::frame()
void Score::restart()
{
now=0;
new_record_flag=false;
}

void Score::show(QPainter &p)
Expand All @@ -50,11 +51,29 @@ void Score::ShowNum(QPainter & p, double x, double y,unsigned int num,QPixmap *
}
}

void Score::ShowMedals(QPainter & p)
{
if(now/10>0)
{
DrawPixmapAtCenter(board->x_board-0.28*board->board.width(),board->y_board+7,
Res::User->res->medals[now<50?now/10-1:3],p);
}
if(new_record_flag)
{
DrawPixmapAtCenter(board->x_board+0.15*board->board.width(),board->y_board+0.15*board->board.height(),
Res::User->res->new_record,p);
}
}



void Score::ScoreAdd()
{
now++;
if(now>best)
{
new_record_flag=true;
}
emit Res::User->SoundSig(MYSOUND::POINT);
}

Expand All @@ -68,6 +87,10 @@ void Score::ShowResult(QPainter &p)
unsigned int temp=now*board->timer2/30;
ShowNum(p,board->x_board+120,board->y_board-24,temp,img+10);
ShowNum(p,board->x_board+120,board->y_board+32,best,img+10);
if(board->timer2>=30)
{
ShowMedals(p);
}
}

bool Score::IsFinish()
Expand Down
3 changes: 3 additions & 0 deletions score.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class Score:MyObject
void restart();
void show(QPainter &);
void ShowNum(QPainter &,double x,double y,unsigned int num,QPixmap * Numimg);
void ShowMedals(QPainter &);
bool new_record_flag=false;
QPointer<ScoreBoard> board;
QPixmap & new_record;
unsigned int best=0,now=0;
};

Expand Down
22 changes: 10 additions & 12 deletions scoreboard.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include "scoreboard.h"
#include"widget.h"
#include"LabelObj.h"
ScoreBoard::ScoreBoard()
ScoreBoard::ScoreBoard():board(Res::User->res->score_board)
{
auto & p=Res::User;
layer=LAYER_TOP-1;
over=p->res->nullimg;
board=&p->res->score_board;
x_over=p->width()/2;
y_over=p->height()/2-185;
x_board=x_over;
Expand All @@ -26,18 +24,18 @@ ScoreBoard::~ScoreBoard()

void ScoreBoard::frame()
{

auto & User=Res::User;
if(timer==29)
{
emit Res::User->SoundSig(MYSOUND::PANEL);
emit User->SoundSig(MYSOUND::PANEL);
}
else if(timer>=30&&timer<40)
{
y_over=Res::User->height()/2-150+(timer-35)*(timer-35)*0.5;
y_over=User->height()/2-150+(timer-35)*(timer-35)*0.5;
}
else if(timer==60)
{
emit Res::User->SoundSig(MYSOUND::PANEL);
emit User->SoundSig(MYSOUND::PANEL);
}
else if(timer>60&&timer<=102)
{
Expand All @@ -59,30 +57,30 @@ void ScoreBoard::frame()

void ScoreBoard::show(QPainter & p)
{

auto & User=Res::User;
if(timer>30)
{
if(timer<40)
{
over=Res::User->tools->SetAlgha(Res::User->res->game_over,15+24*(timer-30));
over=User->tools->SetAlgha(User->res->game_over,15+24*(timer-30));
}
DrawPixmapAtCenter(x_over,y_over,over,p);
}
if(timer>60)
{
DrawPixmapAtCenter(x_board,y_board,*board,p);
DrawPixmapAtCenter(x_board,y_board,board,p);
}
if(timer>130)
{
if(timer<170)
{
play=Res::User->tools->SetAlgha(Res::User->res->button_play,15+6*(timer-130));
play=User->tools->SetAlgha(User->res->button_play,15+6*(timer-130));
}
DrawPixmapAtCenter(x_play,y_play,play,p);
}
if(timer>110)
{
Res::User->socre->ShowResult(p);
User->socre->ShowResult(p);
}
}

Expand Down
2 changes: 1 addition & 1 deletion scoreboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ScoreBoard:public MyObject
unsigned int timer2=0;
QPixmap over;
QPixmap play;
QPixmap * board;
QPixmap & board;
int x_over,y_over,x_board,y_board,x_play,y_play;//over和board坐标
};

Expand Down
5 changes: 5 additions & 0 deletions sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ Res::Res(Widget* p)
game_over=set(784,116,204,54);
score_board=set(0,516,238,126);
button_play=set(702,234,116,70);
for(int i=0;i<4;i++)
{
medals[i]=set(294,748-48*i,48,46);
}
new_record=set(224,1002,32,14);
minus=QPixmap(":/res/minus.png").scaled(50,50);
close=QPixmap(":/res/close.png").scaled(50,50);
back_temp=nullimg;
Expand Down
18 changes: 9 additions & 9 deletions sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
#include <QSound>


const double RESOLUTION = 1.5 ;
const int COLLI_SIZE = 9 ;
const int LAYER_BACK = 0 ;
const int LAYER_PIPE = 100 ;
const int LAYER_GROUND = 200 ;
const int LAYER_PLAYER = 300 ;
const int LAYER_LABEL = 400 ;
const int LAYER_TOP = 500 ;
const double RESOLUTION = 1.5 ;
const int COLLI_SIZE = 9 ;
const int LAYER_BACK = 0 ;
const int LAYER_PIPE = 100 ;
const int LAYER_GROUND = 200 ;
const int LAYER_PLAYER = 300 ;
const int LAYER_LABEL = 400 ;
const int LAYER_TOP = 500 ;


namespace MYSOUND
Expand All @@ -40,7 +40,7 @@ class Res
Res(Widget* );
static Widget * User;
QPixmap nullimg,background[2],ground,bird[3][3],game_ready,num[2][10],white,black,pipe_down,pipe_up,
game_over,score_board,button_play,minus,close ;
game_over,score_board,button_play,minus,close,medals[4],new_record;
QPointer<QSound> sound[5];
private:

Expand Down
8 changes: 4 additions & 4 deletions widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Widget::Widget(QWidget *parent) :

Widget::~Widget()
{
for(int i=0;i<3;i++)
for(int i=0;i<2;i++)
{
thread[i]->quit();
thread[i]->wait();
Expand Down Expand Up @@ -58,7 +58,7 @@ void Widget::init()
ground.reset(new Back(res->ground,this->height()-res->ground.height()/2,-2,LAYER_GROUND));
bird.reset(new Bird());
socre .reset( new Score());
for(int i=0;i<3;i++)
for(int i=0;i<2;i++)
{
my_thread[i]=new MyThread();
thread[i]=new QThread(this);
Expand All @@ -71,7 +71,7 @@ void Widget::init()
connect(&timer, &QTimer::timeout,my_thread[THREAD::FRAME],&MyThread::MyFrame);
connect(this, &Widget::SendKeyPress,my_thread[THREAD::STATE],&MyThread::MyKeyPress);
connect(this, &Widget::Do, this,&Widget::frame2);
connect(this,SIGNAL(SoundSig(int)),my_thread[THREAD::SOUND],SLOT(Sound(int)));
connect(this,SIGNAL(SoundSig(int)),my_thread[THREAD::STATE],SLOT(Sound(int)));
connect(&timer, SIGNAL(timeout()), this, SLOT(update()));
}

Expand Down Expand Up @@ -147,7 +147,7 @@ void Widget::mousePressEvent(QMouseEvent *event)
emit SendKeyPress();
}

void Widget::DoFrame(QMultiMap<int, MyObject*> & task_list)
void Widget::DoFrame(QMultiMap<int, QPointer<MyObject>> & task_list)
{
auto i=task_list.begin();
while (i!=task_list.end())
Expand Down
16 changes: 8 additions & 8 deletions widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#include"tools.h"
#include"pipe.h"
#include"score.h"
#include<QTimer>
#include <QTimer>
#include <QThread>
#include <QGLWidget>
#include<QMultiMap>
#include<QApplication>
#include <QMultiMap>
#include <QApplication>
class MyLabel;
namespace Ui {
class Widget;
Expand Down Expand Up @@ -46,17 +46,17 @@ public slots:
void init();
void frame2();
QScopedPointer<Back> back;
QMultiMap<int,MyObject *> InSubThread;
QMultiMap<int,MyObject *> InMainThread;
QMultiMap<int,QPointer<MyObject>> InSubThread;
QMultiMap<int,QPointer<MyObject >> InMainThread;
void paintEvent(QPaintEvent *);
Ui::Widget *ui;
MyThread * my_thread[3];
QThread *thread[3];
MyThread * my_thread[2];
QThread *thread[2];
QPixmap view;
void keyPressEvent(QKeyEvent * event);
void mousePressEvent(QMouseEvent * event);
bool update_flag=false;
void DoFrame(QMultiMap<int, MyObject*> & );
void DoFrame(QMultiMap<int, QPointer<MyObject> > & );
};


Expand Down

0 comments on commit f8d566d

Please sign in to comment.