Beispiel #1
0
void MainMenu::Render(DisplayContext* displayContext)
{
	for(int i=0; i<ITEM_QTY; ++i)
	{
		displayContext->DrawText(*m_MenuElements[i], m_Positions[i]);
	}
	
	Point arrowPosition( m_Positions[m_FocusIndex] );
	arrowPosition.MoveBy(-m_FocusText.GetTextWidth(), 0);
	displayContext->DrawText(m_FocusText, arrowPosition);
	
	displayContext->SetColor(Color::White);
	displayContext->DrawRectangle(*m_VerticalRect);
	displayContext->DrawRectangle(*m_HorizontalRect);
	
	Scene::Render(displayContext);
}
//Move: Performs game round for Player.
void GamePlayer::Move(GameManager* mgr) {
	if (m_pauseMoveRounds == 0) { // check if player can move
		
		Undraw();

		Point p = GetPosition();
		p.set(p.getX()+m_direction.getX(),p.getY()+m_direction.getY()); // set new postion
		fixPoint(p); //if needed fix the position of the point
		bool move=!mgr->isValidPosition(p);

		if (!move) // in case the new position is valid,  do change of direction randomly
			move = (rand() % 10 == 0);

		while (move) { // if new poisiton is not valid get valid new position.
			p=GetPosition();
			m_direction.set(rand() % 3 - 1,rand() % 3 - 1);
			p.set(p.getX()+m_direction.getX(),p.getY()+m_direction.getY());
			fixPoint(p);

			if ( mgr->isValidPosition(p) && GetPosition().comper(p) != 0 ) 
				move=false;
		}

		SetPosition(p); //set the new position

		m_pauseMoveRounds=PAUSE_MOVE_AFTER_MOVE; //update waiting rounds

		Draw(mgr);

		switch(mgr->TakeMapObject(p)) { // check if payer is on gift
		case GlobalConsts::Food:
			m_power+=ADD_POWER;
			break;
		case GlobalConsts::Quiver:
			m_numOfArrows+=ADD_ARROWS;
			break;
		case GlobalConsts::Bomb:
			m_power-=LOSE_POWER;
			break;
		}

		HandleDeath(mgr); // check death

		if (m_pauseArrowsRounds == 0 && m_numOfArrows > 0 ) // handle shooting arrow
		{
			Point arrowPosition(GetPosition());
			arrowPosition.set(arrowPosition.getX() + m_direction.getX(),arrowPosition.getY() + m_direction.getY());
			if (mgr->isValidPosition(arrowPosition)) {
				mgr->createArrow(arrowPosition,m_direction);
				m_pauseArrowsRounds = PAUSE_ARROWS_AFTER_SHOOT;
				--m_numOfArrows;
			}
		}
		else if ( m_pauseArrowsRounds > 0 )  {
			m_pauseArrowsRounds--;
		}
	}
	else {
		--m_pauseMoveRounds;
	}
}