void EngineStatePoolShowShot::Blue(bool down)
{
#ifdef SHOW_VALID_SHOTS
  if (!down)
  {
    return;
  }

  // Go to next valid shot. If at the end, go back to start.
  ++m_validShotNum;

  int maxValidShot = GetRules(m_pLevel.GetPtr())->GetBehaviour()->
    GetNumValidShots();
  if (m_validShotNum >= maxValidShot)
  {
    m_validShotNum = 0;
  }
  std::cout << "SHOWING VALID SHOT " << m_validShotNum + 1 << " OF "
    << maxValidShot 
    << ": "
    << GetRules(m_pLevel.GetPtr())->GetBehaviour()->
        ValidShotString(m_validShotNum).c_str() 
    << "\n";
#endif
}
	void Block::Touch(ENT::Ball& ball, TouchInfo info) {
		_health--;
		if(0 >= _health) {
			SetCollisionModel(PHY_GHOST);
			SetVelocity(MATH::Vector2(0.0f, 100.0f));
			_angularVelocity = sf::Randomizer::Random(5.0f, 10.0f);
			_drop = true;

			GetRules().numBlocks--;

			// TODO
			int r = rand() % 50;
			if(r <= 3) {
				entPtr_t item = entPtr_t(new ENT::ExtraBallItem(GetRules()));
				item->SetPosition(GetPosition());
				Entity::LinkToWorld(item);
			}
		} 

		_highlight = true;
		_highlightPhase = 0.0f;
	}
	void ExtraBallItem::Touch(Paddle& paddle, TouchInfo info) {
		SetPhysicsModel(PHY_GHOST);
		SetCollisionModel(PHY_GHOST);
		Die();

		entPtr_t ball = entPtr_t(new ENT::Ball(GetRules()));
		ball->SetPosition(paddle.GetPosition() + 
				MATH::Vector2((paddle.GetBBox().lowerRight.x / 2.0f) - (BALL_SIZE / 2.0f), 
				-(BALL_SIZE + 1.0f)));
		Entity::LinkToWorld(ball);

		paddle.AttachEntity(ball);
	}
void EngineStatePoolShowShot::Draw()
{
#ifdef SHOW_VALID_SHOTS
  EngineStatePoolBase::DrawBackground();
//  GetActivePlayer()->DrawSwish();
  Frustum::Instance()->Create();
  m_scenePolys = m_pLevel->Draw();

  GetRules(m_pLevel.GetPtr())->GetBehaviour()->DrawValidShot(m_validShotNum);
  DrawGameObjects(false); // false => non-translucent
#else
  EngineStatePoolBase::Draw();
#endif
}
Beispiel #5
0
void PoolSnapshot::CreateFromCurrentState()
{
  // Get the state of all game objects in the current room.
  Level* pLevel = LevelServer::Instance()->GetCurrentLevel().GetPtr();
  int levelId = pLevel->GetId(); 
  int roomId = pLevel->GetRoomId();

  GameObjectMap& objs = Engine::Instance()->GetGameObjects(levelId, roomId);
  // Iterate through map of Game Objects.  
  for (GameObjectMap::iterator it = objs.begin(); it != objs.end(); ++it)
  {
    PPoolGameObject pGo = it->second; 
    Assert(pGo.GetPtr());

#ifdef UNDO_DEBUG
if (gameObjId == 10)
  std::cout << "** UNDO: Storing cue ball: pos is " 
    << ToString(*(pGo->GetOrientation()))
    << "\n";
#endif

    ObjInfo info;
    info.m_pGo = pGo;
    if (pGo->GetOrientation())
    {
      info.m_or = *(pGo->GetOrientation());
    }
    info.m_state = pGo->GetState();

    m_objInfo.push_back(info);
  }

  // No of ball spotted by each player
  int numPlayers = Engine::Instance()->GetGameState()->GetNumberOfPlayers();
  for (int i = 0; i < numPlayers; i++)
  {
    m_playerInfo.push_back(
      *(Engine::Instance()->GetGameState()->GetPlayerInfo(i)));
  }  

  // Store the state of the Rules - like is this a free ball, can the
  // ball be placed anywhere, etc.
  m_pRules = GetRules(pLevel)->Clone();
}
	void Ball::Think(float secsPassed) {
		_emitter.Move(secsPassed);
		_blur.Move(secsPassed);

		if(!_dying) {
			MATH::Vector2 position(GetPosition());
			sf::Vector2f offset = 0.5f * _ballSprite.GetSize();
			position.x += offset.x;
			position.y += offset.y;
			_blur.SetPosition(position);
			_blur.Emit();
		}

		/*
		okay, this is of course super non-realistic, but we need
		a (not too) fast ball to keep the game going
		*/
		float vel = GetVelocity().Length();
		
		if(900.0f < vel) {
			SetVelocity(900.0f * MATH::Normalize(GetVelocity()));
		}
		
		if(300.0f < vel) {
			SetAcceleration(0.98f);
		} else if(300.0f > vel)  {
			SetAcceleration(1.02f);
		} else {
			SetAcceleration(1.0f);
		}

		if(_dying) {
			_health -= _decayRate * secsPassed;
			if(0.0f >= _health) {
				GetRules().numBalls--;
				Die();
			}
		}
	}