From 213b2f8c345bdbb1b17f22a7f38a9ebca02bd7be Mon Sep 17 00:00:00 2001 From: handsomebsn <1903935168@qq.com> Date: Sat, 20 May 2017 07:02:02 +0800 Subject: [PATCH] Add files via upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 地图初步 --- Tank.pro | 34 +++++++ Tank.pro.user | 259 +++++++++++++++++++++++++++++++++++++++++++++++++ boom.cpp | 7 ++ boom.h | 11 +++ bullet.cpp | 7 ++ bullet.h | 11 +++ gamemap.cpp | 32 ++++++ gamemap.h | 17 ++++ main.cpp | 11 +++ main.h | 14 +++ mainwindow.cpp | 30 ++++++ mainwindow.h | 26 +++++ mapcell.cpp | 20 ++++ mapcell.h | 34 +++++++ mytank.qrc | 17 ++++ object.cpp | 7 ++ object.h | 37 +++++++ tank.cpp | 7 ++ tank.h | 10 ++ wanwu.cpp | 11 +++ wanwu.h | 53 ++++++++++ 21 files changed, 655 insertions(+) create mode 100644 Tank.pro create mode 100644 Tank.pro.user create mode 100644 boom.cpp create mode 100644 boom.h create mode 100644 bullet.cpp create mode 100644 bullet.h create mode 100644 gamemap.cpp create mode 100644 gamemap.h create mode 100644 main.cpp create mode 100644 main.h create mode 100644 mainwindow.cpp create mode 100644 mainwindow.h create mode 100644 mapcell.cpp create mode 100644 mapcell.h create mode 100644 mytank.qrc create mode 100644 object.cpp create mode 100644 object.h create mode 100644 tank.cpp create mode 100644 tank.h create mode 100644 wanwu.cpp create mode 100644 wanwu.h diff --git a/Tank.pro b/Tank.pro new file mode 100644 index 0000000..09f37a2 --- /dev/null +++ b/Tank.pro @@ -0,0 +1,34 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-05-19T10:29:41 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = Tank +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp \ + wanwu.cpp \ + tank.cpp \ + bullet.cpp \ + boom.cpp \ + mapcell.cpp \ + gamemap.cpp + +HEADERS += mainwindow.h \ + wanwu.h \ + tank.h \ + bullet.h \ + boom.h \ + mapcell.h \ + gamemap.h \ + main.h + +RESOURCES += \ + mytank.qrc diff --git a/Tank.pro.user b/Tank.pro.user new file mode 100644 index 0000000..fcdc6b5 --- /dev/null +++ b/Tank.pro.user @@ -0,0 +1,259 @@ + + + + + + EnvironmentId + {061e66c4-2158-49d6-9f1d-ba1daf5895b3} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.5.1 MinGW 32bit + Desktop Qt 5.5.1 MinGW 32bit + qt.55.win32_mingw492_kit + 0 + 0 + 0 + + D:/myqt/build-Tank-Desktop_Qt_5_5_1_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/myqt/build-Tank-Desktop_Qt_5_5_1_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + 在本地部署 + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Tank + + Qt4ProjectManager.Qt4RunConfiguration:D:/myqt/Tank/Tank.pro + + Tank.pro + false + false + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/boom.cpp b/boom.cpp new file mode 100644 index 0000000..75c11c4 --- /dev/null +++ b/boom.cpp @@ -0,0 +1,7 @@ +#include "boom.h" + +boom::boom() +{ + +} + diff --git a/boom.h b/boom.h new file mode 100644 index 0000000..c629f3c --- /dev/null +++ b/boom.h @@ -0,0 +1,11 @@ +#ifndef BOOM_H +#define BOOM_H +#include"wanwu.h" + +class boom : public Wanwu +{ +public: + boom(); +}; + +#endif // BOOM_H diff --git a/bullet.cpp b/bullet.cpp new file mode 100644 index 0000000..3a5ef06 --- /dev/null +++ b/bullet.cpp @@ -0,0 +1,7 @@ +#include "bullet.h" + +bullet::bullet() +{ + +} + diff --git a/bullet.h b/bullet.h new file mode 100644 index 0000000..fafd152 --- /dev/null +++ b/bullet.h @@ -0,0 +1,11 @@ +#ifndef BULLET_H +#define BULLET_H + +#include"wanwu.h" +class bullet : public Wanwu +{ +public: + bullet(); +}; + +#endif // BULLET_H diff --git a/gamemap.cpp b/gamemap.cpp new file mode 100644 index 0000000..d66bfca --- /dev/null +++ b/gamemap.cpp @@ -0,0 +1,32 @@ +#include "gamemap.h" + +GameMap::GameMap() +{ +for(int i=0;iDisplay(paint); + + } + +} + diff --git a/gamemap.h b/gamemap.h new file mode 100644 index 0000000..488f0a9 --- /dev/null +++ b/gamemap.h @@ -0,0 +1,17 @@ +#ifndef GAMEMAP_H +#define GAMEMAP_H + +#include"mapcell.h" +#include +#include"main.h" +class GameMap +{ +private: +Mapcell *cells[INUM][JNUM]; +public: + GameMap(); + ~GameMap(); + void Display(QPainter &paint); +}; + +#endif // GAMEMAP_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..aab39bb --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/main.h b/main.h new file mode 100644 index 0000000..14c49b9 --- /dev/null +++ b/main.h @@ -0,0 +1,14 @@ +#ifndef MAIN +#define MAIN +#define JNUM 23 +#define INUM 19 +#define PICWIDTH 40 +#define PICHEIGHT 40 +#define CELLWIDTH 40 +#define CELLHEIGHT 40 +#define WIDTH 40*23 +#define HEIGHT 40*19 + + +#endif // MAIN + diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..43a2f0e --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,30 @@ +#include "mainwindow.h" +#include"QRect" +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ +} + +MainWindow::~MainWindow() +{ + +} +void MainWindow::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + +setFixedSize(WIDTH,HEIGHT); +QPainter paint(this); +paint.begin(this); +gamemap.Display(paint); +paint.end(); +} + + + + +void MainWindow::keyPressEvent(QKeyEvent *event){ + + + +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..584711c --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,26 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include"main.h" +#include "gamemap.h" + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = 0); + ~MainWindow(); +private slots: +void keyPressEvent(QKeyEvent *event); +void paintEvent(QPaintEvent *event); +private: +GameMap gamemap; + + +}; + +#endif // MAINWINDOW_H diff --git a/mapcell.cpp b/mapcell.cpp new file mode 100644 index 0000000..e68a00d --- /dev/null +++ b/mapcell.cpp @@ -0,0 +1,20 @@ +#include "mapcell.h" +QImage Mapcell::blockimage=QImage(":/images/images/map_block.bmp"); + +Mapcell::Mapcell() +{ + +} + +void Mapcell::Display(QPainter &paint){ + +if(!this->IsDisappear()) +paint.drawImage(m_rectSphere,blockimage,QRect(0,0,PICWIDTH,PICHEIGHT)); +//paint.drawImage(m_rectSphere,QImage(":/images/images/map_block.bmp"),QRect(0,0,PICWIDTH,PICHEIGHT));优化代码,速度飞一般 + +} +void Mapcell::Move(){ + + + +} diff --git a/mapcell.h b/mapcell.h new file mode 100644 index 0000000..fa3b0a8 --- /dev/null +++ b/mapcell.h @@ -0,0 +1,34 @@ +#ifndef MAPCELL_H +#define MAPCELL_H + +#include"wanwu.h" +#include"main.h" +class Mapcell : public Wanwu +{ +public: + + Mapcell(); + Mapcell(int iIndex,int jIndex){ + + + this->m_pos.setX(jIndex*CELLWIDTH+CELLWIDTH/2); + this->m_pos.setY(iIndex*CELLHEIGHT+CELLHEIGHT/2); + this->CalculateSphere(); + + } + // 绘图 + void Display(QPainter &paint); + + // 移动 + void Move(); +private: +static QImage blockimage; +void CalculateSphere(){ + this->m_rectSphere.setRect(m_pos.x()-CELLWIDTH/2,m_pos.y()-CELLHEIGHT/2,CELLWIDTH,CELLHEIGHT); + +} + + +}; + +#endif // MAPCELL_H diff --git a/mytank.qrc b/mytank.qrc new file mode 100644 index 0000000..a6347e5 --- /dev/null +++ b/mytank.qrc @@ -0,0 +1,17 @@ + + + images/background.bmp + images/bullet.bmp + images/fire.bmp + images/map_block.bmp + images/player_tank.bmp + + + sounds/death.wav + sounds/hit.wav + sounds/motor.wav + sounds/shoot.wav + sounds/start.wav + sounds/turret.wav + + diff --git a/object.cpp b/object.cpp new file mode 100644 index 0000000..bb96194 --- /dev/null +++ b/object.cpp @@ -0,0 +1,7 @@ +#include "object.h" + +MyObject::MyObject() +{ + +} + diff --git a/object.h b/object.h new file mode 100644 index 0000000..a24f84e --- /dev/null +++ b/object.h @@ -0,0 +1,37 @@ +#ifndef OBJECT_H +#define OBJECT_H +#include +#include +enum Dir { UP, DOWN, LEFT, RIGHT }; + +class MyObject +{ +public: + // 绘图 + virtual void Display() = 0; + + // 移动 + virtual void Move() = 0; + + // 判断是否消失 + virtual bool IsDisappear() = 0; + +protected: + // 计算势力范围 + virtual void CalculateSphere() = 0; + + // 位置 + Point m_pos; + // 势力范围 + Rect m_rectSphere; + // 颜色 + COLORREF m_color; + // 方向 + Dir m_dir; + // 存在状态 + bool m_bDisappear; + // 单次前进步长 + int m_step; +}; + +#endif // OBJECT_H diff --git a/tank.cpp b/tank.cpp new file mode 100644 index 0000000..c7e85b3 --- /dev/null +++ b/tank.cpp @@ -0,0 +1,7 @@ +#include "tank.h" + +Tank::Tank() +{ + +} + diff --git a/tank.h b/tank.h new file mode 100644 index 0000000..6e79d3d --- /dev/null +++ b/tank.h @@ -0,0 +1,10 @@ +#ifndef TANK_H +#define TANK_H +#include"wanwu.h" +class Tank : public Wanwu +{ +public: + Tank(); +}; + +#endif // TANK_H diff --git a/wanwu.cpp b/wanwu.cpp new file mode 100644 index 0000000..70fa239 --- /dev/null +++ b/wanwu.cpp @@ -0,0 +1,11 @@ +#include "wanwu.h" + +bool Wanwu::IsBoom(const Wanwu &wanwu)const{ +bool isok=true; +if(wanwu.m_rectSphere.left()>m_rectSphere.right() +||wanwu.m_rectSphere.right()m_rectSphere.top()) +isok=false; + +return isok; +} + diff --git a/wanwu.h b/wanwu.h new file mode 100644 index 0000000..f8b3857 --- /dev/null +++ b/wanwu.h @@ -0,0 +1,53 @@ +#ifndef WANWU_H +#define WANWU_H +#include +#include +#include +enum Dir { UP, DOWN, LEFT, RIGHT }; +class Wanwu +{ + protected: + // 计算势力范围 + virtual void CalculateSphere() = 0; + + // 位置 + QPoint m_pos; + // 势力范围 + QRect m_rectSphere; + // 颜色 + //QColor m_color; + // 方向 + Dir m_dir; + // 存在状态 + bool m_bDisappear; + // 单次前进步长 + int m_step; + //生命值 + float life; + //护甲 + float hujia; + //魔抗 + float mokang; + //物理攻击 + float wuli; + //法术攻击 + float fashu; + + public: + Wanwu(){}; + // 绘图 + virtual void Display(QPainter &paint) = 0; + + // 移动 + virtual void Move() = 0; + + // 判断是否消失 + bool IsDisappear(){return m_bDisappear;} + + //判断两物体是否碰撞 + bool IsBoom(const Wanwu &wanwu)const; + // + void SetDisappear(bool tmp){m_bDisappear=tmp;} +}; + +#endif // WANWU_H