Exemple #1
0
int popUpLoop(SDL_Surface *screen, menuDataStore *menuData)
{
	int done, mouseX, mouseY;
	SDL_Event event;
	
	unsigned int startTime, stopTime, diffTime;
	unsigned int innerStartTime, innerStopTime;
	
	done = 0;
	while ( !done ) {
		startTime = SDL_GetTicks();
		/* Check for events */
		while ( SDL_PollEvent(&event) ) {
			innerStartTime = SDL_GetTicks();
			
			
			switch (event.type) {
					
				case SDL_MOUSEMOTION:
					break;
				case SDL_MOUSEBUTTONUP:
					
					SDL_GetMouseState(&mouseX,&mouseY);
					
					printf("Cusor-Position x: %d y: %d\n",mouseX,mouseY);
					int buttonID;
					for (buttonID = 0; buttonID<menuData->buttonCount; buttonID++) {
						if (isButtonClicked(&menuData->buttons[buttonID],mouseX,mouseY)) {
							return buttonID;							
						}
					}
					break;
				case SDL_KEYDOWN:
					/* Any keypress quits the app... */
					switch( event.key.keysym.sym )
				{
						
					case SDLK_ESCAPE:
					case SDLK_q:
						done = 1;
						break;
					default:
						break;
						
				}	
					break;
				case SDL_QUIT:
					done = 1;
					break;
				default:
					break;
			}
			
			innerStopTime = SDL_GetTicks();
			diffTime=(innerStopTime-innerStartTime);
			//25 Frames per second (40 Milliseconds per frame)
			if (MS_FRAMETIME>diffTime) 
				SDL_Delay(MS_FRAMETIME-diffTime);
		}
		stopTime = SDL_GetTicks();
		diffTime = (stopTime-startTime);
		//25 Frames per second (40 Milliseconds per frame)
		if (MS_FRAMETIME>diffTime) 
			SDL_Delay(MS_FRAMETIME-diffTime);
		
	}
	return -1;
	
}
Exemple #2
0
int displayAbout(SDL_Surface *screen, dataStore *data)
{
	int done, mouseX, mouseY;
	SDL_Event event;

	SDL_Color textColor = { 255, 255, 255,0};
	
	SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x00, 0x00, 0x00 ));

	myButton button;
	button.rect.x = screen->clip_rect.w/2-BUTTONWIDTH/2;
	button.rect.y = screen->clip_rect.h-BUTTONHEIGHT-100;
	button.rect.w = BUTTONWIDTH;
	button.rect.h = BUTTONHEIGHT;
	button.name="Back";
	
	drawButton(screen, &button);
	
	TTF_Font *font = theFont(20);
	char aboutText[10][100] = {"Hedgewood is a game written by:"," - toco"," - tk"," - JTR"," "," we hope you enjoy it."," ","Thanks to:"," - friend of tk for the grapics"," - our great tutor Arne"};
	
	if (!(renderMultiLineText(font, 150, 100, &aboutText[0],10, textColor,screen)))
		printf("%s\n",TTF_GetError());
	
	
	SDL_Flip(screen);
	TTF_CloseFont(font);

