当前位置: 首页>>代码示例>>C++>>正文


C++ Gun类代码示例

本文整理汇总了C++中Gun的典型用法代码示例。如果您正苦于以下问题:C++ Gun类的具体用法?C++ Gun怎么用?C++ Gun使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Gun类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fin

GunManager::GunManager(){
   Gun gun;

   std::ifstream fin("gun.dat", std::ofstream::binary);
   while (fin.read((char *)&gun, sizeof(Gun))){   // lê do arquivo 
      gunVector.push_back(gun);

      int id = gun.getId();

      std::string buffer;
      if(id == 1){
         buffer = "audio/machete.wav";
      }else if(id == 2){
         buffer = "audio/colt_shot.wav";
      }else if(id == 3){
         buffer = "audio/luger_shot.wav";
      }else if(id == 4){
         buffer = "audio/mouser_shot.wav";
      }else if(id == 5){
         buffer = "audio/winchester_shot.wav";
      }else if(id == 6){
         buffer = "audio/hotchkiss_shot.wav";
      }

      gunAudio.push_back(buffer);
   }
   fin.close();
}
开发者ID:rpaggi,项目名称:farolete,代码行数:28,代码来源:GunManager.cpp

示例2: copyData

//------------------------------------------------------------------------------
// copyData(), deleteData() -- copy (delete) member data
//------------------------------------------------------------------------------
void Gun::copyData(const Gun& org, const bool cc)
{
   BaseClass::copyData(org);

   if (cc) {
      bullet = nullptr;
   }

   if (org.getBulletType() != nullptr) {
      Bullet* b = org.getBulletType()->clone();
      setBulletType( b );
      b->unref();
   }
   else setBulletType(nullptr);

   armed = org.armed;

   burstFrameTimer = org.burstFrameTimer;
   burstFrameTime = org.burstFrameTime;
   rcount = org.rcount;

   fire = org.fire;
   unlimited = org.unlimited;

   shortBurstTimer = org.shortBurstTimer;
   shortBurstTime  = org.shortBurstTime;

   rounds = org.rounds;
   initRounds = org.initRounds;

   rpm = org.rpm;
}
开发者ID:jaegerbomb,项目名称:OpenEaagles,代码行数:35,代码来源:Guns.cpp

示例3: if

void HUD::update(float frameTime, InventoryItem* const &item, Player* player) {
	currentItem = item->getItem();
	currentPlayer = player;
	Gun* gun = dynamic_cast<Gun*>(currentItem);
	if (gun != 0) {
		if (gun->getGunId() == Gun::ItemType::pistol) {
			currentItemImage->setCurrentFrame(gunNS::PISTOL_FRAME);
		} else if (gun->getGunId() == Gun::ItemType::machineGun) {
			currentItemImage->setCurrentFrame(gunNS::MACHINEGUN_FRAME);
		} else if (gun->getGunId() == Gun::ItemType::shotGun) {
			currentItemImage->setCurrentFrame(gunNS::SHOTGUN_FRAME);
		} else { // For testing purposes
			currentItemImage->setCurrentFrame(10);
		}
	}
	RECT r = hp->getSpriteDataRect();
	//percentage of player hp / width of image
	r.right = player->getHealth() / player->getMaxHP() * hp->getWidth();
	hp->setSpriteDataRect(r);
	currentItemImage->update(frameTime);
	gunHud->update(frameTime);
	hpHUD->update(frameTime);
	hp->update(frameTime);
	pointHud->update(frameTime);
}
开发者ID:Capeguy,项目名称:GPAssignment2,代码行数:25,代码来源:hud.cpp

示例4: Gun

Gun* Gun::create(const std::string& name)
{
    Gun* ret = new Gun();
    if (ret && ret->init(name))
    {
        ret->autorelease();
        return ret;
    }
    delete ret;
    return nullptr;
}
开发者ID:Teivaz,项目名称:CocosSampleGame,代码行数:11,代码来源:Gun.cpp

示例5: callBack

/*********************************************
* CALLBACK
* The main interaction loop of the engine.
* This gets called from OpenGL.  It give us our
* interface pointer (where we get our events from)
* as well as a void pointer which we know is our
* game class.
*********************************************/
void callBack(const Interface *pUI, void *p)
{
	// we know the void pointer is our game class so
	// cast it into the game class.
	Gun *pGun = (Gun *)p;

	// check the paddle
	pGun->move(pUI->isUp(), pUI->isDown());

	// draw it
	pGun->draw();
}
开发者ID:KatelynJean,项目名称:Skeet,代码行数:20,代码来源:gunTest.cpp

示例6: Gun

Gun* Gun::createWithLevel(int _level){
	Gun *gun = new Gun();

	if (gun && gun->init())
	{
		gun->setLevel(_level);

		gun->autorelease();
		return gun;
	}
	CC_SAFE_DELETE(gun);
	return nullptr;
}
开发者ID:phpxin,项目名称:CatchFish,代码行数:13,代码来源:Gun.cpp

