void Game::update(float t)
{ //碰撞检测
if (allEnemy.size()==0||allBullet.size()==0) {
return;
}
auto plane=(Plane *)this->getChildByTag(110);
//判断飞机和所有道具
for (int j=0; j<allTool.size(); j++) {
//得到第j架敌机
Tool * nowtool=allTool.at(j);
Rect br(plane->px,
plane->py,
plane->getChildByTag(10)->getContentSize().width,
plane->getChildByTag(10)->getContentSize().height);
Rect er(nowtool->tx,
nowtool->ty,
nowtool->sp->getContentSize().width,
nowtool->sp->getContentSize().height);
if (br.intersectsRect(er))
{ //碰撞检测到2个矩形相交
//判断吃到哪种道具
switch (nowtool->type) {
case 1://hp
{ plane->hp++;
int i=plane->hp-1;
auto spHp=Sprite::create("hp.png");
spHp->setTag(1000+i);
this->addChild(spHp);
spHp->setAnchorPoint(Vec2(0,1));
spHp->setPosition(Vec2(i*spHp->getContentSize().width+3*i,Director::getInstance()->getWinSize().height));
}break;
case 2://boom
{//所有敌机都销毁
while(allEnemy.size()>0) {
//得到第j架敌机
Enemy * nowEnemy=allEnemy.at(0);
Boom * boom=Boom::createBoom(2, nowEnemy->ex, nowEnemy->ey);
this->addChild(boom,10);
//增加分数
this->m_score+=300;
allEnemy.eraseObject(nowEnemy);
nowEnemy->removeFromParentAndCleanup(true);
}