//	SDL_FreeSurface(message);
	unsigned int startTime, stopTime, diffTime;
	unsigned int innerStartTime, innerStopTime;
	
	done = 0;
	while ( !done ) {
		startTime = SDL_GetTicks();
		/* Check for events */
		while ( SDL_PollEvent(&event) ) {
			innerStartTime = SDL_GetTicks();
			switch (event.type) {
					
				case SDL_MOUSEMOTION:
					break;
				case SDL_MOUSEBUTTONUP:
					
					SDL_GetMouseState(&mouseX,&mouseY);
					if (isButtonClicked(&button, mouseX, mouseY)) {
						
						done = 1;
					}
#if (DEBUG==1)
					printf("Cusor-Position x: %d y: %d\n",mouseX,mouseY);
#endif
					break;
				case SDL_KEYDOWN:
					/* Any keypress quits the app... */
					switch( event.key.keysym.sym )
				{
					case SDLK_f:
						break;
						
					case SDLK_0:
						printf ("Music off\n");
						Mix_HaltMusic();
						Mix_HaltChannel(-1);
						data->soundEnabled=0;
						break;
					case 	SDLK_m:
						printf ("Music on /Pause\n");				
						if( Mix_PlayingMusic() == 0 )  
							Mix_PlayMusic( data->ingamemusic, -1);			
						if( Mix_PausedMusic() == 1 )
							Mix_ResumeMusic(); 
						else Mix_PauseMusic();						
						break;
					case SDLK_ESCAPE:
					case SDLK_q:
						done = 1;
						quitSDL(data);
						break;
					default:
						break;
						
				}	
					break;
/*				case SDL_QUIT:
					done = 1;
					break;
*/				default:
					break;
			}
			innerStopTime = SDL_GetTicks();
			diffTime=(innerStopTime-innerStartTime);
			//25 Frames per second (40 Milliseconds per frame)
			if (MS_FRAMETIME>diffTime) 
				SDL_Delay(MS_FRAMETIME-diffTime);
		}
		stopTime = SDL_GetTicks();
		diffTime = (stopTime-startTime);
		//25 Frames per second (40 Milliseconds per frame)
		if (MS_FRAMETIME>diffTime) 
			SDL_Delay(MS_FRAMETIME-diffTime);
		
	}
	return 0;
}
Exemple #3
0
int storeLoop(SDL_Surface *screen, dataStore *data, menuDataStore *menuData) {
	int done, mouseX, mouseY;
	SDL_Event event;
	int  diffmoney;
	unsigned int startTime, stopTime, diffTime;
	unsigned int innerStartTime, innerStopTime;
	int buttonID;
	done = 0;
	while ( !done ) {
		startTime = SDL_GetTicks();
		/* Check for events */
		while ( SDL_PollEvent(&event) ) {
			innerStartTime = SDL_GetTicks();
			switch (event.type) {
				case SDL_MOUSEMOTION:
					break;
				case SDL_MOUSEBUTTONUP:
					SDL_GetMouseState(&mouseX,&mouseY);
#if (DEBUG==1)
					printf("Cusor-Position x: %d y: %d\n",mouseX,mouseY);				
#endif
					for (buttonID = 0; buttonID<STOREBUTTONCOUNT; buttonID++) {					
						if (isButtonClicked(&menuData->buttons[buttonID],mouseX,mouseY)) {						
							if (buttonID==ITEM_BUTTON) {
								if (data->player.candystash + data->player.bp.currentVolume>=data->player.cutSpeed*1000) {
									diffmoney= data->player.bp.currentVolume - data->player.cutSpeed*1000;
									if(diffmoney<0) {
										data->player.bp.currentVolume=0;
										data->player.candystash += diffmoney;
									} else data->player.bp.currentVolume -= data->player.cutSpeed*1000;
									data->player.cutSpeed+=0.5;
								}
								//							done=2;
							}
							else if (buttonID==BACKPACK_BUTTON ) {
								if (data->player.candystash + data->player.bp.currentVolume>=data->player.bp.maxVolume*3) {
									diffmoney= data->player.bp.currentVolume - data->player.bp.maxVolume*3;
									if(diffmoney<0) {
										data->player.bp.currentVolume=0;
										data->player.candystash += diffmoney;
									} else data->player.bp.currentVolume -= data->player.bp.maxVolume*3;
									data->player.bp.maxVolume+=200;
								}
								//							done=2;
							}
							else if (buttonID==VIEW_BUTTON ) {
								
								if (data->player.candystash + data->player.bp.currentVolume>=data->player.vision*1000) {
									diffmoney= data->player.bp.currentVolume - data->player.vision*1000;
									if(diffmoney<0) {
										data->player.bp.currentVolume=0;
										data->player.candystash += diffmoney;
									} else data->player.bp.currentVolume -= data->player.vision*1000;
									data->player.vision+=1;
								}
								//							done=2;
							}
							else if (buttonID==ENERGY_BUTTON) {
								
								if (data->player.candystash + data->player.bp.currentVolume>=data->player.maxEnergy) {
									diffmoney= data->player.bp.currentVolume - data->player.maxEnergy;
									if(diffmoney<0) {
										data->player.bp.currentVolume=0;
										data->player.candystash += diffmoney;
									} else data->player.bp.currentVolume -= data->player.maxEnergy;
									data->player.maxEnergy+=100;
								}
								//							done=2;
							}
							else if (buttonID==BACK_BUTTON){
								
								done=1;
								break;
								
							}
						}
					}
					displayStore(screen, data,menuData);
					break;
				case SDL_KEYDOWN:
					/* Any keypress quits the app... */
					switch( event.key.keysym.sym ) {
						case SDLK_ESCAPE:
						case SDLK_q:
							done = 1;
							break;
							break;
						case SDLK_0:
							printf ("Music off\n");
							Mix_HaltMusic();
							Mix_HaltChannel(-1);
							data->soundEnabled=0;
							break;
						case 	SDLK_m:
							printf ("Music on /Pause\n");				
							if( Mix_PlayingMusic() == 0 )  
								Mix_PlayMusic( data->ingamemusic, -1);			
							if( Mix_PausedMusic() == 1 )
								Mix_ResumeMusic(); 
							else Mix_PauseMusic();						
							break;
						default:
							break;
					}
					break;
				case SDL_QUIT:
					done = 1;
					break;
				default:
					break;
			}
			innerStopTime = SDL_GetTicks();
			diffTime=(innerStopTime-innerStartTime);
			//25 Frames per second (40 Milliseconds per frame)
			if (MS_FRAMETIME>diffTime)
				SDL_Delay(MS_FRAMETIME-diffTime);
		}
		stopTime = SDL_GetTicks();
		diffTime = (stopTime-startTime);
		//25 Frames per second (40 Milliseconds per frame)
		if (MS_FRAMETIME>diffTime)
			SDL_Delay(MS_FRAMETIME-diffTime);
		
		
		
	}
	return (done-1);
}