Exemplo n.º 1
0
void LagTest()
{
	char			msg[60], strings[100];
	int				clicks[10], done = 0, view = 0, speed = 1, change = 1;
	int				x, y, x2, y2, pos = 0, i = 0, vary = 0, variation = 1;
	u16				pressed, audio = 0, rumble = 0;
	ImagePtr		back, spriteA, spriteB, fixed;
	char 			**ControllerButtons = NULL;
	
	
	srand((int)(time(0)));	
	back = LoadImage(WHITEIMG, 1);
	if(!back)
		return;
	
	back->r = 0x00;
	back->g = 0x00;
	back->b = 0x00;
	
	fixed = LoadImage(LAGPERIMG, 0);
	if(!fixed)
		return;
	spriteA = LoadImage(LAGPERIMG, 0);
	if(!spriteA)
	{
		FreeImage(&fixed);
		return;
	}
	spriteB = LoadImage(LAGPERIMG, 0);
	if(!spriteB)
	{
		FreeImage(&spriteA);
		FreeImage(&fixed);
		return;
	}
		
	SND_Init(INIT_RATE_48000); 
    SND_Pause(0); 	

	x = 144;
	y = 60;
	x2 = 108;
	y2 = 96;
		
	fixed->x = 144;
	fixed->y = 96;	

	for(i = 0; i < 10; i++)
		clicks[i] = 0xFF;

	while(!done && !EndProgram) 
	{
		StartScene();

		DrawImage(back);
		DrawImage(fixed);

		if(y > 132 + vary)
		{
			speed = -1;
			change = 1;
			if(variation)
			{
				if(rand() % 2)
					vary = rand() % 7;
				else
					vary = -1 * rand() % 7;
			}
		}

		if(y < 60 + vary)
		{
			speed = 1;
			change = 1;
			if(variation)
			{
				if(rand() % 2)
					vary = rand() % 7;
				else
					vary = -1 * rand() % 7;
			}
		}

		y += speed;
		x2 += speed;

		spriteA->x = x;
		spriteA->y = y;
		spriteB->x = x2;
		spriteB->y = y2;
		
		if(y == 96)
		{			
			if(audio)
				SND_SetVoice(SND_GetFirstUnusedVoice(), VOICE_STEREO_16BIT, 44100, 0, beep_snd, beep_snd_size, speed == -1 ? 0 : 255, speed == -1 ? 255 : 0, NULL);				
				
			if(rumble)
				ControllerRumble(0, 1);
			
			spriteA->r = 0xff;
			spriteA->g = 0x00;
			spriteA->b = 0x00;

			spriteB->r = 0xff;
			spriteB->g = 0x00;
			spriteB->b = 0x00;
		}
		else
		{
			if(rumble)
				ControllerRumble(0, 0);
				
			if(y == 97 || y == 95) // one pixel off
			{
				spriteA->r = 0x00;
				spriteA->g = 0xff;
				spriteA->b = 0x00;

				spriteB->r = 0x00;
				spriteB->g = 0xff;
				spriteB->b = 0x00;
			}

			if(y == 98 || y == 94) // two pixels off
			{
				spriteA->r = 0xff;
				spriteA->g = 0xff;
				spriteA->b = 0xff;

				spriteB->r = 0xff;
				spriteB->g = 0xff;
				spriteB->b = 0xff;
			}
		}			

		if(view == 0 || view == 2)
			DrawImage(spriteA);

		if(view == 1 || view == 2)
			DrawImage(spriteB);

		for(i = 0; i < 10; i++)
		{
			if(clicks[i] != 0xFF)
			{
				int px, py;

				px = 10;
				py = i*fh + 20;
	
				sprintf(msg, "Offset %02d:", i + 1);
				DrawStringS(px, py, 0xff, 0xff, 0xff, msg);
			
				px += (strlen(msg) + 2)*fw;
				if(clicks[i] == 1)
					sprintf(msg, "%2d frame", clicks[i]);
				else
					sprintf(msg, "%2d frames", clicks[i]);

				if(clicks[i] >= 0)
				{
					if(clicks[i] == 0)
						DrawStringS(px, py, 0x00, 0xff, 0x00, msg);
					else
						DrawStringS(px, py, 0xff, 0xff, 0xff, msg);
				}
				else
					DrawStringS(px, py, 0xff, 0x00, 0x00, msg);
			}
		}

		sprintf(msg, "Audio: %s", audio ? "on" : "off");
		DrawStringS(200, 20, 0xff, 0xff, 0xff, msg);
		sprintf(msg, "Timing: %s", variation ? "random" : "rhythmic");
		DrawStringS(200, 20+fh, 0xff, 0xff, 0xff, msg);		
		sprintf(msg, "Rumble: %s", rumble ? "on" : "off");
		DrawStringS(200, 20+2*fh, 0xff, 0xff, 0xff, msg);		

#ifdef WII_VERSION
		if(ControllerType == ControllerWiimote)
			ControllerButtons = ControlNamesWii;
			
		if(ControllerType == ControllerWiiClassic)
		{
			if(Options.SFCClassicController)
				ControllerButtons = ControlNamesWiiSFC_CC;
			else
				ControllerButtons = ControlNamesWiiCC;
		}
			
		if(ControllerType == ControllerGC)
#endif
			ControllerButtons = ControlNamesGC;
			
		sprintf(strings, "Press \"%c\" when the sprite is aligned with the background.", ControllerButtons[ControlButtonA][0]);
		DrawStringS(20, 170, 0x00, 0xff, 0x00, strings);
		
		sprintf(strings, "Negative values mean you pressed \"%c\" before they intersected", ControllerButtons[ControlButtonA][0]);
		DrawStringS(20, 170+fh, 0x00, 0xff, 0x00, strings);
		
		sprintf(strings, "\"%c\" button toggles horizontal and vertical movement.", ControllerButtons[ControlButtonX][0]);
		DrawStringS(20, 170+2*fh, 0x00, 0xff, 0x00, strings);
		
		sprintf(strings, "\"%c\" trigger toggles rhythmic timing.", ControllerButtons[ControlButtonY][0]);
		DrawStringS(20, 170+3*fh, 0x00, 0xff, 0x00, strings);
		
		sprintf(strings, "\"%c\" button toggles audio feedback.", ControllerButtons[ControlButtonR][0]);
		DrawStringS(20, 170+4*fh, 0x00, 0xff, 0x00, strings);
		
		sprintf(strings, "\"%c\" button toggles rumble feedback.", ControllerButtons[ControlButtonL][0]);
		DrawStringS(20, 170+5*fh, 0x00, 0xff, 0x00, strings);

		EndScene();
		
		ControllerScan();
		pressed = Controller_ButtonsDown(0);
		if (pressed & PAD_BUTTON_B)
			done =	1;
			
		if (pressed & PAD_BUTTON_START)		
		{
			DrawMenu = 1;					
			HelpData = MANUALLAG;
		}
			
		if (pressed & PAD_BUTTON_A)
		{
			if(change)
			{
				clicks[pos] = (y - 96) *speed;
	
				sprintf(msg, " Off: %d", clicks[pos]);					
	
				if(clicks[pos] >= 0)
				{
					change = 0;
					pos ++;
				}
		
				if(pos > 9)
					done = 1;
			}
		}

		if (pressed & PAD_TRIGGER_R)
			audio =	!audio;	
			
		if (pressed & PAD_TRIGGER_L)
		{
			rumble = !rumble;	
			if(!rumble)
				ControllerRumble(0, 0);
		}
			
		if (pressed & PAD_BUTTON_X)
		{
			view ++;
			if(view > 2)
				view = 0;
		}
					
    					
		if(pressed & PAD_BUTTON_Y)
		{
			variation = !variation;
			if(!variation)
				vary = 0;
		}
	}
    
	ControllerRumble(0, 0);

	FreeImage(&back);
	FreeImage(&fixed);
	FreeImage(&spriteA);
	FreeImage(&spriteB);	
	
	if(pos > 9)
	{
		int	total = 0;
		double	res = 0, ms = 0;
		ImagePtr wall;
		
		done = 0;
		wall = LoadImage(BACKIMG, 0);
		if(!wall)
			return;
		
		while(!done && !EndProgram) 
		{			
			StartScene();

			DrawImage(wall);

			total = 0;
			for(i = 0; i < 10; i++)
			{
				int px, py;
	
				px = 70;
				py = i*fh + 70;
	
				sprintf(msg, "%2d", clicks[i]);
				if(clicks[i] >= 0)
				{
					if(clicks[i] == 0)
						DrawStringS(px, py, 0, 0xff, 0, msg);
					else
						DrawStringS(px, py, 0xff, 0xff, 0xff, msg);
				}
				else
					DrawStringS(px, py, 0xff, 0, 0, msg);
	
				if(clicks[i] >= 0)
					total += clicks[i];
	
			}

			if(!IsPAL)
			{
				res = (double)total / 10.0;
				ms = (double)(res*(1000.0/60.0));
				sprintf(msg, "%d/10 = %0.2f average frames ~= %0.2f ms", total, res, ms);
				DrawStringS(60, 110, 0xff, 0x00, 0x00, "+");
				DrawStringS(55, 70 + fh*10, 0xff, 0x00, 0x00, "_____");
				DrawStringS(60, 70 + fh*11, 0xff, 0xff, 0xff, msg);
				DrawStringS(30, 70 + fh*12, 0x00, 0xff, 0xff, "Keep in mind that an NTSC frame is around 16.67 ms");
			}
			else
			{
				res = (double)total / 10.0;
				ms = (double)(res*(1000.0/50.0));
				sprintf(msg, "%d/10 = %0.2f average frames ~= %0.2f ms", total, res, ms);
				DrawStringS(60, 110, 0xff, 0x00, 0xff, "+");
				DrawStringS(55, 70 + fh*10, 0xff, 0x00, 0x00, "_____");
				DrawStringS(60, 70 + fh*11, 0xff, 0xff, 0xff, msg);
				DrawStringS(40, 70 + fh*12, 0x00, 0xff, 0xff, "Keep in mind that a PAL frame is around 20 ms");
			}

			if(total && total < 5)
			{
				DrawStringS(100, 120, 0x00, 0xff, 0x00, "EXCELLENT REFLEXES!");
			}
			if(total == 0)
			{
				DrawStringS(100, 120, 0x00, 0xff, 0x00, "INCREDIBLE REFLEXES!!");
			}

			EndScene();
			
			ControllerScan();
		
		    pressed = Controller_ButtonsDown(0);		
			
			if (pressed & PAD_BUTTON_B)
				done =	1;	
	
			if (pressed & PAD_BUTTON_START)		
			{
				DrawMenu = 1;					
				HelpData = MANUALLAG;
			}
		}
		FreeImage(&wall);
	}
	SND_End();
	
	return;
}
Exemplo n.º 2
0
static void playClick() {
    if( opt_sound > 0)
        SND_SetVoice(SND_GetFirstUnusedVoice(), VOICE_MONO_16BIT, 36000, 0,&Click17a_raw, Click17a_raw_size, opt_sound, opt_sound, NULL);
}
Exemplo n.º 3
0
void SoundTest()
{
	int 			done = 0, sel = 1, play = 0, aleft = 0, aright = 0;
	u32			    pressed;		
	ImagePtr		back;	
	
	back = LoadImage(BACKIMG, 0);
	if(!back)
		return;
		
    SND_Init(INIT_RATE_48000); 
    SND_Pause(0);
	while(!done && !EndProgram) 
	{
		StartScene();
		DrawImage(back);

		DrawStringS(130, 60, 0xff, 0xff, 0xff, "Sound Test"); 
		DrawStringS(80, 120, 0xff, sel == 0 ? 0 : 0xff, sel == 0 ? 0 : 0xff, "Left Channel"); 
		DrawStringS(120, 130, 0xff, sel == 1 ? 0 : 0xff, sel == 1 ? 0 : 0xff, "Center Channel");
		DrawStringS(160, 120, 0xff, sel == 2 ? 0 : 0xff, sel == 2 ? 0 : 0xff, "Right Channel");
		EndScene();

		ControllerScan();
		
        pressed = Controller_ButtonsDown(0);		
		if (pressed & PAD_BUTTON_B)
			done =	1;								

		if (pressed & PAD_BUTTON_A)
			play =	1; 								

		if (pressed & PAD_BUTTON_LEFT)
			sel --;

		if (pressed & PAD_BUTTON_RIGHT)
			sel ++;

		if ( pressed & PAD_BUTTON_START ) 		
		{
			DrawMenu = 1;					
			HelpData = SOUNDHELP;
		}																	
		
		if(sel < 0)
			sel = 2;

		if(sel > 2)
			sel = 0;
		
		switch(sel)
		{
			case 0:
				aleft = 0xff;
				aright = 0x00;
				break;
			case 1:
				aleft = 0xff;
				aright = 0xff;
				break;
			case 2:
				aleft = 0x00;
				aright = 0xff;
				break;
		}

		if(play)
		{
			SND_SetVoice(SND_GetFirstUnusedVoice(), VOICE_STEREO_16BIT, 44100, 0, beep_snd, beep_snd_size, aleft, aright, NULL);				
			play = 0;
		}        

	}    
	FreeImage(&back);
	SND_End();
	return;
}
Exemplo n.º 4
0
static void playWrong() {
    if( opt_sound > 0)
        SND_SetVoice(SND_GetFirstUnusedVoice(), VOICE_MONO_16BIT, 22050, 0,&gromb_raw, gromb_raw_size, opt_sound, opt_sound, NULL);
}