COLL_RET Bullet::onCollision(cocos2d::Node *other) { const int otherTag = other->getTag(); if (otherTag == COLL_TILE_GRASS || otherTag == COLL_TILE_WATER || otherTag == COLL_REBIRTH || otherTag == COLL_AWARDS) return RETAIN; if (COLL_EDGE_BOTTOM == otherTag ||COLL_EDGE_LEFT == otherTag ||COLL_EDGE_RIGHT == otherTag ||COLL_EDGE_TOP == otherTag) { return DESTROY; } if (COLL_BULLET == _tag || COLL_BULLET_IRON == _tag) { if (otherTag != COLL_FELLOWS &&otherTag != COLL_BULLET &&otherTag != COLL_BULLET_IRON) { ParticleSystemQuad * particle = ParticleSystemQuad::create("bullet_exp.plist"); Sprite *tmpSprite = Sprite::createWithSpriteFrameName("bullet_exp.png"); tmpSprite->setVisible(false); particle->setTextureWithRect(tmpSprite->getTexture(), tmpSprite->getTextureRect()); particle->addChild(tmpSprite); particle->setScale(0.05f); particle->setPosition(this->getPosition()); this->getParent()->addChild(particle, 2); particle->setAutoRemoveOnFinish(true); return DESTROY; } } else if (COLL_BULLET_ENEMIES == _tag) { if (otherTag != COLL_ENEMIES && otherTag != COLL_BULLET_ENEMIES) { ParticleSystemQuad * particle = ParticleSystemQuad::create("bullet_exp.plist"); Sprite *tmpSprite = Sprite::createWithSpriteFrameName("bullet_exp.png"); tmpSprite->setVisible(false); particle->setTextureWithRect(tmpSprite->getTexture(), tmpSprite->getTextureRect()); particle->addChild(tmpSprite); particle->setScale(0.05f); particle->setPosition(getPosition()); this->getParent()->addChild(particle, 2); particle->setAutoRemoveOnFinish(true); return DESTROY; } } return RETAIN; }
void TankStateBullet::fire() { int starNum = _tankSprite->getBulletAwardNum(); if (_tankSprite->CanFire() && _tankSprite->getBulletNum() < 2){ CCLOG("TankNode sprite fire"); if (starNum >= 2) { CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(FileUtils::getInstance()->fullPathForFilename("audio/btndir.wav").c_str()); _tankSprite->setBulletSpeed(_bulletSpeedBackup * 2.0f); if (3 == starNum) { _tankSprite->setBulletTag(NodeWithCollision::COLL_BULLET_IRON); } } else{ CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(FileUtils::getInstance()->fullPathForFilename("audio/bullet.wav").c_str()); } Bullet *norBullet = Bullet::create(MAPDATA->getCollDetector(), _tank); _tankSprite->getParent()->addChild(norBullet, -1); ParticleSystemQuad * particle = ParticleSystemQuad::create("bullet_smoke.plist"); Sprite *tmpSprite = Sprite::createWithSpriteFrameName("bullet_smoke.png"); tmpSprite->setVisible(false); particle->setTextureWithRect(tmpSprite->getTexture(), tmpSprite->getTextureRect()); particle->addChild(tmpSprite); particle->setScale(0.2f); particle->setPosition(norBullet->getPosition()); _tank->getParent()->addChild(particle, 2); particle->setAutoRemoveOnFinish(true); _tankSprite->insertBullet(norBullet); } }
void TankState::fire() { if (_tank->CanFire() && 0 == _tank->getBulletNum()){ CCLOG("TankNode sprite fire"); Bullet *norBullet = Bullet::create(MAPDATA->getCollDetector(), _tank); _tank->getParent()->addChild(norBullet, -1); ParticleSystemQuad * particle = ParticleSystemQuad::create("bullet_smoke.plist"); Sprite *tmpSprite = Sprite::createWithSpriteFrameName("bullet_smoke.png"); tmpSprite->setVisible(false); particle->setTextureWithRect(tmpSprite->getTexture(), tmpSprite->getTextureRect()); particle->addChild(tmpSprite); particle->setScale(0.2f); particle->setPosition(norBullet->getPosition()); //particle->setAnchorPoint(ccp(0.5, 0.5)); _tank->getParent()->addChild(particle, 2); particle->setAutoRemoveOnFinish(true); _tank->insertBullet(norBullet); if (_tank->getTag() == NodeWithCollision::COLL_FELLOWS){ CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(FileUtils::getInstance()->fullPathForFilename("audio/bullet.wav").c_str()); } } }