QtでTower Defenceゲームを作成しています。 私の塔は叫んで弾丸クラスを産んでいます。この弾丸のクラスで 弾丸に触れる敵がありますなら、私に検出することができますその周りのポリゴンがある:Qt QGraphicsItemからクラスを呼び出す
QList<QGraphicsItem*> colliding_items=collidingItems();
for(int i=0,n=colliding_items.size();i<n;i++){
if(typeid(*(colliding_items[i]))==typeid(Enemy))
{
//<------------ HERE ?
scene()->removeItem(this);
delete this;
return;
}
}
私はreceiveDamage(int damage)
というヘッダーファイルEnemy.h
内の関数を作成:
void Enemy::reciveDamage(int damage){
m_health -= damage;
if(m_health <= 0){
game->scene->removeItem(this);
delete this;
return;
}
}
Ennemy.h
の内容:
#ifndef ENEMY_H
#define ENEMY_H
#include <QGraphicsPixmapItem>
#include <QObject>
#include <QList> // list << element
#include <QPointF>
class Enemy: public QObject, public QGraphicsPixmapItem{
Q_OBJECT
public:
Enemy(QGraphicsItem * parent=0);
void rotateToPoint(QPointF p);
void reciveDamage(int damage);
public slots:
void move_forward();
private:
QList<QPointF> points;
QPointF dest;
int point_index;
int m_speed = 2;
int m_health = 100;
};
#endif // ENEMY_H
しかし、私はTHERアップ私のコードでそれを呼び出す方法がわかりません電子、任意のアイデア? Enemy
クラスに
あなたのコードスニペットの例:スコープ(一部の詳細およびコンテキストを与える、としてくださいあなたの敵のクラスの定義) – Dreamcooled