/********************************************************************* ** 功能: 碰撞检测 ** 输入参数: float dt: 延时销毁的时间 ** 返回值: 无 ** 修改记录: *********************************************************************/ void FlightProp::PropCollisionDetective(float dt) { if (NULL == _owner) /* 无施放者死亡或未设置施放者 */ { releaseCallBack(); return; } auto roles = UserData::getInstance()->getRoles(); auto rcA = this->getBoundingBox(); auto ownerInfo = _owner->getRoleInfo(); if (RoleStatus_Death == ownerInfo.status) /* 施放者死亡 */ { releaseCallBack(); return; } bool bHit = false; auto ptLoc = Point(this->getPositionX(), this->getPositionY() - m_fHeight);/* 实际坐标需扣除高度 */ this->setLocalZOrder(_owner->getLocalZOrder()); for(unsigned int index = 0;index < roles.size();index ++) /* 敌人角色遍历获取 */ { auto role = (Role *)roles[index]; auto info = role->getRoleInfo(); if ((RoleStatus_Invincible == info.status) || (RoleStatus_Death == info.status) || (ownerInfo.camp == info.camp) || (_owner->getSceneID() != role->getSceneID())) { continue; /* 无敌、同阵营、死亡或是自身不处理 */ } auto rcB = Rect(role->getPositionX() - 10, role->getPositionY() + 20, 20, 40); /* 有效区域 */ if (true == rcB.intersectsRect(rcA)) /* 碰撞 */ { auto ptOffset = role->getPosition() - ptLoc; if (m_stPropInfo.skillInfo.yAtkDis >= abs(ptOffset.y)) /* 动作有效范围判断 */ { bHit = true; role->roleHurt(_owner, m_stPropInfo.skillInfo, m_bDown); } } } if (true == bHit) { releaseWithDelay(dt); } }
void TimeBaseCallBack::initCallBack(TimeBase *tb, CallBackType type) { releaseCallBack(); _timeBase = tb; _timeBase->addCallBack(this); _type = type; }
/********************************************************************* ** 功能: 碰撞检测 ** 输入参数: ** 返回值: ** 修改记录: *********************************************************************/ void EnergyBall::PropCollisionDetective() { if (false == m_bCollision) /* 还不到检测时候 */ { return; } if (NULL == _owner) /* 无施放者死亡或未设置施放者 */ { releaseCallBack(); return; } auto ownerInfo = _owner->getRoleInfo(); if (RoleStatus_Death == ownerInfo.status) /* 施放者死亡 */ { releaseCallBack(); return; } auto roles = UserData::getInstance()->getRoles(); if (0 == roles.size()) /* 没有角色(预览模式) */ { releaseCallBack(); return; } if (RoleStatus_Death == m_Role->getRoleInfo().status) /* 选中的角色死亡,另选角色 */ { energyBallSearchObject(); } else { auto ptRole = m_Role->getPosition(); ptRole.y = ptRole.y + m_fHeight; /* 修正目标点为角色身体 */ auto ptOffset = ptRole - this->getPosition(); this->setPosition(this->getPosition() + ptOffset / ptOffset.getLength() * EnergyBallMoveSpeed * 0.4f); } bool bCollision = false; auto rcA = this->getBoundingBox(); auto rcB = Rect(m_Role->getPositionX() - 10, m_Role->getPositionY() + 20, 20, m_fHeight); /* 有效区域 */ if (true == rcB.intersectsRect(rcA)) { bCollision = true; auto info = m_Role->getRoleInfo(); if (ownerInfo.camp == info.camp) /* 对己补给 */ { m_Role->setRoleHpUp(m_stPropInfo.skillInfo.damage); } else /* 对敌伤害 */ { m_Role->roleHurt(_owner, m_stPropInfo.skillInfo, m_bDown); } } if (true == bCollision) { releaseWithDelay(m_fStay); } }
TimeBaseCallBack::~TimeBaseCallBack() { releaseCallBack(); }