示例#1
0
// When passed two buttons and a toggle int, 0=draw the first , 1=draws the second
void Button_TTF_Toggle_Paint(struct Button* btn1, struct Button* btn2, char *left_text, char *right_text, int toggle_state)
{
	if (toggle_state >=1)
	{
		if(btn2 == 0)
			return;

		GRRLIB_DrawImg(btn2->x, btn2->y, btn2->texture, 0, 1, 1, 0xFFFFFFFF);
		if( (strlen(left_text) > 0) && (strlen(right_text) > 0) )
		{
			// Draw the Left side text in white
			//CFreeTypeGX_DrawText(ttf16pt, (btn2->x + ((btn2->texture.w/2)/2)), (btn2->y + (btn2->texture.h/2) + 1), left_text, (GXColor){0x80, 0x80, 0x80, 0xff}, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
			// Draw the Right side text in black
			CFreeTypeGX_DrawText(ttf16pt, (btn2->x + ((btn2->texture.w/4)*3)), (btn2->y + (btn2->texture.h/2)), right_text, (GXColor){0xee, 0xee, 0xee, 0xee}, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
		}
	}
	else
	{
		if(btn1 == 0)
			return;

		GRRLIB_DrawImg(btn1->x, btn1->y, btn1->texture, 0, 1, 1, 0xFFFFFFFF);
		if( (strlen(left_text) > 0) && (strlen(right_text) > 0) )
		{
			// Draw the Left side text in black
			CFreeTypeGX_DrawText(ttf16pt, (btn1->x + ((btn1->texture.w/2)/2)), (btn1->y + (btn1->texture.h/2)), left_text, (GXColor){0xee, 0xee, 0xee, 0xee}, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
			// Draw the Right side text in white
			//CFreeTypeGX_DrawText(ttf16pt, (btn1->x + ((btn1->texture.w/4)*3)), (btn1->y + (btn1->texture.h/2) + 1), right_text, (GXColor){0x80, 0x80, 0x80, 0xff}, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
		}
	}


}
示例#2
0
void Button_Menu_Paint(struct Button* btn)
{
	if(btn == 0)
		return;

	if(btn->hovering || btn->selected)
		GRRLIB_DrawImg(btn->x, btn->y, btn->hoverTexture, 0, 1, 1, 0xFFFFFFFF);
	else
		GRRLIB_DrawImg(btn->x, btn->y, btn->texture, 0, 1, 1, 0xFFFFFFFF);
	// Draw the text centered to the middle of the button FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE
		CFreeTypeGX_DrawText(ttf18pt, (btn->x + (btn->texture.w / 2)), (btn->y + (btn->texture.h / 2)), btn->ttf_label, (GXColor){0xee, 0xee, 0xee, 0xff}, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
}
示例#3
0
文件: main.c 项目: capz/GRRLIB
int main() {
    float rot=0;
    float i;
    int circsize=150;
    char text[]="GRRLIB ROXX ";

    GRRLIB_Init();
    PAD_Init();


    GRRLIB_texImg *tex_font = GRRLIB_LoadTexture(font3d);
    GRRLIB_InitTileSet(tex_font, 64, 64, 32);
    GRRLIB_SetHandle (tex_font, tex_font->tilew/2, tex_font->tileh+circsize);

    GRRLIB_texImg *tex_screen;
    tex_screen = GRRLIB_CreateEmptyTexture(rmode->fbWidth,rmode->efbHeight);

    GRRLIB_Settings.antialias = true;

    while(1) {
        PAD_ScanPads();
        if(PAD_ButtonsDown(0) & PAD_BUTTON_START) exit(0);

// we say thant we will want to capture to a texture all the following
        GRRLIB_CompoStart();

            for(i=0;i<360;i+=30) {
// We draw some letters
                GRRLIB_DrawTile((rmode->fbWidth/2)-(tex_font->tilew/2), (rmode->efbHeight/2)-(tex_font->tileh+circsize), tex_font, rot+i, 1, 1, 0xFFFFFFFF, text[(int)(i/30)]-32);
            }

// we say we want to capture now, (the buffer will be cleared after the capture)
        GRRLIB_CompoEnd(0, 0, tex_screen);

        rot-=0.6;

// we now draw 3 times  the captured buffer playing with color
        GRRLIB_DrawImg(0, 0, tex_screen, 0, 1, 1, 0xFF00FFFF);
        GRRLIB_DrawImg(50, 50, tex_screen, 0, 1, 1, 0xFFFF00FF);
        GRRLIB_DrawImg(100, 100, tex_screen, 0, 1, 1, 0xFFFFFFFF);

        GRRLIB_Render();
    }

    GRRLIB_FreeTexture(tex_screen);
    GRRLIB_FreeTexture(tex_font);
    GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
    exit(0);
}
示例#4
0
void Button_Flag_Paint(struct Button* btn)
{
	if(btn == 0)
		return;

	if(btn->hovering)
	{
		GRRLIB_DrawImg(btn->x, btn->y, btn->texture, 0, 1.2, 1.2, 0xFFFFFFFF); // Adjust the scale here to make the flag 'bubble up' more
		// Draw the text centered below the flag
		CFreeTypeGX_DrawText(ttf16pt, (btn->x + (btn->texture.w / 2)), (btn->y -10), btn->ttf_label, (GXColor){0xff, 0xff, 0xff, 0xff}, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
	}
	else
		GRRLIB_DrawImg(btn->x, btn->y, btn->texture, 0, 1, 1, 0xFFFFFFFF);

}
示例#5
0
// When passed two buttons and a toggle int, 0=draw the first , 1=draws the second
void Button_Toggle_Paint(struct Button* btn1, struct Button* btn2, int toggle_state)
{
	if (toggle_state >=1)
	{
		if(btn2 == 0)
			return;
		GRRLIB_DrawImg(btn2->x, btn2->y, btn2->texture, 0, 1, 1, 0xFFFFFFFF);
	}
	else
	{
		if(btn1 == 0)
			return;
		GRRLIB_DrawImg(btn1->x, btn1->y, btn1->texture, 0, 1, 1, 0xFFFFFFFF);
	}
}
示例#6
0
static void drawLayout(int n) {
	unsigned char grid[MAX_WIDTH][MAX_HEIGHT][MAX_LAYERS];
	int x,y,z,c,l,pos=0;
	int coord = n % 6;

	for(z=0;z<MAX_LAYERS;++z) {
		for(x=0;x<MAX_WIDTH;++x) {
			for(y=0;y<MAX_HEIGHT;++y) {
				grid[x][y][z]=0;
			}
		}
	}

	for(l=0;l<MAX_TILES;++l) {
		x=layouts[n][pos++];
		y=layouts[n][pos++];
		z=layouts[n][pos++];
		grid[x][y][z]=255;
	}

	for(z=0;z<MAX_LAYERS;++z) {
		for(x=0;x<MAX_WIDTH+MAX_HEIGHT;++x) {
			for(y=(x>=MAX_WIDTH?x-MAX_WIDTH:0),c=(x>=MAX_WIDTH?MAX_WIDTH-1:x);y<MAX_HEIGHT && c>=0;++y,--c) {
				if(grid[c][y][z]==255) {
					GRRLIB_DrawImg(layouths[coord][0]+14+c*5-z,layouths[coord][1]+34+y*7-z,12,16,tex_smalltile,0,1,1,255);
				}
			}
		}
	}

}
示例#7
0
void grlib_PopScreen (void)
	{
	bool al = GRRLIB_GetAntiAliasing ();
	GRRLIB_SetAntiAliasing (0);
	GRRLIB_DrawImg(0, 0, popPushTex, 0, 1, 1, RGBA(255, 255, 255, 255) );
	GRRLIB_SetAntiAliasing (al);
	}
示例#8
0
void cui_board_demo(cui_board *board, GRRLIB_texImg* tex_pieces, GRRLIB_texImg* tex_tile, GRRLIB_ttfFont* font){
  unsigned int i;
  unsigned int x=0, y=0;
    
  int offset_x = 140;
  int offset_y = 80;
    
  srand ( time(NULL) );

  for (i = 0; i < CUI_TILE_NB; i++) {
    u32 color1 = rand() % 0x0000FF88;
    u32 color2 = rand() % 0x0000FF88;
    
    bool is_white = (x%2?false:true);
    if(y%2)is_white=!is_white;
    u32 tile_color = is_white? color1 : color2;

    GRRLIB_DrawImg(x*40+offset_x, y*40+offset_y, tex_tile, 0, 1, 1, tile_color);
        
    if ((i & 7) == 7){
      char board_num[2];
      snprintf(board_num, 2, "%d", 8-y);
			
      y++;
      x=0;
    }else{			
      x++;
    }
  }
 
}  
示例#9
0
// Draw the latest buffered popPushTex... but before do that discard all previous texture
void grlib_DrawScreenTex (GRRLIB_texImg * tex)
	{
	bool al = GRRLIB_GetAntiAliasing ();
	GRRLIB_SetAntiAliasing (FALSE);
	GRRLIB_DrawImg (0, 0, tex , 0, 1, 1, RGBA(255, 255, 255, 255) );
	GRRLIB_SetAntiAliasing (al);
	}
示例#10
0
/**
 * Wraps the GRRLIB_DrawImg function with parameters for width & height instead of scaleX & scaleY
 */
void DrawImg(float x, float y, float width, float height, GRRLIB_texImg texture, u8 opacity)
{
        float scaleX = width / TILE_WIDTH;
        float scaleY = height / TILE_HEIGHT;

        //Adjust for the fact that images scale at their center
        float newX = x - (TILE_WIDTH / 2) + (width / 2);
        float newY = y - (TILE_HEIGHT / 2) + (height / 2); 
        
        GRRLIB_DrawImg(newX, newY, texture, 0, scaleX, scaleY, opacity);
} 
示例#11
0
void grlib_DrawImg (int x, int y, int w, int h, GRRLIB_texImg * tex, f32 angle, u32 color)
	{
	f32 zx, zy;
	
	if (!tex) return;
	
	zx = (f32)w / tex->w;
	zy = (f32)h / tex->h;
	
	GRRLIB_DrawImg (x, y, tex, angle, zx, zy, color ); 
	}
示例#12
0
void Button_TTF_Paint(struct Button* btn)
{
	if(btn == 0)
		return;

	if(btn->hovering || btn->selected)
	{
		GRRLIB_DrawImg(btn->x, btn->y, btn->hoverTexture, 0, 1, 1, 0xFFFFFFFF);
		if (strlen(btn->ttf_label) > 0)
		{
			CFreeTypeGX_DrawText(ttf16pt, (btn->x + (btn->texture.w / 2)), (btn->y + (btn->texture.h / 2)), btn->ttf_label, (GXColor){0x00, 0x00, 0x00, 0xff}, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
		}
	}
	else
	{
		GRRLIB_DrawImg(btn->x, btn->y, btn->texture, 0, 1, 1, 0xFFFFFFFF);
		if (strlen(btn->ttf_label) > 0)
		{
			CFreeTypeGX_DrawText(ttf16pt, (btn->x + (btn->texture.w / 2)), (btn->y + (btn->texture.h / 2)), btn->ttf_label, (GXColor){0xee, 0xee, 0xee, 0xff}, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
		}
	}
}
示例#13
0
void Button_Key_Paint(struct Button* btn)
{
	if(btn == 0)
		return;

	if(btn->hovering || btn->selected)
	{
		GRRLIB_DrawImg(btn->x, btn->y, btn->texture, 0, 1.2, 1.2, 0xFFFFFFFF); // Adjust the scale here to make the 'bubble up' 
		if (strlen(btn->ttf_label) > 0)
		{
			CFreeTypeGX_DrawText(ttf18pt, (btn->x + (btn->texture.w / 2)), (btn->y + (btn->texture.h / 2)), btn->ttf_label, (GXColor){0x00, 0x00, 0x00, 0xff}, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
		}
	}
	else
	{	
		GRRLIB_DrawImg(btn->x, btn->y, btn->texture, 0, 1, 1, 0xFFFFFFFF);
		if (strlen(btn->ttf_label) > 0)
		{
			CFreeTypeGX_DrawText(ttf18pt, (btn->x + (btn->texture.w / 2)), (btn->y + (btn->texture.h / 2)), btn->ttf_label, (GXColor){0x00, 0x00, 0x00, 0xff}, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE);
		}
	}
}
示例#14
0
void Button_Paint(struct Button* btn)
{
	if(btn == 0)
		return;

	if(btn->hovering)
	{
		GRRLIB_DrawImg(btn->x, btn->y, btn->hoverTexture, 0, 1, 1, 0xFFFFFFFF);
		if(btn->show_reflection)
		{
			GRRLIB_DrawImgReflection(btn->x, (btn->y + btn->texture.h), btn->hoverTexture, 0, 1, 1, 0.7);
		}
	}
	else
	{
		GRRLIB_DrawImg(btn->x, btn->y, btn->texture, 0, 1, 1, 0xFFFFFFFF);
		if(btn->show_reflection)
		{
			GRRLIB_DrawImgReflection(btn->x, (btn->y + btn->texture.h), btn->texture, 0, 1, 1, 0.7);
		}
	}
}
示例#15
0
void Button3_Theme_Paint_Fade(struct Button3* btn, int theme_id, int fade)
{
	if(btn == 0)
		return;

	u32 color = 0xFFFFFF00|fade;

	if(btn->hovering)
	{
		switch (theme_id)
		{
			case 0: // black theme
				GRRLIB_DrawImg(btn->x, btn->y, btn->hoverTexture, 0, 1, 1, color);
				break;
			case 1: // white theme
				GRRLIB_DrawImg(btn->x, btn->y, btn->texture, 0, 1, 1, color);
				break;
			case 2: // blue state
			case 3:
				GRRLIB_DrawImg(btn->x, btn->y, btn->TriStateTexture, 0, 1, 1, color);
				break;
			default:
				GRRLIB_DrawImg(btn->x, btn->y, btn->hoverTexture, 0, 1, 1, color);
				break;
		}
	}
	else
	{
		switch (theme_id)
		{
			case 0: // black theme
				GRRLIB_DrawImg(btn->x, btn->y, btn->texture, 0, 1, 1, color);
				break;
			case 1: // white theme
				GRRLIB_DrawImg(btn->x, btn->y, btn->hoverTexture, 0, 1, 1, color);
				break;
			case 2: // blue state
			case 3:
				GRRLIB_DrawImg(btn->x, btn->y, btn->TriStateTexture, 0, 1, 1, color);
				break;
			default:
				GRRLIB_DrawImg(btn->x, btn->y, btn->texture, 0, 1, 1, color);
				break;
		}

	}
}
示例#16
0
void cui_board_display(cui_board *board, GRRLIB_texImg* tex_pieces, GRRLIB_texImg* tex_tile, GRRLIB_ttfFont* font, int cursor_x, int cursor_y){
  unsigned int i;
  unsigned int x=0, y=0;
    
  int offset_x = 140;
  int offset_y = 80;

  for(i=0;i<8;i++){
    char board_alpha[2] = {i + 'A'};
    GRRLIB_PrintfTTF (i*40+offset_x+20, offset_y + 8*40 + 16/2, font, board_alpha, 16, 0xFFFFFFFF);	
  }

  for (i = 0; i < CUI_TILE_NB; i++) {

    u32 tile_color;
    if(x == cursor_x && y == cursor_y){
      tile_color = 0x223388FF;
    }else tile_color = board->tile[i].color;
		
    GRRLIB_DrawImg(x*40+offset_x, y*40+offset_y, tex_tile, 0, 1, 1, tile_color);
        
    if ((i & 7) == 7){
      char board_num[2];
      snprintf(board_num, 2, "%d", 8-y);
      GRRLIB_PrintfTTF (offset_x - 20, y*40+offset_y + 16/2, font, board_num, 16, 0xFFFFFFFF);
			
      y++;
      x=0;
    }else{			
      x++;
    }
  }
   
  x=y=0;
  offset_x++;
  offset_y = 11;
  for (i = 0; i < CUI_TILE_NB; i++) {

    if (board->piece[i] != CUI_EMPTY){
      u32 piece_color = (board->color[i] == CUI_WHITE ? board->piece_color1 : board->piece_color2);
      GRRLIB_DrawPart(x*40+offset_x, y*40+offset_y, board->piece[i]*40, 0, 40, 100, tex_pieces, 0, 1, 1, piece_color);
    }
        
    if ((i & 7) == 7){
      y++;
      x=0;
    }else x++;
  }
}  
示例#17
0
void Button3_Theme_Paint_Offset(struct Button3* btn, int theme_id, int x_offset, int y_offset)
{
	if(btn == 0)
		return;

	if(btn->hovering)
	{
		switch (theme_id)
		{
			case 0: // black theme
				GRRLIB_DrawImg(btn->x+x_offset, btn->y+y_offset, btn->hoverTexture, 0, 1, 1, 0xFFFFFFFF);
				break;
			case 1: // white theme
				GRRLIB_DrawImg(btn->x+x_offset, btn->y+y_offset, btn->texture, 0, 1, 1, 0xFFFFFFFF);
				break;
			case 2: // blue state
			case 3:
				GRRLIB_DrawImg(btn->x+x_offset, btn->y+y_offset, btn->TriStateTexture, 0, 1, 1, 0xFFFFFFFF);
				break;
			default:
				GRRLIB_DrawImg(btn->x+x_offset, btn->y+y_offset, btn->hoverTexture, 0, 1, 1, 0xFFFFFFFF);
				break;
		}
	}
	else
	{
		switch (theme_id)
		{
			case 0: // black theme
				GRRLIB_DrawImg(btn->x+x_offset, btn->y+y_offset, btn->texture, 0, 1, 1, 0xFFFFFFFF);
				break;
			case 1: // white theme
				GRRLIB_DrawImg(btn->x+x_offset, btn->y+y_offset, btn->hoverTexture, 0, 1, 1, 0xFFFFFFFF);
				break;
			case 2: // blue state
			case 3:
				GRRLIB_DrawImg(btn->x+x_offset, btn->y+y_offset, btn->TriStateTexture, 0, 1, 1, 0xFFFFFFFF);
				break;
			default:
				GRRLIB_DrawImg(btn->x+x_offset, btn->y+y_offset, btn->texture, 0, 1, 1, 0xFFFFFFFF);
				break;
		}

	}
}
示例#18
0
void grlib_DrawImgCenter (int x, int y, int w, int h, GRRLIB_texImg * tex, f32 angle, u32 color)
	{
	f32 zx, zy;
	
	if (!tex) return;
	
	zx = (f32)w / tex->w;
	zy = (f32)h / tex->h;
	
	GRRLIB_SetHandle (tex, tex->w / 2, tex->h / 2);
	//GRRLIB_SetHandle (tex, 0,0);
	
	x -= tex->w/2;
	y -= tex->w/2;
	
	GRRLIB_DrawImg (x, y, tex, angle, zx, zy, color ); 
	}
示例#19
0
void grlib_DrawIRCursor (void)
	{
	ir_t ir;
	static u8 alphadec = 255;
	static s16 alpha = 0; // Start with cursor hidden
	static u32 cursorActivity = 0;
	
	static u32 startms = 0;
	u32 ms = ticks_to_millisecs(gettime());
	
	WPAD_IR (0, &ir);
	
	if (ms > startms)
		{
		if (cursorActivity == grlibSettings.cursorActivity)
			{
			alpha -= alphadec;
			if (alpha < 0) alpha = 0;
			}
		else
			{
			alpha = 255;
			alphadec = 5;
			cursorActivity = grlibSettings.cursorActivity;
			}
		
		startms = ms+100;
		}
	
	if (ir.valid)
		{
		grlib_irPos.x = ir.x;
		grlib_irPos.y = ir.y;
		grlib_irPos.valid = 1;
		alpha = 255;
		}
	else
		{
		grlib_irPos.valid = 0;
		}

	GRRLIB_DrawImg( grlib_irPos.x, 
					grlib_irPos.y, 
					grlibSettings.pointer[0], 0, 1, 1, RGBA(255, 255, 255, alpha) ); 
	}
示例#20
0
cui_menu menu_play(cui_game* p_game)
{
	cui_menu next_state = CUI_MENU_MAIN;
	bool done=false;
	
	GRRLIB_texImg *tex_pieces = GRRLIB_LoadTexture(chess_classic_png);
	GRRLIB_texImg *tex_tile = GRRLIB_LoadTexture(keyboard_key_png);	
	GRRLIB_ttfFont* font = GRRLIB_LoadTTF(font_ttf, font_ttf_size); 
	bool is_debug = false;

	char coords[5];
	char calculated_coords[5];
	
	strcpy(coords, "d2d20");
	strcpy(calculated_coords, "d2d20");
	
	while(!done){
		WPAD_IR(0, &ir);
		WPAD_ScanPads();
		
		u32 pressed = WPAD_ButtonsDown(0);
		u32 released = WPAD_ButtonsUp(0);
		
		if(egg_check_s1_code(pressed, released)){
			is_debug = true;
			p_game->board->tile_color1 = 0xc66300FF;
			p_game->board->tile_color2 = 0x632100FF;
			p_game->board->piece_color1 = 0x4242CCFF;
			p_game->board->piece_color2 = 0x444411FF;
			cui_board_init(p_game->board);
			if(voice) AESND_PlayVoice(voice, VOICE_STEREO8, warp, warp_size, VOICE_FREQ32KHZ, 1, false);
		}

		if ( pressed & WPAD_BUTTON_HOME ){
			if(!p_game->is_mute)AESND_Pause(true);
			if(menu_home(p_game) == CUI_MENU_EXIT){done=true;next_state=CUI_MENU_EXIT;}	
			if(!p_game->is_mute)AESND_Pause(false);
		}
		
		if ( pressed & WPAD_BUTTON_MINUS){
			switch(menu_option(p_game)){
				case CUI_MENU_OPTION_GFX:menu_option_gfx(p_game);break;
				case CUI_MENU_OPTION_SND:menu_option_snd(p_game);break;
				default:break;
			}
		}
		
		int index_offset_x = (p_game->cursor->hotspot_x - 40 / 2)/ 40 - 140 / 40;
		int index_offset_y = p_game->cursor->hotspot_y / 40 - 80 / 40;
		
		if (pressed & WPAD_BUTTON_B) {
			p_game->cursor->is_grabbing = true;
			
			if(index_offset_x >= 0 && index_offset_x < 8 && index_offset_y >= 0 && index_offset_y < 8){
				coords[0] = 'a' + index_offset_x;
				coords[1] = '8' - index_offset_y;
			}
				
		}
		else if(released & WPAD_BUTTON_B){
			p_game->cursor->is_grabbing = false;

			if(index_offset_x >= 0 && index_offset_x < 8 && index_offset_y >= 0 && index_offset_y < 8){
				coords[2] = 'a' + index_offset_x;
				coords[3] = '8' - index_offset_y;
				coords[4] = 0;

				if(voice) AESND_PlayVoice(voice, VOICE_STEREO16, move_pcm, move_pcm_size, VOICE_FREQ48KHZ, 1, false);
				
				if(calculate_coords(coords, calculated_coords, p_game->engine)){
					cui_board_read_core(p_game->board, p_game->engine);
				}
				
			}
		}
		
		cui_cursor_update(p_game->cursor, ir.x, ir.y, ir.angle);
		
		
		if(p_game->tex_wallpaper)GRRLIB_DrawImg(0, -50, p_game->tex_wallpaper, 1, 1, 1, 0XFFFFFFFF);
		
		cui_board_display(p_game->board, tex_pieces, tex_tile, font, index_offset_x, index_offset_y);
		cui_cursor_display(p_game->cursor);
		
		if(is_debug){
			GRRLIB_PrintfTTF (20, 00, font, coords, 16, 0x424242FF);
			GRRLIB_PrintfTTF2 (20, 20, font, 16, 0xFFFFFFFF, "x:%.2f y:%.2f", ir.x, ir.y);
			GRRLIB_PrintfTTF2 (20, 40, font, 16, 0xFFFFFFFF, "x:%.2f y:%.2f", ir.x/40, ir.y/40);
			GRRLIB_PrintfTTF2 (20, 60, font, 16, 0xFFFFFFFF, "x:%d y:%d", index_offset_x, index_offset_y);
			GRRLIB_PrintfTTF (20, 80, font, p_game->cursor->is_grabbing?"GRAB":"POINT", 16, 0xFFFFFFFF);
			
			GRRLIB_Rectangle(p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, 4, 4, 0xFF4242FF, 1);
		}
	
		GRRLIB_Render();
	}
	
	GRRLIB_FreeTexture(tex_pieces);
	GRRLIB_FreeTexture(tex_tile);
	GRRLIB_FreeTTF(font);
		
	return next_state;
}
示例#21
0
 int showDOLWindow(int nr)
 { 
         int ret = 1;
         bool doloop = true; 
         int fade = 5; 
         int y, sp; 
         int i;
		 
		 okButton.x = 353;
		 okButton.y = 335;
  
		 switch(nr)
		 {
			case 1:
				CFG_COUNT = CFG_METROID_COUNT;
				for ( i=0; i<CFG_COUNT; i++)
					strcpy(Episode[i], MPT_DOL[i]);
				break;
			case 2:
				CFG_COUNT = CFG_HOD23_COUNT;
				for ( i=0; i<CFG_COUNT; i++)
					strcpy(Episode[i], HOD23_DOL[i]);
				break;
		 }
  
         do{ 
			y = 115; 
			sp = 0; 

			WPAD_ScanPads(); 
			PAD_ScanPads(); 
			GetWiimoteData(); 

			draw_covers(); 
			GRRLIB_2D_Init(); 
			GRRLIB_FillScreen(0x00000000|fade); 

			GRRLIB_Rectangle(40, 106, 560, 276, 0xffffffdd, true);
			GRRLIB_Rectangle(42, 108, 556, 272, 0x737373FF, true);
			GRRLIB_Rectangle(268, 168, 304, 44, 0xffffffdd, true);
			GRRLIB_Rectangle(270, 170, 300, 40, 0x000000FF, true);

			// Get the title info
			struct discHdr *header = NULL;
			header = &self.gameList[self.gameSelected];
			char gameName[MAX_TITLE_LEN]; 

			if(self.usingTitlesTxt)
			{
				// Load a custom title
				sprintf(gameName, "%s", header->title);
				getTitle(titleList, (char*)header->id, gameName);
			}
			else
				sprintf(gameName, "%s", (header->title));

			// Chomp the title to fit
			if(strlen(gameName) >= 22)
			{
				//strncpy(gameName, header->title, 17);
				gameName[19] = '\0';
				strncat(gameName, "...", 3);
			}

			// Display Title, Last Played, and Size
			char tTemp[50];
			sprintf(tTemp,"%s",gameName);
			CFreeTypeGX_DrawText(ttf20pt, 420, 200, tTemp, (GXColor){0xff, 0xff, 0xff, 0xff}, FTGX_JUSTIFY_CENTER);
			CFreeTypeGX_DrawText(ttf20pt, 268, 149, "Episode to play ?", (GXColor){0xff, 0xff, 0xff, 0xff}, FTGX_JUSTIFY_LEFT);

			CFreeTypeGX_DrawText(ttf16pt, 350, 280, "Episode:", (GXColor){0x00, 0x00, 0x00, 0xff}, FTGX_JUSTIFY_RIGHT);
			CFreeTypeGX_DrawText(ttf16pt, 503, 280,  Episode[ret -1], (GXColor){0xff, 0xff, 0xff, 0xff}, FTGX_JUSTIFY_CENTER);


			// Draw the game cover
			if(self.gameSelected < MAX_BUFFERED_COVERS || self.gameSelected >= 0)
			{
				if(BUFFER_IsCoverReady(self.gameSelected))
				{
					pthread_mutex_lock(&buffer_mutex[self.gameSelected]);
					if(_texture_data[self.gameSelected].data)
					{
						if(CONF_GetAspectRatio() == CONF_ASPECT_16_9)
						{
							if(settings.covers3d)
							{
								GRRLIB_DrawFlatCoverImg(60, 131, _texture_data[self.gameSelected], 0, AR_16_9, 1, 0xFFFFFFFF);
							}
							else
							{
								GRRLIB_DrawImg(60, 131, _texture_data[self.gameSelected], 0, AR_16_9, 1, 0xFFFFFFFF);
							}
						}
						else
						{
							if(settings.covers3d)
							{
								GRRLIB_DrawFlatCoverImg(60, 131, _texture_data[self.gameSelected], 0, 1, 1, 0xFFFFFFFF);
							}
							else
							{
								GRRLIB_DrawImg(60, 131, _texture_data[self.gameSelected], 0, 1, 1, 0xFFFFFFFF);
							}
						}
					}
					else
					{
						if(CONF_GetAspectRatio() == CONF_ASPECT_16_9)
						{
							if(settings.covers3d)
							{
								GRRLIB_DrawFlatCoverImg(60, 131 , cover_texture_3d, 0, AR_16_9, 1, 0xFFFFFFFF);
							}
							else
							{
								GRRLIB_DrawImg(60, 131, cover_texture, 0, AR_16_9, 1, 0xFFFFFFFF);
							}
						}
						else
						{
							if(settings.covers3d)
							{
								GRRLIB_DrawFlatCoverImg(60, 131, cover_texture_3d, 0, 1, 1, 0xFFFFFFFF);
							}
							else
							{
								GRRLIB_DrawImg(60, 131, cover_texture, 0, 1, 1, 0xFFFFFFFF);
							}
						}
					}
					
					pthread_mutex_unlock(&buffer_mutex[self.gameSelected]);
				}
				else
				{	
				if(CONF_GetAspectRatio() == CONF_ASPECT_16_9)
				{
					if(settings.covers3d)
					{
						GRRLIB_DrawFlatCoverImg(60, 131, cover_texture_3d, 0, AR_16_9, 1, 0xFFFFFFFF);
					}
					else
					{
						GRRLIB_DrawImg(60, 131, cover_texture, 0, AR_16_9, 1, 0xFFFFFFFF);
					}
				}
				else
				{
					if(settings.covers3d)
					{
						GRRLIB_DrawFlatCoverImg(60, 131, cover_texture_3d, 0, 1, 1, 0xFFFFFFFF);
					}
					else
					{
						GRRLIB_DrawImg(60, 131, cover_texture, 0, 1, 1, 0xFFFFFFFF);
					}
				}
				}
			}
			else
			{
				if(CONF_GetAspectRatio() == CONF_ASPECT_16_9)
				{
					if(settings.covers3d)
					{
						GRRLIB_DrawFlatCoverImg(60, 131, cover_texture_3d, 0, AR_16_9, 1, 0xFFFFFFFF);
					}
					else
					{
						GRRLIB_DrawImg(60, 131, cover_texture, 0, AR_16_9, 1, 0xFFFFFFFF);
					}
				}
				else
				{
					if(settings.covers3d)
					{
						GRRLIB_DrawFlatCoverImg(60, 131, cover_texture_3d, 0, 1, 1, 0xFFFFFFFF);
					}
					else
					{
						GRRLIB_DrawImg(60, 131, cover_texture, 0, 1, 1, 0xFFFFFFFF);
					}
				}
			}


			Button_TTF_Paint(&okButton); 
			Button_Paint(&gDOLdownButton);
			Button_Paint(&gDOLupButton);

			DrawCursor(0, pointer.p_x, pointer.p_y, pointer.p_ang, 1, 1, 0xFFFFFFFF); 

			if ( Button_Hover(&okButton, pointer.p_x, pointer.p_y) ||
				 Button_Hover(&gDOLupButton, pointer.p_x, pointer.p_y) ||
			     Button_Hover(&gDOLdownButton, pointer.p_x, pointer.p_y) ) 
			{ 
				 // Should we be rumbling? 
				 if (--self.rumbleAmt > 0) 
						 WPAD_Rumble(0,1); // Turn on Wiimote rumble 
				 else  
						 WPAD_Rumble(0,0); // Kill the rumble 
			} 
			else 
			{ // If no button is being hovered, kill the rumble 
				 WPAD_Rumble(0,0); 
				 self.rumbleAmt = 5; 
			} 
			
			if((WPAD_ButtonsDown(0) & WPAD_BUTTON_A)||(PAD_ButtonsDown(0) & PAD_BUTTON_A))
			{
				if(Button_Select(&okButton, pointer.p_x, pointer.p_y) && WPAD_ButtonsDown(0) & WPAD_BUTTON_A) 
				{
					doloop = false;
				}
				else if (Button_Select(&gDOLdownButton, pointer.p_x, pointer.p_y))
				{ // Clicked on the episodeDOL buttons
					if (ret > 1)
					{
						ret --;
					}
					else
					{
						ret = (CFG_COUNT);
					}
				}
				else if (Button_Select(&gDOLupButton, pointer.p_x, pointer.p_y))
				{
					if (ret < (CFG_COUNT))
					{
						ret ++;
					}
					else
					{
						ret = 1;
					}
				}
			}
			GRRLIB_Render(); 
                  
         }while(doloop); 
  return ret;

}
示例#22
0
文件: main.c 项目: capz/GRRLIB
int main() {
    int i;
    int screen_index = 0;
    float t=0;
    const int R=81;
    const int r=71;
    const int d=120;
    float f=0;
    float ff=0;
    float spr=0;
    int n=1;
    float a=0;
    float cubeZ=10.0f;
    float camZ=30.0f;;

    GRRLIB_Init();
    PAD_Init();

    GRRLIB_Settings.antialias = false;

    GRRLIB_texImg *tex_screen[9];
    for(i=0; i<9; i++) {
        tex_screen[i] = GRRLIB_CreateEmptyTexture(rmode->fbWidth, rmode->efbHeight);
    }

    GRRLIB_texImg *tex_girl = GRRLIB_LoadTexture(girl);
    GRRLIB_texImg *tex_logo = GRRLIB_LoadTexture(logo);
    GRRLIB_texImg *tex_font = GRRLIB_LoadTexture(font);
    GRRLIB_InitTileSet(tex_font, 16, 16, 32);


    for(i=0;i<=255;i+=1) {
        GRRLIB_Printf((640-(16*16))/2, 200, tex_font, 0xFFFFFF00|i, 1, "HOW MANY 3D CUBE");
        GRRLIB_Printf((640-(16*20))/2, 216, tex_font, 0xFFFFFF00|i, 1, "CAN YOU DISPLAY WITH");
        GRRLIB_DrawImg((640-352)/2, 248, tex_logo, 0, 1, 1, 0xFFFFFF00|i);
        GRRLIB_Printf((640-(16*28))/2, 480-16, tex_font, 0xFFFFFF00|i, 1, "BY NONAMENO FROM GRRLIB TEAM");
        GRRLIB_Render();
    }
    for(i=255;i>=0;i-=2) {
        GRRLIB_Printf((640-(16*16))/2, 200, tex_font, 0xFFFFFF00|i, 1, "HOW MANY 3D CUBE");
        GRRLIB_Printf((640-(16*20))/2, 216, tex_font, 0xFFFFFF00|i, 1, "CAN YOU DISPLAY WITH");
        GRRLIB_DrawImg((640-352)/2, 248, tex_logo, 0, 1, 1, 0xFFFFFF00|i);
        GRRLIB_Printf((640-(16*28))/2, 480-16, tex_font, 0xFFFFFF00|i, 1, "BY NONAMENO FROM GRRLIB TEAM");
        GRRLIB_Render();
    }

    GRRLIB_SetBackgroundColour(0x00, 0x00, 0x00, 0xFF);

    while(1) {
        PAD_ScanPads();
        GRRLIB_Camera3dSettings(0.0f,0.0f,camZ, 0,1,0, 0,0,0);

        GRRLIB_2dMode();
        GRRLIB_DrawImg(0, 0, tex_screen[screen_index], 0, 1, 1, 0xFFFFFFFF);

        GRRLIB_3dMode(0.1, 1000, 45, 1, 0);
        GRRLIB_SetBlend(GRRLIB_BLEND_ALPHA);


        cubeZ+=0.02f;
        GRRLIB_ObjectView((float)(((R + r-ff)*cos(t-f) - d*cos(((R + r-f)/r)*t)))/20.0f,(float)(((R + r-ff)*sin(t) - d*sin(((R + r)/r)*t)-f))/20.0f,sin(cubeZ)*10, a,a*2,a*3,1,1,1);
        GRRLIB_SetTexture(tex_girl, 0);
        GX_Begin(GX_QUADS, GX_VTXFMT0, 24);
            GX_Position3f32(-1.0f,1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(1.0f,1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(1.0f,-1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(-1.0f,-1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(1.0f,1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(-1.0f,1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(-1.0f,-1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(1.0f,-1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(1.0f,1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(1.0f,1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(1.0f,-1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(1.0f,-1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(-1.0f,1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(-1.0f,1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(-1.0f,-1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(-1.0f,-1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(-1.0f,1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(1.0f,1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(1.0f,1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(-1.0f,1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(1.0f,-1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(-1.0f,-1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(-1.0f,-1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(1.0f,-1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);
        GX_End();

        a+=0.5f;

        GRRLIB_2dMode();
        GRRLIB_Screen2Texture(0, 0, tex_screen[screen_index], GX_FALSE);
        GRRLIB_Printf((640-(16*6*5))/2+5, 200+5, tex_font, 0x00000088, 5, "%06d",(int)spr);
        GRRLIB_Printf((640-(16*6*5))/2, 200, tex_font, 0xFFEEEE88, 5, "%06d",(int)spr);

        GRRLIB_Render();
        screen_index++;
        screen_index %= 9;
        spr+=0.1f;
        t+=0.01f;

        if(t>n*2*M_PI) {
            n++;
            f+=0.01f;
        }

        if(f>2*M_PI) {
            f=0;
            ff+=0.02f;
        }


        if(PAD_ButtonsDown(0) & PAD_BUTTON_START) exit(0);
    }
    GRRLIB_FreeTexture(tex_logo);
    GRRLIB_FreeTexture(tex_girl);
    GRRLIB_FreeTexture(tex_font);
    for(i=0; i<9; i++) {
        GRRLIB_FreeTexture(tex_screen[i]);
    }
    GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB

    return 0;
}
示例#23
0
enum e_cui_menu menu_option_gfx(cui_game* p_game)
{
	cui_menu next_state = CUI_MENU_MAIN;
	bool done=false;
	u32 option_tile_color_1 = p_game->board->tile_color1;
	u32 option_tile_color_2 = p_game->board->tile_color2;
	u32 option_piece_color_1 = p_game->board->piece_color1;
	u32 option_piece_color_2 = p_game->board->piece_color2;
	
	GRRLIB_texImg *tex_tile = GRRLIB_LoadTexture(keyboard_key_png);
	GRRLIB_texImg *tex_pieces = GRRLIB_LoadTexture(chess_classic_png);
	GRRLIB_texImg *tex_up = GRRLIB_LoadTexture(scrollbar_arrowup_png);
	GRRLIB_texImg *tex_down = GRRLIB_LoadTexture(scrollbar_arrowdown_png);
	GRRLIB_ttfFont* font = GRRLIB_LoadTTF(font_ttf, font_ttf_size);  
	
	int i,j;
	UI_button button_color[4][8];		//tile 1, tile 2, piece 1, piece 2 | R-+, G-+, B-+, A-+,
	for(i=0;i<4;i++){
		for(j=0;j<8;j++){
			UI_InitBtn(&button_color[i][j], 120 + j*64, 64 + i*80, NULL);
			button_color[i][j].img = j%2==0?tex_down:tex_up;
		}
	}
		
	UI_button button_return;
	UI_InitBtn(&button_return, 500, 400, "apply");
	button_return.img = GRRLIB_LoadTexture(button_png);
	button_return.font = font;
	
	UI_button button_cancel;
	UI_InitBtn(&button_cancel, 350, 400, "cancel");
	button_cancel.img = GRRLIB_LoadTexture(button_png);
	button_cancel.font = font;
	
	while(!done){		
		cui_game_update_cursor(p_game->cursor);
		u32 pressed = WPAD_ButtonsDown(0);
		
		
		u32* color_to_modify=NULL;
		u32 mask;
		for(i=0;i<4;i++){
			for(j=0;j<8;j++){
				UI_UpdateBtn(&button_color[i][j], p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A);
				if(button_color[i][j].click){
					switch(i){
						case 0:color_to_modify = &option_tile_color_1;break;
						case 1:color_to_modify = &option_tile_color_2;break;
						case 2:color_to_modify = &option_piece_color_1;break;
						case 3:color_to_modify = &option_piece_color_2;break;
					}
					if(j==0 || j==1)mask=0x06000000;
					if(j==2 || j==3)mask=0x00060000;
					if(j==4 || j==5)mask=0x00000600;
					if(j==6 || j==7)mask=0x00000006;
					*color_to_modify+=j%2==0?-mask:mask;
				}
			}
		}


		
		UI_UpdateBtn(&button_cancel, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A);
		UI_UpdateBtn(&button_return, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A);
		
		if(button_return.click){
			if((option_tile_color_1 != p_game->board->tile_color1) || (option_tile_color_2 != p_game->board->tile_color2)){
				p_game->board->tile_color1 = option_tile_color_1;
				p_game->board->tile_color2 = option_tile_color_2;
				cui_board_init(p_game->board);
			}
			
			if(option_tile_color_1 != p_game->board->piece_color1)p_game->board->piece_color1=option_piece_color_1;
			if(option_tile_color_2 != p_game->board->piece_color2)p_game->board->piece_color2=option_piece_color_2;
					
			done=true;
			next_state=CUI_MENU_MAIN;
		}
		
		if(button_cancel.click){
			done=true;
			next_state=CUI_MENU_MAIN;
		}
		
		if ( pressed & WPAD_BUTTON_HOME ){
			if(!p_game->is_mute)AESND_Pause(true);
			if(menu_home(p_game) == CUI_MENU_EXIT){done=true;next_state=CUI_MENU_EXIT;}	
			if(!p_game->is_mute)AESND_Pause(false);
		}

		GRRLIB_DrawImg(380, 80+140, tex_tile, 0, 2, 2, option_tile_color_1);
		GRRLIB_DrawImg(380, 180+140, tex_tile, 0, 2, 2, option_tile_color_2);
		GRRLIB_DrawImg(380+80, 80+140, tex_tile, 0, 2, 2, option_tile_color_2);
		GRRLIB_DrawImg(380+80, 180+140, tex_tile, 0, 2, 2, option_tile_color_1);
		GRRLIB_DrawImg(380+160, 80+140, tex_tile, 0, 2, 2, option_tile_color_1);
		GRRLIB_DrawImg(380+160, 180+140, tex_tile, 0, 2, 2, option_tile_color_2);
		GRRLIB_DrawImg(380, 80, tex_pieces, 0, 2, 2, option_piece_color_2);
		GRRLIB_DrawImg(380, 180, tex_pieces, 0, 2, 2, option_piece_color_1);
		
		
		GRRLIB_PrintfTTF (145, 0, font, "RED              GREEN              BLUE             ALPHA", 20, 0xFFFFFFFF);
		GRRLIB_PrintfTTF (15, 40, font, "Tiles color #1", 20, 0xFFFFFFFF);
		GRRLIB_PrintfTTF (15, 40+80, font, "Tiles color #2", 20, 0xFFFFFFFF);
		GRRLIB_PrintfTTF (15, 40+80*2, font, "Pieces color #1", 20, 0xFFFFFFFF);
		GRRLIB_PrintfTTF (15, 40+80*3, font, "Pieces color #2", 20, 0xFFFFFFFF);

		for(i=0;i<4;i++){
			for(j=0;j<8;j++){
				UI_DrawBtn(&button_color[i][j]);
			}
		}


		UI_DrawBtn(&button_return);
		UI_DrawBtn(&button_cancel);
		
		GRRLIB_Line(235, 25, 235, 350, 0xFFFFFFFF);
		GRRLIB_Line(235+64*2, 25, 235+64*2, 350, 0xFFFFFFFF);
		GRRLIB_Line(235+64*4, 25, 235+64*4, 350, 0xFFFFFFFF);
		GRRLIB_Line(235+64*6, 25, 235+64*6, 350, 0xFFFFFFFF);
		
		cui_cursor_display(p_game->cursor);
		
		GRRLIB_Render();
	}
	
	GRRLIB_FreeTexture(tex_tile);
	GRRLIB_FreeTexture(tex_pieces);
	GRRLIB_FreeTexture(tex_up);
	GRRLIB_FreeTexture(tex_down);
	GRRLIB_FreeTTF(font); 
	
	free(button_return.text);
	free(button_cancel.text);
	
	return next_state;	
}
示例#24
0
文件: main.c 项目: capz/GRRLIB
int main() {
    u32 paddown;
    s8 page = 0;

    // Font texture
    GRRLIB_texImg *text_font1 = GRRLIB_LoadTexture(font1);
    GRRLIB_InitTileSet(text_font1, 32, 36, 32);

    // Load the original texture and create empty texture of the same size as the original one
    GRRLIB_texImg *tex_pirate   = GRRLIB_LoadTexture(pirate);
    GRRLIB_texImg *tex_gray     = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_sepia    = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_invert   = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_blur1    = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_blur2    = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_blur3    = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_blur4    = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_blur5    = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_blur6    = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_pixel1   = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_pixel2   = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_pixel3   = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_pixel4   = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_pixel5   = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_pixel6   = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_scatter1 = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_scatter2 = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_scatter3 = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_scatter4 = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_scatter5 = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_scatter6 = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_fliph    = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_flipv    = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);
    GRRLIB_texImg *tex_fliphv   = GRRLIB_CreateEmptyTexture(tex_pirate->w, tex_pirate->h);

    // Let's precalculate the grayscale texture
    GRRLIB_BMFX_Grayscale(tex_pirate, tex_gray);
    GRRLIB_FlushTex(tex_gray);

    // Let's precalculate the sepia texture
    GRRLIB_BMFX_Sepia(tex_pirate, tex_sepia);
    GRRLIB_FlushTex(tex_sepia);

    // Let's precalculate the inverted color texture
    GRRLIB_BMFX_Invert(tex_pirate, tex_invert);
    GRRLIB_FlushTex(tex_invert);

    // Let's precalculate 6 differents blur texture with 6 differents blur factor
    GRRLIB_BMFX_Blur(tex_pirate, tex_blur1, 1);
    GRRLIB_FlushTex(tex_blur1);
    GRRLIB_BMFX_Blur(tex_pirate, tex_blur2, 2);
    GRRLIB_FlushTex(tex_blur2);
    GRRLIB_BMFX_Blur(tex_pirate, tex_blur3, 3);
    GRRLIB_FlushTex(tex_blur3);
    GRRLIB_BMFX_Blur(tex_pirate, tex_blur4, 4);
    GRRLIB_FlushTex(tex_blur4);
    GRRLIB_BMFX_Blur(tex_pirate, tex_blur5, 5);
    GRRLIB_FlushTex(tex_blur5);
    GRRLIB_BMFX_Blur(tex_pirate, tex_blur6, 6);
    GRRLIB_FlushTex(tex_blur6);

    // Let's precalculate 6 differents pixelate texture with 6 differents pixelate factor
    GRRLIB_BMFX_Pixelate(tex_pirate, tex_pixel1, 1);
    GRRLIB_FlushTex(tex_pixel1);
    GRRLIB_BMFX_Pixelate(tex_pirate, tex_pixel2, 2);
    GRRLIB_FlushTex(tex_pixel2);
    GRRLIB_BMFX_Pixelate(tex_pirate, tex_pixel3, 3);
    GRRLIB_FlushTex(tex_pixel3);
    GRRLIB_BMFX_Pixelate(tex_pirate, tex_pixel4, 4);
    GRRLIB_FlushTex(tex_pixel4);
    GRRLIB_BMFX_Pixelate(tex_pirate, tex_pixel5, 5);
    GRRLIB_FlushTex(tex_pixel5);
    GRRLIB_BMFX_Pixelate(tex_pirate, tex_pixel6, 6);
    GRRLIB_FlushTex(tex_pixel6);

    // Let's precalculate 6 differents pixelate texture with 6 differents pixelate factor
    GRRLIB_BMFX_Scatter(tex_pirate, tex_scatter1, 2);
    GRRLIB_FlushTex(tex_pixel1);
    GRRLIB_BMFX_Scatter(tex_pirate, tex_scatter2, 4);
    GRRLIB_FlushTex(tex_pixel2);
    GRRLIB_BMFX_Scatter(tex_pirate, tex_scatter3, 6);
    GRRLIB_FlushTex(tex_pixel3);
    GRRLIB_BMFX_Scatter(tex_pirate, tex_scatter4, 8);
    GRRLIB_FlushTex(tex_pixel4);
    GRRLIB_BMFX_Scatter(tex_pirate, tex_scatter5, 10);
    GRRLIB_FlushTex(tex_pixel5);
    GRRLIB_BMFX_Scatter(tex_pirate, tex_scatter6, 12);
    GRRLIB_FlushTex(tex_pixel6);

    // Let's precalculate for flipping the texture
    GRRLIB_BMFX_FlipH(tex_pirate, tex_fliph);
    GRRLIB_FlushTex(tex_fliph);
    GRRLIB_BMFX_FlipV(tex_pirate, tex_flipv);
    GRRLIB_FlushTex(tex_flipv);
    GRRLIB_BMFX_FlipV(tex_fliph, tex_fliphv);
    GRRLIB_FlushTex(tex_fliphv);

    GRRLIB_Init();
    PAD_Init();

    while(1) {
        PAD_ScanPads();
        paddown = PAD_ButtonsDown(0);

        GRRLIB_FillScreen(0xFFFFFFFF);

        switch(page)
        {
            case 1:
                GRRLIB_Printf(10, 10, text_font1, 0X000000FF, 1, "GRAYSCALE FX");

                GRRLIB_DrawImg(10, 60, tex_pirate, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*1, 60, tex_gray, 0, 1, 1, 0xFFFFFFFF);
                break;
            case 2:
                GRRLIB_Printf(10, 10, text_font1, 0X000000FF, 1, "SEPIA FX");

                GRRLIB_DrawImg(10, 60, tex_pirate, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*1, 60, tex_sepia, 0, 1, 1, 0xFFFFFFFF);
                break;
            case 3:
                GRRLIB_Printf(10, 10, text_font1, 0X000000FF, 1, "INVERT FX");

                GRRLIB_DrawImg(10, 60, tex_pirate, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*1, 60, tex_invert, 0, 1, 1, 0xFFFFFFFF);
                break;
            case 4:
                GRRLIB_Printf(10, 10, text_font1, 0X000000FF, 1, "FLIPH AND FLIPV FX");

                GRRLIB_DrawImg(10, 60, tex_pirate, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*1, 60, tex_fliph, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*2, 60, tex_flipv, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*3, 60, tex_fliphv, 0, 1, 1, 0xFFFFFFFF);
                break;
            case 5:
                GRRLIB_Printf(10, 10, text_font1, 0X000000FF, 1, "BLUR FX");

                GRRLIB_DrawImg(10, 60, tex_pirate, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*1, 60, tex_blur1, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*2, 60, tex_blur2, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*3, 60, tex_blur3, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10, 60+tex_pirate->h*1, tex_blur4, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*1, 60+tex_pirate->h*1, tex_blur5, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*2, 60+tex_pirate->h*1, tex_blur6, 0, 1, 1, 0xFFFFFFFF);
                break;
            case 6:
                GRRLIB_Printf(10, 10, text_font1, 0X000000FF, 1, "PIXELATE FX");

                GRRLIB_DrawImg(10, 60, tex_pirate, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*1, 60, tex_pixel1, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*2, 60, tex_pixel2, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*3, 60, tex_pixel3, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10, 60+tex_pirate->h*1, tex_pixel4, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*1, 60+tex_pirate->h*1, tex_pixel5, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*2, 60+tex_pirate->h*1, tex_pixel6, 0, 1, 1, 0xFFFFFFFF);
                break;
            case 7:
                GRRLIB_Printf(10, 10, text_font1, 0X000000FF, 1, "SCATTER FX");

                GRRLIB_DrawImg(10, 60, tex_pirate, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*1, 60, tex_scatter1, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*2, 60, tex_scatter2, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*3, 60, tex_scatter3, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10, 60+tex_pirate->h*1, tex_scatter4, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*1, 60+tex_pirate->h*1, tex_scatter5, 0, 1, 1, 0xFFFFFFFF);
                GRRLIB_DrawImg(10+tex_pirate->w*2, 60+tex_pirate->h*1, tex_scatter6, 0, 1, 1, 0xFFFFFFFF);
                break;
            default:
                GRRLIB_Printf(10, 10, text_font1, 0X000000FF, 1, "WELCOME TO THE");
                GRRLIB_Printf(10, 40, text_font1, 0X000000FF, 1, "GRRLIB FX DEMO.");
                GRRLIB_Printf(10, 80, text_font1, 0X000000FF, 1, "TO QUIT PRESS THE");
                GRRLIB_Printf(10, 120, text_font1, 0X000000FF, 1, "HOME BUTTON.");
                GRRLIB_Printf(10, 160, text_font1, 0X000000FF, 1, "USE + OR - TO MOVE");
                GRRLIB_Printf(10, 200, text_font1, 0X000000FF, 1, "ACROSS PAGES.");
        }

        GRRLIB_Render();
        if(paddown & PAD_BUTTON_START) {
            break;
        }
        if(paddown & PAD_BUTTON_X) {
            page--;
            if(page < 0) page = 7;
        }
        if(paddown & PAD_BUTTON_Y) {
            page++;
            if(page > 7) page = 0;
        }
    }
    GRRLIB_FreeTexture(tex_pirate);
    GRRLIB_FreeTexture(tex_gray);
    GRRLIB_FreeTexture(tex_sepia);
    GRRLIB_FreeTexture(tex_invert);
    GRRLIB_FreeTexture(tex_fliph);
    GRRLIB_FreeTexture(tex_flipv);
    GRRLIB_FreeTexture(tex_fliphv);
    GRRLIB_FreeTexture(tex_blur1);
    GRRLIB_FreeTexture(tex_blur2);
    GRRLIB_FreeTexture(tex_blur3);
    GRRLIB_FreeTexture(tex_blur4);
    GRRLIB_FreeTexture(tex_blur5);
    GRRLIB_FreeTexture(tex_blur6);
    GRRLIB_FreeTexture(tex_pixel1);
    GRRLIB_FreeTexture(tex_pixel2);
    GRRLIB_FreeTexture(tex_pixel3);
    GRRLIB_FreeTexture(tex_pixel4);
    GRRLIB_FreeTexture(tex_pixel5);
    GRRLIB_FreeTexture(tex_pixel6);
    GRRLIB_FreeTexture(tex_scatter1);
    GRRLIB_FreeTexture(tex_scatter2);
    GRRLIB_FreeTexture(tex_scatter3);
    GRRLIB_FreeTexture(tex_scatter4);
    GRRLIB_FreeTexture(tex_scatter5);
    GRRLIB_FreeTexture(tex_scatter6);
    GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
    return 0;
}
示例#25
0
int main() {
    int startx=0, starty=0;
    int x=0, y=0;
    int dirx=0, diry=0;
    int cptx=0, cpty=0;
    int bgx=-32, bgy=-32;
    float idperso=0;
    int i=0;
    float sinnonameno=0, oldsinnonameno=0;
    float camZ=1400.0f;
    float a=0;

    GRRLIB_Init();
    GRRLIB_Settings.antialias = false;
    WPAD_Init();
    GRRLIB_ClipDrawing(0,0,rmode->fbWidth,rmode->efbHeight);
    GRRLIB_texImg *tex_tile1 = GRRLIB_LoadTexture(tile1);
    GRRLIB_InitTileSet(tex_tile1, TileMap1Width, TileMap1Height, 0);
    GRRLIB_texImg *tex_perso = GRRLIB_LoadTexture(perso);
    GRRLIB_InitTileSet(tex_perso, 64, 64, 0);
    GRRLIB_texImg *tex_bg = GRRLIB_LoadTexture(bg);
    GRRLIB_texImg *tex_nonameno = GRRLIB_LoadTexture(nonameno);
    GRRLIB_InitTileSet(tex_nonameno, 32, 32, 0);

    GRRLIB_texImg *tex_screen = GRRLIB_CreateEmptyTexture(rmode->fbWidth, rmode->efbHeight);

    GRRLIB_SetBackgroundColour(0x00, 0x00, 0x00, 0xFF);

    while(1) {
        GRRLIB_2dMode();
        WPAD_ScanPads();
        if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)  break;
        if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_PLUS)  camZ+=20.0f;
        if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_MINUS)  camZ-=20.0f;

        if((dirx==0) && (diry==0)) {
            if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_LEFT) { diry=-4; idperso=15;}
            else if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_RIGHT) { diry=4; idperso=15;}
            else if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_DOWN) { dirx=-4 ; idperso=1;}
            else if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_UP) { dirx=4 ; idperso=8;}
        }

        if((dirx==0) && (diry==0)) {
            idperso=0;
        }

        if(((Map1Info[9+starty][10+startx]==1) || (Map1Info[9+starty][11+startx]==1)) || ((Map1Info[9+starty][10+startx]==43521) || (Map1Info[9+starty][11+startx]==43521))) {
        }
        else{
            dirx=0;
            diry=-4;
        }

        if(dirx<0) {
            if((Map1Info[7+starty][12+startx]==8) || (Map1Info[7+starty][12+startx]==2) || (Map1Info[8+starty][12+startx]==8) || (Map1Info[8+starty][12+startx]==2)) {
                dirx=0;
            }
            else {
                idperso++;
                if(idperso>7)
                    idperso=1;
            }
        }

        if(dirx>0) {
            if((Map1Info[7+starty][9+startx]==8) || (Map1Info[7+starty][9+startx]==2) || (Map1Info[8+starty][9+startx]==8) || (Map1Info[8+starty][9+startx]==2)) {
                dirx=0;
            }
            else {
                idperso++;
                if(idperso>14)
                    idperso=8;
           }
        }

        if(diry<0) {
            if((Map1Info[9+starty][10+startx]==1) || (Map1Info[9+starty][11+startx]==1)) {
                diry=0;
            }
        }

        if(diry!=0) {
            idperso++;
            if(idperso>22)
                idperso=16;
        }

        cptx+=dirx;
        if(dirx>0)
            bgx++;
        else if(dirx<0)
            bgx--;
        if((bgx>-1) || (bgx<-63))
            bgx=-32;

        if(cptx==32) {
            cptx=0;
            dirx=0;
            startx--;
        }
        else if(cptx==-32) {
            cptx=0;
            dirx=0;
            startx++;
        }

        cpty+=diry;
        if(diry>0)
            bgy++;
        else if(diry<0)
            bgy--;
        if((bgy>-1) ||(bgy<-63))
            bgy=-32;

        if(cpty==32) {
            cpty=0;
            diry=0;
            starty--;
        }
        else if(cpty==-32) {
            cpty=0;
            if(((Map1Info[9+starty][10+startx]==1) || (Map1Info[9+starty][11+startx]==1)) || ((Map1Info[9+starty][10+startx]==43521) || (Map1Info[9+starty][11+startx]==43521))) {
                diry=0;
            }
            starty++;
        }
        GRRLIB_DrawImg(bgx, bgy, tex_bg, 0, 1, 1, 0xFFFFFFFF);

        for(y=0;y<=(17);y++) {
            for(x=0;x<=(21);x++) {
            if(Map1Data[y+starty][x+startx] != 0) {
                GRRLIB_DrawTile(x*TileMap1Width+cptx-TileMap1Width,y*TileMap1Height+cpty-TileMap1Height,tex_tile1,0,1,1,0xFFFFFFFF,Map1Data[y+starty][x+startx]-1);
            }
            }
        }
        GRRLIB_DrawTile(TileMap1Width*9,TileMap1Height*6,tex_perso,0,1,1,0xFFFFFFFF,(int)idperso);

        oldsinnonameno=sinnonameno;
        for(i=0; i<8; i++) {
            GRRLIB_DrawTile(TileMap1Width*(6+i),(TileMap1Height*10)+sin(sinnonameno)*64,tex_nonameno,0,1,1,0xFFFFFFFF,i);
            sinnonameno+=0.4F;
        }
        sinnonameno=oldsinnonameno+0.08F;

        GRRLIB_Screen2Texture(0, 0, tex_screen, GX_TRUE);


        GRRLIB_Camera3dSettings(0.0f,0.0f,camZ, 0,1,0, 0,0,0);
        GRRLIB_3dMode(0.1,3000,45,1,0);
        GRRLIB_SetTexture(tex_screen,0);
        GRRLIB_ObjectView(0,0,0, a,a*2,a*3,1,1,1);
        GX_Begin(GX_QUADS, GX_VTXFMT0, 16);
            GX_Position3f32(-rmode->fbWidth/2,rmode->efbHeight/2,rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(rmode->fbWidth/2,rmode->efbHeight/2,rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(rmode->fbWidth/2,-rmode->efbHeight/2,rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(-rmode->fbWidth/2,-rmode->efbHeight/2,rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(rmode->fbWidth/2,rmode->efbHeight/2,-rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(-rmode->fbWidth/2,rmode->efbHeight/2,-rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(-rmode->fbWidth/2,-rmode->efbHeight/2,-rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(rmode->fbWidth/2,-rmode->efbHeight/2,-rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(rmode->fbWidth/2,rmode->efbHeight/2,rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(rmode->fbWidth/2,rmode->efbHeight/2,-rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(rmode->fbWidth/2,-rmode->efbHeight/2,-rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(rmode->fbWidth/2,-rmode->efbHeight/2,rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(-rmode->fbWidth/2,rmode->efbHeight/2,-rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(-rmode->fbWidth/2,rmode->efbHeight/2,rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(-rmode->fbWidth/2,-rmode->efbHeight/2,rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(-rmode->fbWidth/2,-rmode->efbHeight/2,-rmode->fbWidth/2);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);
        GX_End();

        a+=0.2f;

        GRRLIB_Render();
    }

    GRRLIB_FreeTexture(tex_tile1);
    GRRLIB_FreeTexture(tex_perso);
    GRRLIB_FreeTexture(tex_bg);
    GRRLIB_FreeTexture(tex_nonameno);
    GRRLIB_FreeTexture(tex_screen);
    GRRLIB_Exit();
    exit(0);
}
示例#26
0
void drawMenu(WPADData *wd) {
	int x,z=0,l,y,zz=0;
	GRRLIB_DrawImg(0, 0, 640, 480, tex_menuback, 0, 1, 1, 255);

	switch(curmenunum) {
		case MAIN_MENU :
			GRRLIB_DrawImg(0, 52, 608, 400, tex_menufore, 0, 1, 1, 255);

			// Overlay the Japanese name for Mahjongg Solitaire - Shanghi
			if(opt_lang==JAPANESE)
				GRRLIB_DrawImg(354, 142, 72, 40, tex_shanghi, 0, 1, 1, 255);

			for(x=0;x<5;x++) {
				GRRLIB_GPrintf(320,mainhs[x][1],0xFFFFFFFF,x==0?1.15:1,1, ALIGN_CENTRE,CUR_FONT(msel==x),curtext[LNG_MMENU_PLAY + x]);
			}

			GRRLIB_GPrintf( 10, 420, 0xFFFFFFFF, 0.5, 0.5, ALIGN_LEFT, CUR_FONT(true), VERSION_STRING);
			break;
		case PLAY_MENU :
			GRRLIB_DrawImg(34,30,576,264, tex_menufore, 0, 1, 1, 255);
			f32 zoom;
			int strlen;

			for(x=0;x<3;x++) {
				strlen = GRRLIB_GetStringWidth(CUR_FONT(false), curtext[LNG_PMENU_1PLAYER+x*2]);
				if(strlen>playhs[x][2]) {
					zoom=(float)playhs[x][2]/(float)strlen;
					GRRLIB_GPrintf(playhs[x][0],playhs[x][1],0xFFFFFFFF,zoom,1, ALIGN_LEFT,CUR_FONT(msel==x),curtext[LNG_PMENU_1PLAYER+x*2]);
				}
				else {
					GRRLIB_GPrintf(playhs[x][0]+playhs[x][2]/2,playhs[x][1],0xFFFFFFFF,1,1, ALIGN_CENTRE,CUR_FONT(msel==x),curtext[LNG_PMENU_1PLAYER+x*2]);
				}
				strlen = GRRLIB_GetStringWidth(CUR_FONT(false), curtext[LNG_PMENU_1PLAYER+x*2+1]);
				if(strlen>playhs[x][2]) {
					zoom=(float)playhs[x][2]/(float)strlen;
					GRRLIB_GPrintf(playhs[x][0],playhs[x][1]+36,0xFFFFFFFF,zoom,1, ALIGN_LEFT,CUR_FONT(msel==x),curtext[LNG_PMENU_1PLAYER+x*2+1]);
				}
				else {
					GRRLIB_GPrintf(playhs[x][0]+playhs[x][2]/2,playhs[x][1]+36,0xFFFFFFFF,1,1, ALIGN_CENTRE,CUR_FONT(msel==x),curtext[LNG_PMENU_1PLAYER+x*2+1]);
				}
			}

			GRRLIB_GPrintf(600, playhs[3][1],0xFFFFFFFF,1,1, ALIGN_RIGHT,CUR_FONT(msel==x),curtext[LNG_GAME_BACK]);

			for(x=0;x<3;x++) {
				if(!(x==msel))
					GRRLIB_DrawImg(playhs[x][0], 90, 168, 196,tex_shade, 0, 1, 1, 255);
			}
			break;
		case OPTIONS_MENU :
			GRRLIB_DrawImg(-9, 30, 640, 420, tex_menufore, 0, 1, 1, 255);

			for(x=0;x<6;x++) {
				// check if on/off entry
				if(x==4 || x==2 || x==5) {
					char buffer[60];

					strcpy(buffer,curtext[LNG_OMENU_CTILESET+x]);

					if((x==4 && opt_rumble) || (x==2 && opt_hoverhint) || (x==5 && opt_widescreen)) {
						char *s2 = strchr(buffer,'/');
						if(s2!=NULL)
							buffer[s2-buffer]='\0';
					}
					else {
						char *s2=strchr(buffer,'/') + 1;
						char *s1=strrchr(buffer,' ') + 1;
						if(s1!=NULL && s2!=NULL)
							memmove(s1,s2,60-(s2-buffer)+1);
					}

					GRRLIB_GPrintf(320,opths[x][1],0xFFFFFFFF,1,1, ALIGN_CENTRE,CUR_FONT(msel==x),buffer);

				}
				else
					GRRLIB_GPrintf(320,opths[x][1],0xFFFFFFFF,1,1, ALIGN_CENTRE,CUR_FONT(msel==x),curtext[LNG_OMENU_CTILESET+x]);
			}
			GRRLIB_GPrintf(600, opths[6][1],0xFFFFFFFF,1,1, ALIGN_RIGHT,CUR_FONT(msel==x),curtext[LNG_GAME_BACK]);

			break;
		case SOUND_MENU :
			GRRLIB_DrawImg(86,30,524,436, tex_menufore, 0, 1, 1, 255);

			for(x=0;x<2;x++) {
				GRRLIB_GPrintf(320,soundhs[x+3][1],0xFFFFFFFF,1,1, ALIGN_CENTRE,CUR_FONT(msel==x),curtext[LNG_SMENU_MUSIC+x]);
			}
			GRRLIB_GPrintf(600, soundhs[2][1],0xFFFFFFFF,1,1, ALIGN_RIGHT,CUR_FONT(msel==x),curtext[LNG_GAME_BACK]);

			// draw the offs
			GRRLIB_GPrintf(186,115,0xFFFFFFFF,1,1, ALIGN_RIGHT,CUR_FONT(false),curtext[LNG_SMENU_MUSIC+2]);
			GRRLIB_GPrintf(186,224,0xFFFFFFFF,1,1, ALIGN_RIGHT,CUR_FONT(false),curtext[LNG_SMENU_MUSIC+2]);

			// draw the fulls
			GRRLIB_GPrintf(454,115,0xFFFFFFFF,1,1, ALIGN_LEFT,CUR_FONT(false),curtext[LNG_SMENU_MUSIC+3]);
			GRRLIB_GPrintf(454,224,0xFFFFFFFF,1,1, ALIGN_LEFT,CUR_FONT(false),curtext[LNG_SMENU_MUSIC+3]);

			if(msel==0) {
				if(wd->btns_h & WPAD_BUTTON_A)
					GRRLIB_DrawImg(xmusic-4, soundhs[0][1]-2, 60, 60, tex_sball, 0, 1, 1, 255);
				else
					GRRLIB_DrawImg(xmusic, soundhs[0][1]+2, 44, 44, tex_uball, 0, 1, 1, 255);
			}
			else
				GRRLIB_DrawImg(xmusic, soundhs[0][1]+2, 44, 44, tex_uball, 0, 1, 1, 255);

			if(msel==1) {
				if(wd->btns_h & WPAD_BUTTON_A)
					GRRLIB_DrawImg(xsound-4, soundhs[1][1]-2, 60, 60, tex_sball, 0, 1, 1, 255);
				else
					GRRLIB_DrawImg(xsound, soundhs[1][1]+2, 44, 44, tex_uball, 0, 1, 1, 255);
			}
			else
				GRRLIB_DrawImg(xsound, soundhs[1][1]+2, 44, 44, tex_uball, 0, 1, 1, 255);

			break;
		case LANG_MENU :
			for(x=0;x<9;x++) {
				// set
				int tx = x + (curpage==0?0:9);
				// only show if overall less then number of languages supported
				if(tx<=13) {
					if(x==msel) {
						zz=512-oldz;
						for(y=0;y<108;y+=4) {
							z=oldz;
							for(l=0;l<148;l+=4) {
								GRRLIB_DrawGTile(langhs[x][0]-5+l+SinTab[zz%SinSize]/4,langhs[x][1]+y+SinTab[z%SinSize]/4,4,4,tex_flags,148,108,0,1.1,1.1,0xFFFFFFFF,(tx%4)*37+(tx/4)*27*37*4 +l/4+(y/4)*37*4);
								z++;
							}
							zz--;
						}
					}
					else
						GRRLIB_DrawGTile(langhs[x][0],langhs[x][1],148,108,tex_flags,4,4,0,1,1,0xFFEEEEEE,tx);

					GRRLIB_DrawGTile(langhs[x][0]-8,langhs[x][1]+80,160,40,tex_languages,4,4,0,1,1,0xFFFFFFFF,tx);
				}
			}

			oldz+=1;
			if(oldz>=256) oldz=0;

			if(curpage==0) {
				if(btnover)
					GRRLIB_DrawImg(580,220,40,40, tex_plus, 0, 1, 1, 255);
				else
					GRRLIB_DrawImg(580,220,40,40, tex_plus, 0, 0.8, 0.8, 127);
			}
			else {
				if(btnover)
					GRRLIB_DrawImg(10,220,40,40, tex_minus, 0, 1, 1, 255);
				else
					GRRLIB_DrawImg(10,220,40,40, tex_minus, 0, 0.8, 0.8, 128);
			}

			break;
		case LAYOUT_MENU :
			GRRLIB_GPrintf(320,27,0xFFFFFFFF,1,1, ALIGN_CENTRE,CUR_FONT(true),curtext[LNG_OMENU_CLAYOUT]);

			for(x=0;x<6;x++) {
				GRRLIB_DrawImg(layouths[x][0],layouths[x][1]-10,180,208, tex_layout, 0, 1, 0.8, 255);
				int tx = x + (curpage==0?0:6);
				drawLayout(tx);
			}

			for(x=0;x<6;x++) {
				int tx = x + (curpage==0?0:6);
				if(!(x==msel))
					GRRLIB_DrawImg(layouths[x][0]+4, layouths[x][1]-8, 168, 196,tex_shade, 0, 1, 0.8, 255);
					if(opt_lang==JAPANESE)
						GRRLIB_GPrintf(layouths[x][0]+92,layouths[x][1]+152,0xFFFFFFFF,1,0.8, ALIGN_CENTRE,CUR_FONT(msel==x),curtext[LNG_LAYOUT_DEFAULT+tx]);
					else
						GRRLIB_GPrintf(layouths[x][0]+77,layouths[x][1]+152,0xFFFFFFFF,0.55,0.8, ALIGN_CENTRE,CUR_FONT(msel==x),curtext[LNG_LAYOUT_DEFAULT+tx]);
			}

			if(curpage==0) {
				if(btnover)
					GRRLIB_DrawImg(600,240,40,40, tex_plus, 0, 1, 1, 255);
				else
					GRRLIB_DrawImg(600,240,40,40, tex_plus, 0, 0.8, 0.8, 127);
			}
			else {
				if(btnover)
					GRRLIB_DrawImg(0,240,40,40, tex_minus, 0, 1, 1, 255);
				else
					GRRLIB_DrawImg(0,240,40,40, tex_minus, 0, 0.8, 0.8, 128);
			}
			break;
		case TILESET_MENU :
		{
			GRRLIB_GPrintf(320,27,0xFFFFFFFF,1,1, ALIGN_CENTRE,CUR_FONT(true),curtext[LNG_OMENU_CTILESET]);

			for(x=0;x<6;x++) {
				GRRLIB_DrawImg(layouths[x][0],layouths[x][1]-10,180,208, tex_layout, 0, 1, 0.8, 255);

				GRRLIB_DrawImg(layouths[x][0]+4-236,layouths[x][1]-148,640,480,tex_bk[x],0,0.24,0.3,255);

				GRRLIB_DrawImg(layouths[x][0]+4,layouths[x][1]-10+3,168, 200, tex_border, 0, 1, 0.8, 255);

				for(y=0;y<4;y++) {
					GRRLIB_DrawGTile(layouths[x][0]+21+y*30,layouths[x][1]+29+y*22,44,60,tex_tiles[x],21,2,0,1,1,0xFFFFFFFF,y*11);
				}
			}

			for(x=0;x<6;x++) {
				if(!(x==msel))
					GRRLIB_DrawImg(layouths[x][0]+4, layouths[x][1]-8, 168, 196,tex_shade, 0, 1, 0.8, 255);
					if(opt_lang==JAPANESE)
						GRRLIB_GPrintf(layouths[x][0]+92,layouths[x][1]+152,0xFFFFFFFF,1,0.8, ALIGN_CENTRE,CUR_FONT(msel==x),curtext[LNG_TILESET_DEFAULT+x]);
					else
						GRRLIB_GPrintf(layouths[x][0]+77,layouths[x][1]+152,0xFFFFFFFF,0.55,0.8, ALIGN_CENTRE,CUR_FONT(msel==x),curtext[LNG_TILESET_DEFAULT+x]);
			}
		}
		break;
		case HIGHSCORE_MENU:
		{
		    drawHighscoreMenu();
		}
		break;
	}
}
示例#27
0
int main() {
    // Perso init position
	int startPosX = 9;
	int startPosY = 6;
	
	// Perso size
	int persoHalfHeight = 1;
	int persoHeight     = 2;
	int persoHalfWidth  = 1;
	int persoWidth      = 2;
	
	// Map position
	int posX = startPosX;
    int posY = startPosY;
	
    int cptx = 0, cpty = 0;
    int bgx = -32, bgy = -32;
	
	
	// Counters used to process each tile of the map
    int x = 0;
    int y = 0;
	
	// Directions X/Y, defined by controls
    int dirx = 0;
    int diry = 0;
	
	// Frame number to draw of the perso
    float idperso = 0;
	
	// Counter of letters displaying on top layer 
    int i = 0;
	// Used to move letters following a sinusoidal signal
    float sinnonameno    = 0;
	float oldsinnonameno = 0;


    ////////////////
	// SYSTEM INITS
	////////////////

    // Init Video mode, aspect ratio, FIFO buffer, FAT system, so on.
    GRRLIB_Init();
		
	// Init Controls (Wiimote, Balance board, Sensor bar, so on.)
    WPAD_Init();
	

    /////////////////////////////
	// LOAD TEXTURES / TILESETS
    /////////////////////////////
		
	// Load texture from image (c array)
    GRRLIB_texImg *tex_tile1 = GRRLIB_LoadTexture(tile1);
	// Handle the texture to be used (set number of tiles, start position, offset position, so on)
    GRRLIB_InitTileSet(tex_tile1, TileMapWidth, TileMapHeight, 0);
	
	// Load texture from image (c array)
    GRRLIB_texImg *tex_perso = GRRLIB_LoadTexture(perso);
	// Handle the texture to be used (set number of tiles, start position, offset position, so on)
    GRRLIB_InitTileSet(tex_perso, 64, 64, 0);
	
	// Load texture from image (c array)
    GRRLIB_texImg *tex_bg = GRRLIB_LoadTexture(bg);
	
	// Load texture from image (c array)
    GRRLIB_texImg *tex_nonameno = GRRLIB_LoadTexture(nonameno);
	// Handle the texture to be used (set number of tiles, start position, offset position, so on)
    GRRLIB_InitTileSet(tex_nonameno, 32, 32, 0);

    // Load texture to draw text (native printf doesn't work with GRRLib)
    GRRLIB_texImg *tex_BMfont1 = GRRLIB_LoadTexture(BMfont1);
	// Handle the texture to be used, in order to draw characters from the fonttype
    GRRLIB_InitTileSet(tex_BMfont1, 32, 32, 32);


    ////////////////
    // ENDLESS LOOP
	////////////////
    while(1) {
	    // Get status of Wii controller
        WPAD_ScanPads();
		
		// If HOME button is pressed, the loop is interrupted. 0 is the Wiimote channel (Wiimote number 1 out of 4).
		// WPAD_ButtonsXXX returns a hexadecimal value representing all buttons down. The mask on HOME button allows to check if this buttons is pressed
		// (HOME button hexadecimal value: 0x0080)
        if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) {
          break;
		}

        
        // Set directions X/Y values and perso frame to display, depending controls
        
        if ((dirx == 0) && (diry == 0)) {
            if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_LEFT) { // If LEFT button is held : go bottom
			  diry    = -4; // move perso 4px on bottom
			  idperso = 15; // select frame 15 of the perso (back)
			} else if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_RIGHT) { // If RIGHT button is held : go top
			  diry    = 4;  // move perso 4px on top
			  idperso = 15; // select frame 15 of the perso (back)
			} else if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_DOWN) { // If DOWN button is held : go right
			  dirx    = -4; // move perso 4px on right
			  idperso = 1;  // select frame 1 of the perso (watching on his right)
			} else if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_UP) { // If UP button is held : go left
			  dirx    = 4;  // move perso 4px on left
			  idperso = 8;  // select frame 4 of the perso (watching on his left)
			}
        }


        // If no movement, select frame 0 of the perso (front of the screen)
        if ((dirx == 0) && (diry == 0)) {
            idperso = 0;
        }


        if 	(
		        (
				    // Checks if ground at bottom (grey ground only)
		            (Map1Info[posY + persoHeight + 1][posX + persoWidth] == 1) || (Map1Info[posY + persoHeight + 1][posX + persoHalfWidth] == 1)
			    ) 
			    || 
			    (
				    // Checks if ladder at bottom. Allow to move freely on ladders
					(Map1Info[posY + persoHeight + 1][posX + persoWidth] == 10064) || (Map1Info[posY + persoHeight + 1][posX + persoHalfWidth] == 10064)
				)
		    ) 
		{
			// Does nothing there
        } else { 
		    // Any case: fall
            dirx = 0; 
            diry = -4;
        }


        // Debug (got the values at this step, but printed later)
        int printDirX = dirx;
		int printDirY = diry;
		int printPosX = posX;
		int printPosY = posY;


        if (dirx < 0) { // If goes on RIGHT
		    // Checks collide on right to column
            if 	(
			
					(Map1Info[posY + persoHalfHeight][posX + persoWidth + 1] == 8) 
					|| 
					(Map1Info[posY + persoHalfHeight][posX + persoWidth + 1] == 2) 
					|| 
					(Map1Info[posY + persoHeight][posX + persoWidth + 1] == 8) 
					|| 
					(Map1Info[posY + persoHeight][posX + persoWidth + 1] == 2)
				) 
			{
                dirx = 0;
            } else {
				// Animation walking on right
                idperso++;
                if (idperso > 7) {
                    idperso = 1;
				}
            }
        } else if (dirx > 0) { // If goes on LEFT
			// Checks collide on left to column
            if	(
			
			        (Map1Info[posY + persoHalfHeight][posX] == 8) 
					|| 
					(Map1Info[posY + persoHalfHeight][posX] == 2) 
					|| 
					(Map1Info[posY + persoHeight][posX] == 8) 
					|| 
					(Map1Info[posY + persoHeight][posX] == 2)
				) 
			{
                dirx = 0;
            } else {
				// Animation walking on left
                idperso++;
                if (idperso > 14) {
                    idperso = 8;
				}
           }
        }


        // Jumping
        if (diry < 0) { 
		    // Checks if bottom tile is grey ground
            if ((Map1Info[posY + persoHeight + 1][posX + persoWidth] == 1) || (Map1Info[posY + persoHeight + 1][posX + persoHalfWidth] == 1)) {
                diry = 0;
            }
        }
		
		// Animation while jumping / falling / climbing a ladder
        if (diry != 0) {
            idperso++;
            if (idperso > 22) {
                idperso = 16;
			}
        }



		
		// Move the background horizontally
        if (dirx > 0) {
			bgx++;
        } else if (dirx < 0) {
            bgx--;
		}
        if ((bgx > -1) || (bgx < -63)) {
            bgx = -32;
		}


        // Move the map horizontally depending perso movements.
		// This allows to display map 4pixels per 4pixels, instead of tile per tile
        cptx += dirx;
        if (cptx == TileMapWidth) {
            cptx = 0;
            dirx = 0;
            posX--;
        } else if (cptx == -TileMapWidth) {
            cptx = 0;
            dirx = 0;
            posX++;
        }

        
		// Move the background vertically
        if (diry > 0) {
            bgy++;
        } else if (diry < 0) {
            bgy--;
		}
        if ((bgy > -1) || (bgy < -63)) {
            bgy = -32;
		}


        // Move the map vertically depending perso movements
		// This allows to display map 4pixels per 4pixels, instead of tile per tile
        cpty += diry;
        if (cpty == TileMapHeight) {
            cpty = 0;
            diry = 0;
            posY--;
        } else if (cpty == -TileMapHeight) {
            cpty = 0;
			
			// We check if perso is on the ground or on a ladder.
			// It allows to let the animation of fall/jump to continue to run instead.
            if	(
					(
						(Map1Info[posY + persoHeight + 1][posX + persoWidth] == 1) 
						|| 
						(Map1Info[posY + persoHeight + 1][posX + persoHalfWidth] == 1)
					) 
					|| 
					(
						(Map1Info[posY + persoHeight + 1][posX + persoWidth] == 10064) 
						|| 
						(Map1Info[posY + persoHeight + 1][posX + persoHalfWidth] == 10064)			
					)
				) 
			{
                diry = 0;
            }
			
            posY++;
        }
		
		
		//////////////////////////
		// DRAWING THE BACKGROUND
		//////////////////////////
		
        GRRLIB_DrawImg(bgx,       // X of upper left corner
		               bgy,       // Y of upper left corner
					   tex_bg,    // texture
					   0,         // rotation
					   1,         // scale X
					   1,         // scale Y
					   0xFFFFFFFF // color
					  );


		////////////////////////////////
		// DRAWING EACH TILE OF THE MAP
        ////////////////////////////////

        // Reminder:
		//   TileMapWidth  = 32px
		//   TileMapHeight = 32px

        // Process 17 tiles on height of the screen (17 x 32px = 512px)
        for (y = 0; y <= (16); y++) {
			// Process 22 tiles on width of the screen (22 * 32 = 704px)
            for (x = 0; x <= (21); x++) {
			    // Only displays tiles with content (others are "transparent" on the screen)
                if (Map1Data[y + posY - startPosY][x + posX - startPosX] != 0) {
                    GRRLIB_DrawTile(x * TileMapWidth + cptx - TileMapWidth, 					// X position to draw (upper left)
					                y * TileMapHeight + cpty - TileMapHeight,					// Y position to draw (upper left)
									tex_tile1,													// texture of the tileset
									0,															// rotation
									1,															// scale X
									1,															// scale Y
									0xFFFFFFFF,													// color
									Map1Data[y + posY - startPosY][x + posX - startPosX] - 1 	// Frame to display (from the tileset)
								   );
                }
            }
        }
		
		
		/////////////////////
		// DRAWING THE PERSO
		/////////////////////
		
        GRRLIB_DrawTile(TileMapWidth * startPosX,  // horizontal center of the screen
						TileMapHeight * startPosY, // vertical center of the screen
						tex_perso, 				    // texture of the tileset
						0, 						    // rotation
						1, 						    // scale X
						1, 						    // scale Y
						0xFFFFFFFF, 			    // color
						(int)idperso			    // Frame to display (from the tileset)
					   );

        
		
		///////////////////////////////////
		// LETTERS MOVING ON A SIN SIGNAL
		///////////////////////////////////
		oldsinnonameno = sinnonameno;
        for (i = 0; i < 8; i++) {
            GRRLIB_DrawTile(TileMapWidth * (6 + i), 
			                (TileMapHeight * 10) + sin(sinnonameno) * 64, 
							tex_nonameno, 
							0, 												// rotation
							1, 												// scale X
							1, 												// scale Y
							0xFFFFFFFF, 									// color
							i
						   );
            sinnonameno += 0.4F;
        }
        sinnonameno = oldsinnonameno + 0.08F;
		

        // Debugging
		
		GRRLIB_Printf(0, 0, tex_BMfont1, 0xFFFFFFFF, 1, "X:%d Y:%d SX:%d SY:%d", printDirX, printDirY, printPosX, printPosY);
		GRRLIB_Printf(0, 32, tex_BMfont1, 0xFFFFFFFF, 1, "CX:%d CY:%d", cptx, cpty);
		
				
		/////////////
		// RENDERING
		/////////////
		
		GRRLIB_Render();
    }


    // Free textures
    GRRLIB_FreeTexture(tex_tile1);
    GRRLIB_FreeTexture(tex_perso);
    GRRLIB_FreeTexture(tex_bg);
    GRRLIB_FreeTexture(tex_nonameno);
	GRRLIB_FreeTexture(tex_BMfont1);
	
	
	// Free screen access / frame buffers / FIFO to allow 
	// next app to handle the system without any trouble
    GRRLIB_Exit();

    exit(0);
}
示例#28
0
文件: main.c 项目: rp-/wii-mahjong
int main(int argc, char* argv[])
{
    u8 *tex_ptrone=GRRLIB_LoadTexture(handpointerred_png);
    u8 *tex_ptrtwo=GRRLIB_LoadTexture(handpointergreen_png);
    u8 *tex_back=GRRLIB_LoadJPG(bigmenuback_jpg, bigmenuback_jpg_size);
    u8 *tex_fore=GRRLIB_LoadTexture(credits_png);

    fatInitDefault();
    GRRLIB_InitVideo();
    WPAD_Init();

    SYS_SetResetCallback(WiiResetPressed);
    SYS_SetPowerCallback(WiiPowerPressed);
    WPAD_SetPowerButtonCallback(WiimotePowerPressed);
    rmode = VIDEO_GetPreferredMode(NULL);

    AESND_Init(NULL);
    MODPlay_Init(&mod_track);
    Init_Voice();

    AESND_Pause(0);                // the sound loop is running now

                                 // set the MOD song
    if (MODPlay_SetMOD (&mod_track, dojo_dan_oriental_mod) < 0 ) {
        MODPlay_Unload (&mod_track);
    } else {
        // set the music volume to the minimum so we don't hear the music before saved volume is known
        MODPlay_SetVolume( &mod_track, 0,0);
        MODPlay_Start (&mod_track);// Play the MOD
    }

    WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);

    WPAD_SetVRes(WPAD_CHAN_ALL, rmode->fbWidth, rmode->xfbHeight);

    initMain();

    MODPlay_SetVolume( &mod_track, opt_music, opt_music);

    while( HWButton == 0) {
        WPAD_ScanPads();
        u32 wpad_one_down = WPAD_ButtonsDown(0);
        u32 wpad_two_down = WPAD_ButtonsDown(1);

        u32 type;
        WPADData *wd_one, *wd_two;
        WPAD_ReadPending(WPAD_CHAN_ALL, countevs);
        WPAD_Probe(WPAD_CHAN_ALL, &type);

        wd_one = WPAD_Data(0);
        wd_two = WPAD_Data(1);

        switch(main_mode) {
            case STARTUP :
                GRRLIB_FillScreen(0xFF000000);
                GRRLIB_DrawImg(0, 0, 640, 480, tex_back, 0, 1, 1, alpha>255?255:alpha);
                GRRLIB_DrawImg(68,308, 256, 80, tex_fore, 0, 1, 1, alpha>255?255:alpha);
                if(alpha++>394 || wpad_one_down > 0) {
                    main_mode=MENU;
                    if(tex_back) free(tex_back);
                    if(tex_fore) free(tex_fore);
                    initMenu();
                }
                break;
            case MENU :
                GRRLIB_FillScreen(0xFF000000);
                int menuopt = menuWiimote(wd_one,wpad_one_down);
                if(menuopt==EXIT) {
                    if(tex_ptrone) free(tex_ptrone);
                    if(tex_ptrtwo) free(tex_ptrtwo);
                }

                if(menuopt>NOTHING) {
                    processMenuOption(menuopt);
                    if(main_mode==GAME) {
                        MODPlay_Unload (&mod_track);
                        if(opt_tileset==SPOOKY)
                            MODPlay_SetMOD (&mod_track, graveyard_mod);
                        else
                        if(opt_tileset==EGYPTIAN)
                            MODPlay_SetMOD (&mod_track, egypt_crap_mod);
                        else
                        if(opt_tileset==SIMPLE)
                            MODPlay_SetMOD (&mod_track, childhood_mod);
                        else
                        if(opt_tileset==SPACE)
                            MODPlay_SetMOD (&mod_track, nebulos_mod);
                        else
                            MODPlay_SetMOD (&mod_track, sushi_mod);
                        MODPlay_SetVolume( &mod_track, opt_music, opt_music);
                        MODPlay_Start (&mod_track);
                    }
                    else
                        drawMenu(wd_one);
                }
                else
                    drawMenu(wd_one);
                break;
            case GAME :
                if(gameWiimote(wd_one,wpad_one_down,wd_two,wpad_two_down)) {
                    // we are exiting the game back to the menu
                    main_mode=MENU;
                    MODPlay_Unload (&mod_track);
                    MODPlay_SetMOD (&mod_track, dojo_dan_oriental_mod);
                    MODPlay_SetVolume( &mod_track, opt_music, opt_music);
                    MODPlay_Start (&mod_track);
                    killGame();
                    initMenu();
                }
                else {
                    drawGame();
                }
                break;
        }

        // alternate which pointer is on top every frame to not give the advantage to player one in two player mode
        static int ticktock=0;

        ticktock++;

        if(wd_two->ir.valid && ticktock%2==0) {
            if(main_mode==GAME && whatGameMode()==ONE_PLAYER_GAME) {
                // don't display second pointer in one player mode
            }
            else
                GRRLIB_DrawColImg(wd_two->ir.x - 9,wd_two->ir.y - 7,68,80,tex_ptrtwo,0,1,1,0xEEFFFFFF);
        }

        if(wd_one->ir.valid) {
            GRRLIB_DrawColImg(wd_one->ir.x - 9,wd_one->ir.y - 7,68,80,tex_ptrone,0,1,1,0xEEFFFFFF);
        }

        if(wd_two->ir.valid && ticktock%2!=0) {
            if(main_mode==GAME && whatGameMode()==ONE_PLAYER_GAME) {
                // don't display second pointer in one player mode
            }
            else
                GRRLIB_DrawColImg(wd_two->ir.x - 9,wd_two->ir.y - 7,68,80,tex_ptrtwo,0,1,1,0xEEFFFFFF);
        }

        if(wd_one->btns_h & WPAD_BUTTON_1) {
            GRRLIB_ScrShot("MahjonggWii_Screen_%y%m%d_%H%M%S.png",time(NULL));
        }

        GRRLIB_Render();
    }

    // we are exiting, free the mallocs
    switch( main_mode) {
        case GAME:
            killGame();

    }
    if(tex_ptrone) free(tex_ptrone);
    if(tex_ptrtwo) free(tex_ptrtwo);
    killMenuLanguages();
    MODPlay_Unload (&mod_track);
    Free_Voice();
    WPAD_Shutdown();
    GRRLIB_Stop();
    saveConfig(FILE_CFG);
    SYS_ResetSystem(HWButton, 0, 0);

    return 0;
}
示例#29
0
文件: main.c 项目: capz/GRRLIB
int main() {
    int i;
    int screen_index = 0;
    float t = 0;
    const int R = 81;
    const int r = 71;
    const int d = 120;
    float f = 0;
    float ff = 0;
    float spr = 0;
    int n = 1;


    GRRLIB_Init();
    PAD_Init();

    GRRLIB_Settings.antialias = false;

    GRRLIB_texImg *tex_screen[10];
    for(i=0; i<10; i++) {
        tex_screen[i] = GRRLIB_CreateEmptyTexture(rmode->fbWidth, rmode->efbHeight);
    }

    GRRLIB_texImg *tex_ball = GRRLIB_LoadTexture(ball);
    GRRLIB_texImg *tex_logo = GRRLIB_LoadTexture(logo);
    GRRLIB_texImg *tex_font = GRRLIB_LoadTexture(font);
    GRRLIB_InitTileSet(tex_font, 16, 16, 32);


    for(i=0;i<=255;i+=1) {
        GRRLIB_Printf((640-(16*16))/2, 200, tex_font, 0xFFFFFF00|i, 1, "HOW MANY SPRITES");
        GRRLIB_Printf((640-(16*20))/2, 216, tex_font, 0xFFFFFF00|i, 1, "CAN YOU DISPLAY WITH");
        GRRLIB_DrawImg((640-352)/2, 248, tex_logo, 0, 1, 1, 0xFFFFFF00|i);
        GRRLIB_Printf((640-(16*28))/2, 480-16, tex_font, 0xFFFFFF00|i, 1, "BY NONAMENO FROM GRRLIB TEAM");
        GRRLIB_Render();
    }
    for(i=255;i>=0;i-=2) {
        GRRLIB_Printf((640-(16*16))/2, 200, tex_font, 0xFFFFFF00|i, 1, "HOW MANY SPRITES");
        GRRLIB_Printf((640-(16*20))/2, 216, tex_font, 0xFFFFFF00|i, 1, "CAN YOU DISPLAY WITH");
        GRRLIB_DrawImg((640-352)/2, 248, tex_logo, 0, 1, 1, 0xFFFFFF00|i);
        GRRLIB_Printf((640-(16*28))/2, 480-16, tex_font, 0xFFFFFF00|i, 1, "BY NONAMENO FROM GRRLIB TEAM");
        GRRLIB_Render();
    }

    while(1) {
        PAD_ScanPads();

        GRRLIB_DrawImg(0, 0, tex_screen[screen_index], 0, 1, 1, 0xFFFFFFFF);
        GRRLIB_DrawImg(((R + r-ff)*cos(t-f) - d*cos(((R + r-f)/r)*t))+rmode->fbWidth/2-32, ((R + r-ff)*sin(t) - d*sin(((R + r)/r)*t)-f)+rmode->efbHeight/2-32, tex_ball, 1, 1, 1, 0xFFFFFFFF);
        GRRLIB_Screen2Texture(0, 0, tex_screen[screen_index], GX_FALSE);
        GRRLIB_Printf((640-(16*6*5))/2+5, 200+5, tex_font, 0x00000088, 5, "%06d",(int)spr);
        GRRLIB_Printf((640-(16*6*5))/2, 200, tex_font, 0xFFEEEE88, 5, "%06d",(int)spr);

        GRRLIB_Render();
        screen_index++;
        screen_index %= 10;
        spr+=0.1f;
        t+=0.01f;

        if(t>n*2*M_PI) {
            n++;
            f+=0.01f;
        }

        if(f>2*M_PI) {
            f=0;
            ff+=0.02f;
        }


        if(PAD_ButtonsDown(0) & PAD_BUTTON_START) exit(0);

    }
    GRRLIB_FreeTexture(tex_logo);
    GRRLIB_FreeTexture(tex_ball);
    GRRLIB_FreeTexture(tex_font);
    for(i=0; i<10; i++) {
        GRRLIB_FreeTexture(tex_screen[i]);
    }
    GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
    return 0;
}