Esempio n. 1
0
	void PropExplosion::Evolve(const std::vector<InputState>& /*iInputs*/, Uint32 iTimestamp, const MapConstPtr &iPresentMap, const MapPtr &iFutureMap) const
	{
		if (iTimestamp < _timeout) 
		{
			auto explosion = std::make_shared<PropExplosion>(*this);
			explosion->active = true;
		  	iFutureMap->SetEntity(explosion);
		}
		else
		{
			if (_stage == 0)
			{
				if (_willPropagate)
				{
					Propagate(iTimestamp, iPresentMap, iFutureMap);
				}
			}
			
			if (_stage < 4)
			{
				auto explosion = std::make_shared<PropExplosion>(*this);
				explosion->active = true;
				explosion->_timeout = iTimestamp + kExplosionTimer;
				explosion->_stage = explosion->_stage + 1;
				iFutureMap->SetEntity(explosion);
			}
		}
	}
Esempio n. 2
0
	void Bomb::Evolve(const std::vector<InputState>& /*iInputs*/, uint32_t iTimestamp, const MapConstPtr &iPresentMap, const MapPtr &iFutureMap) const
	{
		if (iTimestamp >= _timeout || _detonating) 
		{
			auto umpire = std::static_pointer_cast<Umpire>(iFutureMap->GetEntity(constants::UMPIRE));
			umpire->DecrementBombCount(_playerId);

			// center
			auto blast = Explosion::Create(iTimestamp, Explosion::IsoTropic);
			blast->x = x;
			blast->y = y;
			iFutureMap->SetEntity(blast);

			// outwards
			SetBlast(_strength, x, y, Explosion::Horizontal, iTimestamp, iPresentMap, iFutureMap,
				[](int i, int* x, int* y) { *x -= i; });
			SetBlast(_strength, x, y, Explosion::Vertical, iTimestamp, iPresentMap, iFutureMap,
				[](int i, int* x, int* y) { *y -= i; });
			SetBlast(_strength, x, y, Explosion::Horizontal, iTimestamp, iPresentMap, iFutureMap,
				[](int i, int* x, int* y) { *x += i; });
			SetBlast(_strength, x, y, Explosion::Vertical, iTimestamp, iPresentMap, iFutureMap,
				[](int i, int* x, int* y) { *y += i; });

			if (Mix_PlayChannel(-1, _explosionSound.get(), 0) == -1)
			{
				printlog("Mix_PlayChannel: %s\n",Mix_GetError());
			}
		}
		else
		{
			auto bomb = std::make_shared<Bomb>(*this);

			if (_nextFrameDueTime < iTimestamp)
			{
				bomb->_frameId++;
				bomb->_frameId %= 3;
				bomb->_nextFrameDueTime = iTimestamp + constants::BOMB_FRAME_UPDATE_DELAY;
			}

			iFutureMap->SetEntity(bomb);
		}
	}
Esempio n. 3
0
	void Explosion::Evolve(const std::vector<InputState>& /*iInputs*/, Uint32 iTimestamp, const MapConstPtr &iPresentMap, const MapPtr &iFutureMap) const
	{
		auto explosion = std::make_shared<Explosion>(*this);
		if (iTimestamp > _timeout) 
		{
			explosion->_stage++;
			explosion->_timeout = iTimestamp + kExplosionTimer;
		}

		if (_stage < 4)
		{
			explosion->active = true;
			iFutureMap->SetEntity(explosion);
		}
	}
Esempio n. 4
0
	void Block::Evolve(const std::vector<InputState>& /*iInputs*/, uint32_t /*iTimestamp*/, const MapConstPtr &/*iPresentMap*/, const MapPtr &iFutureMap) const
	{
		iFutureMap->SetEntity(std::make_shared<Block>(*this));		
	}
Esempio n. 5
0
	 void PropExplosion::Propagate(Uint32 iTimestamp, const MapConstPtr &iPresentMap, const MapPtr &iFutureMap) const
	 {
	 	switch(_propagation)
	 	{
	 		case IsoTropic:

 				if (CanPropagate(iPresentMap, GetX() + 1, GetY()))
 				{
 					auto explosion = std::make_shared<PropExplosion>(*this);
 					explosion->active = true;
				    explosion->_timeout = iTimestamp + kExplosionTimer;
				    explosion->SetX(GetX() + 1);
				    explosion->_propagation = Right;
				    iFutureMap->SetEntity(explosion);	  
 				}

 				if (CanPropagate(iPresentMap, GetX() - 1, GetY()))
 				{
 					auto explosion = std::make_shared<PropExplosion>(*this);
 					explosion->active = true;
				    explosion->_timeout = iTimestamp + kExplosionTimer;
				    explosion->SetX(GetX() - 1);
				    explosion->_propagation = Left;
				    iFutureMap->SetEntity(explosion);	  
 				}

				if (CanPropagate(iPresentMap, GetX(), GetY() + 1))
 				{
 					auto explosion = std::make_shared<PropExplosion>(*this);
 					explosion->active = true;
				    explosion->_timeout = iTimestamp + kExplosionTimer;
				    explosion->SetY(GetY() + 1);
				    explosion->_propagation = Down;
				    iFutureMap->SetEntity(explosion);	  
 				}

 				if (CanPropagate(iPresentMap, GetX(), GetY() - 1))
 				{
 					auto explosion = std::make_shared<PropExplosion>(*this);
 					explosion->active = true;
				    explosion->_timeout = iTimestamp + kExplosionTimer;
				    explosion->SetY(GetY() - 1);
				    explosion->_propagation = Up;
				    iFutureMap->SetEntity(explosion);	  
 				}

	 			return;

	 		case Up:

	 			if (CanPropagate(iPresentMap, GetX(), GetY() - 1))
 				{
 					auto explosion = std::make_shared<PropExplosion>(*this);
 					explosion->active = true;
				    explosion->_timeout = iTimestamp + kExplosionTimer;
				    explosion->SetY(GetY() - 1);
				    explosion->_propagation = Up;
				    iFutureMap->SetEntity(explosion);	  
 				}

 				return;

	 		case Down:

	 			if (CanPropagate(iPresentMap, GetX(), GetY() + 1))
 				{
 					auto explosion = std::make_shared<PropExplosion>(*this);
 					explosion->active = true;
				    explosion->_timeout = iTimestamp + kExplosionTimer;
				    explosion->SetY(GetY() + 1);
				    explosion->_propagation = Down;
				    iFutureMap->SetEntity(explosion);	  
 				}

 				return;

	 		case Left:

				if (CanPropagate(iPresentMap, GetX() - 1, GetY()))
 				{
 					auto explosion = std::make_shared<PropExplosion>(*this);
 					explosion->active = true;
				    explosion->_timeout = iTimestamp + kExplosionTimer;
				    explosion->SetX(GetX() - 1);
				    explosion->_propagation = Left;
				    iFutureMap->SetEntity(explosion);	  
 				}

				return;

	 		case Right:

	 			if (CanPropagate(iPresentMap, GetX() + 1, GetY()))
 				{
 					auto explosion = std::make_shared<PropExplosion>(*this);
 					explosion->active = true;
				    explosion->_timeout = iTimestamp + kExplosionTimer;
				    explosion->SetX(GetX() + 1);
				    explosion->_propagation = Right;
				    iFutureMap->SetEntity(explosion);	  
 				}

 				return;
	 	}
	 }