Exemple #1
0
/**
* \fn int gameLoop(sInterface *p_interface, sMap *p_map)
* \brief Fonction de rendu de l'enigme et d'interfacage avec l'utilisateur
*
* \param *p_interface pointeur vers une structure de type sInterface
* \param *p_map pointeur vers une structure de type sMap
* \return int représentant le déroulement de la fonction
*/
int gameLoop(sInterface *p_interface, sMap *p_map) {
	
	bool l_loop = TRUE, l_solve = FALSE;
	char txtCmpt[32] = "";

	SDL_Rect l_posText = {(WINDOW_WIDTH / CASE_COLUMN_AMOUNT)/2, (WINDOW_HEIGHT / CASE_LINE_AMOUNT)/2, 50, 50};
	SDL_Color l_color = {255, 0, 0};

	p_interface->player.mapPosition.x = p_map->starting.x;
	p_interface->player.mapPosition.y = p_map->starting.y;
	p_interface->player.realPosition = getRealPosition(p_interface->player.mapPosition);
	p_interface->player.realDestination = getRealPosition(p_interface->player.mapPosition);

	displayMap(p_interface, p_map);

	while (l_loop){
		if(SDL_PollEvent(&(p_interface->event))) {
			switch (p_interface->event.type) {
				case(SDL_KEYDOWN):
					switch (p_interface->event.key.keysym.sym) {
						case(SDLK_z):
							updateGoal(p_interface, p_map, DUP);
							break;

						case(SDLK_d):
							updateGoal(p_interface, p_map, DRIGHT);
							break;

						case(SDLK_s):
							updateGoal(p_interface, p_map, DDOWN);
							break;

						case(SDLK_q):
							updateGoal(p_interface, p_map, DLEFT);	
							break;

						case(SDLK_x):
							l_solve = !l_solve;
							break;

						case(SDLK_ESCAPE):
							l_loop = FALSE;
							break;
					}
					break;

				case(SDL_MOUSEBUTTONDOWN):
					break;
			}
			while (SDL_PollEvent(&(p_interface->event)));
		}

		SDL_RenderClear(p_interface->renderer);
		SDL_RenderCopy(p_interface->renderer, p_interface->backgroundSprite, NULL, NULL);

		if(l_solve)
			showSolution(p_interface, p_interface->solution);
		renderParticle(&(p_interface->effect.particle), p_interface, p_map, TRUE);

		updateVision(p_interface, p_map);

		sprintf_s(txtCmpt, 30, "%d", p_interface->compteur);
		displayText(p_interface->renderer, txtCmpt, l_color, l_posText);


		SDL_RenderPresent(p_interface->renderer);
		if (WinOrNot(p_interface, p_map)) {
			l_loop = FALSE;
		}
		SDL_Delay(SDL_ANIMATION_FRAMETIME);
	}


	return 0;
}
Exemple #2
0
void CBoxManMain::DispatchMsg(UINT nChar)
{
	int x1,y1,x2,y2,x3,y3;
	x1=m_ptManPosition.x;
	y1=m_ptManPosition.y;
	switch (nChar)
	{
	case VK_UP:
		x2=x1;
		y2=y1-1;
		x3=x1;
		y3=y1-2;
		UpdataMap(x1,y1,x2,y2,x3,y3);

		break;
	case VK_DOWN:
		x2=x1;
		y2=y1+1;
		x3=x1;
		y3=y1+2;
		UpdataMap(x1,y1,x2,y2,x3,y3);
		break;
	case VK_LEFT:
		x2=x1-1;
		y2=y1;
		x3=x1-2;
		y3=y1;
		UpdataMap(x1,y1,x2,y2,x3,y3);
		break;
	case VK_RIGHT:
		x2=x1+1;
		y2=y1;
		x3=x1+2;
		y3=y1;
		UpdataMap(x1,y1,x2,y2,x3,y3);
		break;
	case 82://R
	case 114://r
		LoadMap(m_iMissionNum);
		GetManPosition();
		m_pBoxManWnd->Invalidate(FALSE);
		
		break;
	case 113://F2
		m_iMissionNum=m_iMissionNum+1;
		if (m_iMissionNum>MAX_MISSION_NUM)
		{
			m_iMissionNum=1;
		}
		LoadMap(m_iMissionNum);
		GetManPosition();
		m_pBoxManWnd->Invalidate(FALSE);

		break;
	case 112://F1

		m_iMissionNum=m_iMissionNum-1;
		if (m_iMissionNum<1)
		{
			m_iMissionNum=MAX_MISSION_NUM;
		}
		LoadMap(m_iMissionNum);
		GetManPosition();
		m_pBoxManWnd->Invalidate(FALSE);

		break;
	}
	WinOrNot();
}