17 Star 30 Fork 22

zhouxiang / air_plane

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
flyer.h 2.89 KB
一键复制 编辑 原始数据 按行查看 历史
zhouxiang 提交于 2013-09-16 18:58 . 添加注释
#ifndef FLYER_H
#define FLYER_H
#include <QGraphicsObject>
#include <QGraphicsScene>
#include <QDebug>
#include "global.h"
/**
* @brief The Flyer class 飞行物体的基类
*/
class Flyer : public QGraphicsObject
{
Q_OBJECT
public:
Flyer(uint speed, QGraphicsScene *scene, QGraphicsItem *parent = 0):QGraphicsObject(parent),
m_speed(speed){
scene->addItem(this);
}
virtual ~Flyer() {}
/**
* @brief fly 对飞行轨迹的描述,自动
*/
virtual void autofly() = 0;
/**
* @brief advance
* This virtual function is called twice for all items
* by the QGraphicsScene::advance() slot. In the first phase,
* all items are called with phase == 0,
* indicating that items on the scene are about to advance,
* and then all items are called with phase == 1.
* Reimplement this function to update your item if you need simple scene-controlled animation.
*/
virtual void advance(int /*phase*/) {
}
/**
* @brief reinit 重新init
*/
virtual void reinit() {
}
void setSpeed(uint speed);
/**
* @brief posLost 当checkpos失败时,物体就要从场景中取出来,缓存起来,重新初始化后再使用
*/
virtual void posLost() {
setVisible(false);
deleteLater();
}
/**
* @brief name 用来标识类,在类转换时使用
* @return
*/
virtual int name() const = 0;
/**
* @brief doCollide 处理与本item碰撞的项
* @param list
*/
virtual void doCollide() = 0;
/**
* @brief fall 坠落
*/
virtual void fall(){
setFlag(QGraphicsItem::ItemIsMovable, false);
setFlag(QGraphicsItem::ItemIsFocusable, false);
//emit sig_fall();
}
signals:
void sig_fall();
protected:
typedef enum{Front, Behind, Left, Right} CHECK_FLAG;// w s a d
/**
* @brief checkPos 检测位置,返回true在场景中可以移动
*/
bool checkPos(CHECK_FLAG flag);
/**
* @brief m_speed 移动速度
*/
uint m_speed;
};
inline //加了inline就不报错,why?
void Flyer::setSpeed(uint speed)
{
m_speed = speed;
}
/**
* @brief Flyer::checkPos
* @param flag
* @return
* @note 40 ,20 未图片的长和宽
*/
inline
bool Flyer::checkPos(CHECK_FLAG flag)
{
bool re = false;
switch (flag) {
case Front:
//比较代码
if (scenePos().ry() > 0) {
re = true;
}
break;
case Behind:
if (scenePos().ry() < scene()->height() - PIXMAPHEIGHT) {
re = true;
}
break;
case Left:
if (scenePos().rx() > 0) {
re = true;
}
break;
case Right:
if (scenePos().rx() < scene()->width() - PIXMAPWEIGHT) {
re = true;
}
break;
default:
break;
}
return re;
}
#endif // FLYER_H
C++
1
https://gitee.com/zhouX/air_plane.git
git@gitee.com:zhouX/air_plane.git
zhouX
air_plane
air_plane
master

搜索帮助