示例7: location

void GunFactory::createBlaster(){
	sf::Vector2f location(0,0);
	Gun* gunPtr = new Gun(location, 12, this->fSI);
	this->fSI->model->guns->push_back(gunPtr);

	GunView* gunViewPtr = new GunView(this->fSI->window, this->fSI->assets, gunPtr);
	this->fSI->view->views->push_back(gunViewPtr);

	// Now let's center this Gun
	location.x = (this->fSI->model->game->getWidth() - gunPtr->getSize().getWidth())/2;
	location.y = this->fSI->model->game->getHeight() - gunPtr->getSize().getHeight();
	gunPtr->move(location);
}
开发者ID:rubenvanassche,项目名称:Space-Invaders,代码行数:13,代码来源:GunFactory.cpp

示例8: draw

void Player::draw() {
	Image::draw();
	Item* activeItem = inventory->getActiveItem()->getItem();
	if (activeItem->getItemType() == Item::Equipable) {
		Gun* gun = (Gun*)activeItem;
		gun->draw();
	}
	OSD::instance()->addLine("Player is at (" + std::to_string(topLeft.x) + ", " + std::to_string(topLeft.y) + ") Can Jump: " + std::to_string(canJump) + " | Can Fall: " + std::to_string(canFall) + " | Jumping: " + std::to_string(jumping) + " | Falling: " + std::to_string(falling));
	OSD::instance()->addLine("(" + std::to_string(int(topLeft.x)) + ", " + std::to_string(int(topLeft.y)) + ") ---- (" + std::to_string(int(topRight.x)) + ", " + std::to_string(int(topRight.y)) + ")");
	OSD::instance()->addLine("     |     ----     |  ");
	OSD::instance()->addLine("(" + std::to_string(int(bottomLeft.x)) + ", " + std::to_string(int(bottomRight.y)) + ") ---- (" + std::to_string(int(bottomRight.x)) + ", " + std::to_string(int(bottomRight.y)) + ")");

}
开发者ID:Capeguy,项目名称:GPAssignment2,代码行数:13,代码来源:player.cpp

示例9: draw

void HUD::draw() {
	gunHud->draw();
	currentItemImage->draw();
	hpHUD->draw();
	hp->draw();
	pointHud->draw();
	if (currentItem != nullptr && currentItem->getItemType() == Item::Equipable) {
		Gun* gun = (Gun*)currentItem;
		ammoFont->print("X (" + gun->getAmmoDisplay() + ") ", currentItemImage->getX() + 100, currentItemImage->getY() + 8);
	}
	if (currentPlayer != nullptr) {
		ammoFont->print("Carnage: " + std::to_string(currentPlayer->getTotalPoints()), pointHud->getX() + 20, pointHud->getY() + 15);
	}
}
开发者ID:Capeguy,项目名称:GPAssignment2,代码行数:14,代码来源:hud.cpp

示例10: printf

void IFSMCowFindGun::Calculate(MovingEntity* entity, Instance* instance){

	Gun* target = instance->GetGun();
	if (entity->GetPosition().DistanceBetween(target->GetPosition()) <= CATCH_DISTANCE)
	{
		//switch states
		printf("[Cow] found the Gun!\n");
		entity->SetState(new IFSMCowHide());
		instance->ResetEntities(false, false, false, true);
		return;
	}

	Vector2D newHeading = (target->GetPosition() - entity->GetPosition());
	newHeading.Normalize();

	entity->SetHeading(newHeading);
	entity->Move(0.0f);

}
开发者ID:Gijs-W,项目名称:kmint1,代码行数:19,代码来源:IFSMCowFindGun.cpp

示例11: getGun

//------------------------------------------------------------------------------
// Manage the trigger switch event
//------------------------------------------------------------------------------
bool SimpleStoresMgr::onTriggerSwEvent(const base::Boolean* const sw)
{
   Gun* g = getGun(); // Get the primary gun
   if (g != nullptr) {

      // Single Burst?
      bool burst = (sw == nullptr);

      // Firing?
      bool fire = false;
      if ( isWeaponDeliveryMode(A2A) || isWeaponDeliveryMode(A2G) ) {
         if ( burst ) fire = true;
         else fire = sw->getBoolean();
      }

      // Pass the control to the gun
      g->fireControl(fire, burst);
   }

   return true;
}
开发者ID:wangfeilong321,项目名称:OpenEaagles,代码行数:24,代码来源:StoresMgr.cpp

示例12: main

