Exemplo n.º 1
0
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();
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------
// 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;
}
Exemplo n.º 3
0
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);
}
Exemplo n.º 4
0
Gun* Gun::create(const std::string& name)
{
    Gun* ret = new Gun();
    if (ret && ret->init(name))
    {
        ret->autorelease();
        return ret;
    }
    delete ret;
    return nullptr;
}
Exemplo n.º 5
0
/*********************************************
* 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();
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
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)) + ")");

}
Exemplo n.º 9
0
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);
	}
}
Exemplo n.º 10
0
	void Shut()
	{
		if(pistol==NULL)
			cout<<"Hut BBANG!"<<endl;
		else
			pistol->Shut();
	}
Exemplo n.º 11
0
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);

}
Exemplo n.º 12
0
//------------------------------------------------------------------------------
// 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;
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
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();
}
Gun* WeaponStore::PickUp(const char *name, int bullet){
	Gun* tGun = myFactory->GetGun(name);
	Gun* newGun = new Gun(*tGun);
	newGun->Load(bullet);
	return newGun;
}
Exemplo n.º 16
0
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();
}
Exemplo n.º 17
0
void Airplane::Fire(unsigned int gun)
{
	assert(gun < guns.size());
	Gun *g = guns[gun];
	g->AttemptToFire();
}
Exemplo n.º 18
0
void Player::update(float frameTime, LevelController* lc) {
	// 1-Press NoClip
	if (noClipButtonReleased && input->isKeyDown(VK_F2)) {
		noClip = !noClip;
		noClipButtonReleased = false;
	} else {
		noClipButtonReleased = true;
	}
	velocityX = getVelocity().x;
	velocityY = getVelocity().y;
	// Handle NoClip
	if (noClip) {
		if (input->isKeyDown(PLAYER_RIGHT)) {
			velocityX = playerNS::NOCLIP_SPEED * frameTime;
			orientation = Right;
		} else if (input->isKeyDown(PLAYER_LEFT)) {
			velocityX = -playerNS::NOCLIP_SPEED * frameTime;
			orientation = Left;
		} else {
			velocityX = 0;
		}
		if (input->isKeyDown(PLAYER_UP)) {
			velocityY = -playerNS::NOCLIP_SPEED * frameTime;
			orientation = Up;
		} else if (input->isKeyDown(PLAYER_DOWN)) {
			velocityY = playerNS::NOCLIP_SPEED * frameTime;
			orientation = Down;
		} else {
			velocityY = 0;
		}
		velocity = VECTOR2(velocityX, velocityY);
		frameDelay = 1000000;
		Item* activeItem = inventory->getActiveItem()->getItem();
		if (inventory->getActiveItem()->getItem()->getItemType() == Item::Equipable) {
			Gun* gun = dynamic_cast<Gun*>(activeItem);
			if (gun != 0) {
				gun->update(frameTime, orientation, getX(), getY(), input, lc);
			}
		}
		Entity::update(frameTime);
		return;
	}
	// Set Obj Vars
	levelController = lc;
	// Debug Messages
	OSD::instance()->addLine("Jump Distance: " + std::to_string(jumpdistance) + " / " + std::to_string(playerNS::JUMP_HEIGHT));
	OSD::instance()->addLine("Can | Left: " + std::to_string(canMoveLeft(true)) + " | Right: " + std::to_string(canMoveRight(true)) + " | Up: " + std::to_string(canMoveUp(true)) + " | Down: " + std::to_string(canMoveDown(true)));
	// Stuck Hotfix
	if (!canMoveLeft() && !canMoveRight() && !canMoveUp() && !canMoveDown()) {
		setX(spawnPos.x);
		setY(spawnPos.y);
	}
	// Update Guns
	inventory->update(frameTime, input);
	// Boss Audio
	if (lc->getMapX() * -1.0 > 1900) {
		audio->stopCue(BK_MUSIC);
		audio->playCue(BOSS_MUSIC);
	}

	// Start of Player Movement
	if (healthStatus != Dead) {
		if (!canMoveDown()) {
			if (!input->isKeyDown(PLAYER_UP) && !input->isKeyDown(PLAYER_JUMP))
				canJump = true;
			canFall = false;
			falling = false;
		} else {
			canFall = true;
			falling = true;
		}
		// Move Left and Right
		if (input->isKeyDown(PLAYER_RIGHT) && canMoveRight()) {
			velocityX = playerNS::SPEED * frameTime;
			while (!canMoveRight()) {
				spriteData.x -= 0.1;
				velocityX = 0;
			}
			orientation = Right;
		} else if (input->isKeyDown(PLAYER_LEFT) && canMoveLeft()) {
			velocityX = -playerNS::SPEED * frameTime;
			while (!canMoveLeft()) {
				spriteData.x += 0.1;
				velocityX = 0;
			}
			orientation = Left;
		} else {
			velocityX = 0;
			if (input->isKeyDown(PLAYER_UP)) {
				orientation = Up;
			}

			if (input->isKeyDown(PLAYER_DOWN)) {
				orientation = Down;
			}
		}
		// Handle Jumping
		if (jumping || (((input->isKeyDown(PLAYER_JUMP) || input->isKeyDown(PLAYER_UP)) && canMoveUp() && canJump))) {
			jumpdistance = jumpOriginY - getY();
			if (canJump && !jumping)
				jumpOriginY = getY();
			if (jumpdistance > playerNS::JUMP_HEIGHT || !canMoveUp()) {
				jumping = false;
				canJump = false;
				falling = true;
			} else {
				if (!jumping)
					velocityY = -playerNS::JUMP_SPEED * frameTime;
				else
					velocityY += 0.5 * frameTime;
				jumping = true;
				canJump = false;
			}
		}
		if (!jumping)
			jumpOriginY = getY();
		if (falling && !jumping) {
			if (canMoveDown()) {
				velocityY = playerNS::FALLING_SPEED * frameTime;
			} else {
				velocityY = 0;
			}
		}
		// Handle Stuck
		while (canMoveUp() && !canMoveDown() && !canMoveLeft() && !canMoveRight()) {
			spriteData.y -= 0.1;
		}
		while (!canMoveUp() && !canMoveDown() && !canMoveLeft() && canMoveRight()) {
			spriteData.x += 0.1;
		}
		while (!canMoveUp() && !canMoveDown() && canMoveLeft() && !canMoveRight()) {
			spriteData.x -= 0.1;
		}
		// Final Sanity Check
		if (!canMoveLeft() && velocityX < 0 || !canMoveRight() && velocityX > 0)
			velocityX = 0;
		if (!canMoveUp() && velocityY < 0 || !canMoveDown() && velocityY > 0)
			velocityY = 0;
		setVelocity(VECTOR2(velocityX, velocityY));

		// Handle Orientations
		if (input->isKeyDown(PLAYER_UP))
			orientation = Up;
		else if (input->isKeyDown(PLAYER_DOWN))
			orientation = Down;
		switch (orientation) {
		case Right:
			currentFrame = 953;
			spriteData.flipHorizontal = true;
			break;
		case Down:
			currentFrame = 954;
			break;
		case Left:
			currentFrame = 953;
			spriteData.flipHorizontal = false;
			break;
		case Up:
			currentFrame = 952;
			break;
		}

		// Draw Items
		Item* activeItem = inventory->getActiveItem()->getItem();
		if (inventory->getActiveItem()->getItem()->getItemType() == Item::Equipable) {
			Gun* gun = dynamic_cast<Gun*>(activeItem);
			if (gun != 0) {
				gun->update(frameTime, orientation, getX(), getY(), input, lc);
			}
		}
		// Crate Collision
		if (lc->collidedWithCrate() == 1 && lc->getCrateItem() != -1) {
			audio->playCue(RELOAD);
			if (lc->collidedWithCrate() == 1 && lc->getCrateItem() != -1) {
				int itemid = lc->getCrateItem();
				InventoryItem *invItem;
				std::vector<InventoryItem*>* itemList = inventory->getItems();
				switch (itemid) {
				case playerNS::ItemType::shotGun:
					shotgun = new Shotgun();
					shotgun->initialize(gameptr, 136, 41, 2, gunTexture);
					shotgun->setCurrentFrame(6);
					invItem = new InventoryItem(shotgun);
					break;
				case playerNS::ItemType::machineGun:
					machineGun = new MachineGun();
					machineGun->initialize(gameptr, 136, 41, 2, gunTexture);
					machineGun->setCurrentFrame(0);
					invItem = new InventoryItem(machineGun);
					break;
				case 3:
					break;
				}
				for (int i = 0; i < itemList->size(); i++) {
					InventoryItem *iItem = itemList->at(i);
					Item* item = iItem->getItem();
					Item* newItem = invItem->getItem();
					if (item->getItemType() == Item::Equipable && newItem->getItemType() == Item::Equipable) {
						Gun* gunInvItem = dynamic_cast<Gun*>(item);
						Gun* gunNewItem = dynamic_cast<Gun*>(newItem);
						if (gunInvItem->getGunId() == gunNewItem->getGunId()) {
							gunInvItem->addAmmo();
							lc->setCrateCollided(0);
							return; // Should this be return or break?
						}
					} else if (item->getItemType() == Item::Usable && newItem->getItemType() == Item::Usable) {
						lc->setCrateCollided(0);
						return;
					} // Should this be return or break?
				}
				inventory->addItem(invItem);
				lc->setCrateCollided(0);
				lc->setCrateItem(-1);
			}
		}
		Entity::update(frameTime);
	}
}