Projectile *Projectile::createModel(ProjectileTypes type) { Projectile *retval = new Projectile(); if (retval && retval->initModelWithType(type)) { retval->autorelease(); return retval; } CC_SAFE_DELETE(retval); return NULL; }
Projectile *Projectile::create(int projectileID, Projectile *model) { Projectile *retVal = new Projectile(); if (retVal && retVal->initWithProjectileID(projectileID, model)) { retVal->autorelease(); return retVal; } CC_SAFE_DELETE(retVal); return NULL; }
void GameWorld::AddRocket(Vehicle* shooter, Vector2D target) { Projectile* pProjectile = new Projectile_Rocket(shooter, target); pProjectile->autorelease(); // 添加进来 m_Projectiles.push_back(pProjectile); pProjectile->initWithFile("media/image/missile.png"); if (m_pUILayer) { m_pUILayer->addChild(pProjectile); } }
Projectile* Projectile::createProjectile(string filename, Vec2 p, Vec2 speed, string name) { Projectile* ob = new Projectile(); if(ob && ob->initProjectile(filename, p, speed, name)) { ob->autorelease(); return ob; } CC_SAFE_DELETE(ob); return NULL; }
Projectile* Projectile::create(Vec2 position, Vec2 direction) { Projectile* bullet = new Projectile(); if (!bullet->init()) { CC_SAFE_DELETE(bullet); return nullptr; } bullet->autorelease(); bullet->setPosition(position); bullet->setRotation(-CC_RADIANS_TO_DEGREES(direction.getAngle())); bullet->direction = direction; return bullet; }
Projectile* Projectile::create( GameCharacterAttribute& att, ProjectileTypeEnum type, void* extraInfo, int ownerId ) { Projectile* pRet = nullptr; /** * 这里是根据子弹类型通过“组装”的方式来,主要是发现采用继承的方式会出现 * 各种蛋疼的事情 */ switch (type) { case PROJECTILE_TYPE_GALAXO_BALL: // 闪电球 { // 单体攻击型 pRet = new ProjectileMonomerAttack(att, (int)extraInfo); // @_@ 装配移动引擎 pRet->setMovingPart(new ProjectileTrackMovingPart((int)extraInfo)); pRet->getMovingPart()->setRate(1800); // @_@ 装配显示部分 pRet->setShapePart(new ProjectileTypeOneShapePart("xuejingling-texiao", "atk")); break; } case PROJECTILE_TYPE_ZEUS_FLY_HAMMER: // 飞锤 { // 单体攻击 pRet = new ProjectileMonomerAttack(att, (int)extraInfo); pRet->setMovingPart(new ProjectileTrackMovingPart((int)extraInfo)); pRet->getMovingPart()->setRate(1000); pRet->setShapePart(new ProjectileTypeOneShapePart("zhousi-wuqi", "atk3", true)); break; } case PROJECTILE_TYPE_PIG_FLY_KNIFE: // 野猪飞刀 { pRet = new ProjectileMonomerAttack(att, (int)extraInfo); pRet->setMovingPart(new ProjectileTrackMovingPart((int)extraInfo)); pRet->getMovingPart()->setRate(1000); pRet->setShapePart(new ProjectileTypeOneShapePart("Pig-wuqi", "atk2", true)); break; } case PROJECTILE_TYPE_NIU_FLY_SHIELD: // 牛的飞盾 { pRet = new ProjectileMonomerAttack(att, (int)extraInfo); pRet->setMovingPart(new ProjectileTrackMovingPart((int)extraInfo)); pRet->setShapePart(new ProjectileTypeOneShapePart("Niu-wuqi", "atk2", true)); break; } case PROJECTILE_TYPE_THEIF_FLY_DAGGER: // 刺客的飞匕首 { pRet = new ProjectileMonomerAttack(att, (int)extraInfo); pRet->setMovingPart(new ProjectileTrackMovingPart((int)extraInfo)); pRet->setShapePart(new ProjectileTypeOneShapePart("Theif-wuqi", "atk2", true)); break; } default: break; } if (pRet != nullptr) { pRet->m_projectileType = type; pRet->m_ownerId = ownerId; pRet->autorelease(); // 注册到管理器中 ProjectileMgr->addProjectile(pRet); // 添加到地图上 GameMap::instance()->addProjectile(pRet); // 开始发射的表现 pRet->getShapePart()->onLaunchStart(); } return pRet; }