int main()
{
   srand(time(NULL));

   int nBullets = 5;
   int nChambers = 73;
   int numGuns = 1000;
   int numTrials = 1000;

   vector<int> results;
   for (int i = 0; i < numGuns; ++i)
   {
      Gun* currGun = new Gun(nBullets, nChambers);
      for (int j = 0; j < numTrials; ++j)
      {
         results.push_back(currGun->PullTrigger());
      }
      delete currGun;
   }

   cout << "Average probability to survive is " << 1.0*accumulate(results.begin(), results.end(), 0) / results.size();
   
   return 0;
}
开发者ID:nkersting,项目名称:Code,代码行数:24,代码来源:russian.cpp

示例13: getStoresManagement

void LifeForm::fire()
{
    Basic::Number* hdgObj = new Basic::Number(getHeadingR());
    Basic::Number* pitchObj = new Basic::Number(lookAngle * Basic::Angle::D2RCC);
    StoresMgr* mgr = getStoresManagement();
    if (mgr != nullptr) {
        if (getSimulation() != nullptr) {
            if (weaponSel == LF_MISSILE) {
                mgr->setGunSelected(false);
                Missile* missile = mgr->getNextMissile();
                if (missile != nullptr) {
                    missile->setSlotInitPitch(pitchObj);
                    missile->setSlotInitHeading(hdgObj);
                    missile->reset();
                    Missile* msl = mgr->releaseOneMissile();
                    if (msl != nullptr) {
                        if (tgtAquired && tgtPlayer != nullptr) msl->setTargetPlayer(tgtPlayer, true);
                    }
                }
            }
            else if (weaponSel == LF_GUN) {
                mgr->setGunSelected(true);
                Gun* myGun = mgr->getGun();
                if (myGun != nullptr) {
                    myGun->setGunArmed(true);
                    Basic::Number* num = new Basic::Number(lookAngle * Basic::Angle::D2RCC);
                    myGun->setSlotPitch(num);
                    num->unref();
                    myGun->fireControl(true);
                }
           }
        }
    }
    hdgObj->unref();
    pitchObj->unref();
}
开发者ID:derekworth,项目名称:afit-swarm-simulation,代码行数:36,代码来源:LifeForms.cpp

示例14: Gun

Gun* WeaponStore::PickUp(const char *name, int bullet){
	Gun* tGun = myFactory->GetGun(name);
	Gun* newGun = new Gun(*tGun);
	newGun->Load(bullet);
	return newGun;
}
开发者ID:mjaimin,项目名称:C---Design-Patterns-Examples,代码行数:6,代码来源:Flyweight.cpp

示例15: main

int main()
{
	init();

	resetTicks();

	bool end = false;
	list<Thing*>::iterator it;

	Gun *gun = new Gun();
	Scoreboard *sb = new Scoreboard();

	level = 4.0;
	int prev_button = 0;

	while(!end)
	{
		if (ticks > 0)
		{
			while(ticks-- > 0)
			{
				if (randomFloat(0, 48 - level) < 1.0)
				{
					if (randomInt(0, 15) == 0)
						world.push_back(new Bonus(randomInt(20, 620), level * randomFloat(0.99, 1.05)));
					else
						world.push_back(new Baddie(randomInt(20, 620), level * randomFloat(0.99, 1.05)));
				}

				for(it = world.begin(); it != world.end(); it++)
					(*it)->update();

				for(it = world.begin(); it != world.end();)
				{
					if (!(*it)->isAlive())
					{
						delete (*it);
						it = world.erase(it);
					}
					else
					{
						it++;
					}
				}
				gun->update();

				if (key[KEY_ESC])
				{
					end = true;
				}
				end |= (hp <= 0);

				level += 0.0012;

				if ((mouse_b == 1) && (mouse_b != prev_button) && (ammo > 0))
				{
					ammo--;
					for(it = world.begin(); it != world.end(); it++)
						(*it)->shootAt(mouse_x, mouse_y);
				}
				if ((mouse_b == 2) && (mouse_b != prev_button))
				{
					ammo = 6;
					score -= 250;
				}

				prev_button = mouse_b;
			}
		}

		clear_bitmap(buffer);
		for(it = world.begin(); it != world.end(); it++)
			(*it)->draw();
		gun->draw();
		sb->draw();

		blit(buffer, screen, 0, 0, 0, 0, 640, 480);
	}

	clear_bitmap(screen);
	textprintf_centre_ex(screen, font, 320, 220, makecol(255, 0, 0), -1, "G A M E    O V E R");
	textprintf_centre_ex(screen, font, 320, 240, makecol(255, 255, 255), -1, "Final score: %d", score);
	textprintf_centre_ex(screen, font, 320, 260, makecol(255, 255, 0), -1, "Press both mouse buttons to exit");

	while (mouse_b);
	while (mouse_b != 3);

	destroy();
}
开发者ID:Bencepapa,项目名称:CymonsGames,代码行数:89,代码来源:baddie.cpp


注:本文中的Gun类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。