You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
#include "Collision.h"
|
|
#include "gamedefine.h"
|
|
|
|
QMutex mutex;
|
|
|
|
EnemyCollision::EnemyCollision(QObject* parent) : QObject(parent), mPlayer(nullptr), mEnemyList(nullptr) {
|
|
|
|
}
|
|
|
|
EnemyCollision::~EnemyCollision(){
|
|
|
|
}
|
|
|
|
void EnemyCollision::setupCollision(Player* player, QList<EnemyBase*> *enemyList) {
|
|
mPlayer = player;
|
|
mEnemyList = enemyList;
|
|
}
|
|
|
|
void EnemyCollision::player_enemyCollision(Player &mPlayer,QList<EnemyBase*> &mEnemyList)
|
|
{
|
|
QMutexLocker locker(&mutex);
|
|
if(mPlayer.isInvincible) emit EnemyCollisionFinished("return");//判断无敌
|
|
int enemyNum = mEnemyList.size();
|
|
for(int i=0;i<enemyNum;i++)
|
|
{
|
|
if(mPlayer.collidesWithItem(mEnemyList[i]))
|
|
{
|
|
mPlayer.getHurt(mEnemyList[i]->getAttackPoint());
|
|
emit EnemyCollisionFinished("hurt");
|
|
if(mPlayer.getHP() <= 0)//死亡
|
|
{
|
|
emit EnemyCollisionFinished("dead");
|
|
}
|
|
emit EnemyCollisionFinished("Invincibletime");
|
|
}
|
|
}
|
|
}
|
|
|
|
void EnemyCollision::processCollisions() {
|
|
if (!mPlayer || !mEnemyList) return;
|
|
player_enemyCollision(*mPlayer, *mEnemyList);
|
|
}
|