Exemple #1
0
void		Menu::PlayMenu(gdl::Input &input)
{
  if (input.getKey(SDLK_UP))
    {
      _cursor == 5 ? _cursor = 8 : _cursor--;
      usleep(100000);
    }
  else if (input.getKey(SDLK_DOWN))
    {
      _cursor <= 7 ? _cursor++ : _cursor = 5;
      usleep(100000);
    }
  if (_cursor == 5)
    {
      if (input.getKey(SDLK_RIGHT))
	_nbr_players = 2;
      else if (input.getKey(SDLK_LEFT))
	_nbr_players = 1;
    }
  if (_cursor == 6)
    {
      int	nbmax = _size_x / 3;
      if (input.getKey(SDLK_RIGHT))
	{
	  _nbr_enemies >= nbmax ? _nbr_enemies = 1 : _nbr_enemies += 1;
	  usleep(100000);
	}
      else if (input.getKey(SDLK_LEFT))
	{
	  _nbr_enemies >= 2 ? _nbr_enemies -= 1 : _nbr_enemies = nbmax;
	  usleep(100000);
	}
    }
  if (_cursor == 7)
    {
      if (input.getKey(SDLK_RIGHT))
	{
	  _size_x >= 100 ? _size_x = 10 : _size_x += 1;
	  _size_y >= 100 ? _size_y = 10 : _size_y += 1;
	  usleep(100000);
	}
      else if (input.getKey(SDLK_LEFT))
	{
	  _size_x > 10 ? _size_x -= 1 : _size_x = 100;
	  _size_y > 10 ? _size_y -= 1 : _size_y = 100;
	  usleep(100000);
	}
      if (_nbr_enemies > static_cast<int>(_size_x / 3))
	_nbr_enemies = _size_x/3;
    }
  if (_cursor == 8 &&
      getMapY() != 0 &&
      getMapX() != 0 &&
      getNbrEnemies() != 0 &&
      getNbrPlayers() != 0 &&
      input.getKey(SDLK_RETURN))
    _cursor = 11;
}
void UINodeServerSelector::render (int x, int y) const
{
	Super::render(x, y);
	x += getRenderX();
	y += getRenderY();
	_frontend->renderFilledRect(x, y, _colWidth * _frontend->getWidth(), _headlineHeight, colorGray);
	_headlineFont->print(NAME_HEADLINE, _fontColor, x + getNameX(), y, false);
	_headlineFont->print(MAP_HEADLINE, _fontColor, x + getMapX(), y, false);
	_headlineFont->print(PLAYERS_HEADLINE, _fontColor, x + getPlayersX(), y, false);
}
void UINodeServerSelector::renderSelectorEntry (int index, const ServerEntry& data, int x, int y, int colWidth, int rowHeight, float alpha) const
{
	Color color = { 0.6f, 0.6f, 0.6f, 0.6f };
	if (_selectedIndex == index) {
		color[0] = color[1] = color[2] = 1.0f;
		color[3] = 0.3f;
	} else if ((index % 2) == 0) {
		color[3] = 0.3f;
	}

	const int nameWidth = getMapX() - getNameX() - _rowSpacing;
	const int mapNameWidth = getPlayersX() - getMapX() - _rowSpacing;
	const std::string players = string::toString(data.playerCount) + "/" + string::toString(data.maxPlayerCount);
	const int playersWidth = _font->getTextWidth(PLAYERS_HEADLINE) - _rowSpacing;

	_frontend->renderFilledRect(x, y, colWidth, rowHeight, color);
	_font->printMax(data.name, _fontColor, x + getNameX(), y, nameWidth, false);
	_font->printMax(data.mapName, _fontColor, x + getMapX(), y, mapNameWidth, false);
	_font->printMax(players, _fontColor, x + getPlayersX(), y, playersWidth, false);
}
void IonCanonSatellite::process(int step)
{
	AbilityExecutor::process(step);


	int unitStep = (step + m_initialStep) % GAME_STEP_PER_SECOND;
	bool process = (unitStep % m_procStepSize) == 0;

	if(process && m_active)
	{
		m_currentAngle += m_rotation;
		if(m_currentAngle >= 360)
			m_currentAngle -= 360;

		setDirection(m_currentAngle);

		if(m_attackSecX == (getMapX() - 1) && !m_attack)
		{
			m_attack = true;
			int x = m_attackSecX;
			int y = getMapY();
			Building* target = ObjectController::getInstance()->getBuilding(x, y);

			if(target != nullptr)
			{
				m_bullet->setMapCoord(x, y, true);
				m_bullet->setTarget(target);
			}
		}
		else if(m_steps == 0)
		{
			returnToBase();
			m_freeState = true;
			m_active = false;
		}
	}
}