[CHG] Improve template with almost everything

This commit is contained in:
Crayon2000 2009-01-26 08:03:53 +00:00
parent 03ca45bf76
commit adaa54dfe3
4 changed files with 1301 additions and 13 deletions

View file

@ -116,8 +116,8 @@ void GRRLIB_NGoneFilled(Vector v[], u32 color, long n) {
void GRRLIB_InitTileSet(struct GRRLIB_texImg *tex, unsigned int tilew, unsigned int tileh, unsigned int tilestart) { void GRRLIB_InitTileSet(struct GRRLIB_texImg *tex, unsigned int tilew, unsigned int tileh, unsigned int tilestart) {
tex->tilew = tilew; tex->tilew = tilew;
tex->tileh = tileh; tex->tileh = tileh;
tex->nbtilew = tex->w/tilew; tex->nbtilew = tex->w / tilew;
tex->nbtileh = tex->h/tileh; tex->nbtileh = tex->h / tileh;
tex->tilestart = tilestart; tex->tilestart = tilestart;
} }

1181
template/source/gfx/link.h Normal file

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -18,6 +18,18 @@
#include "gfx/BMfont3.h" #include "gfx/BMfont3.h"
#include "gfx/BMfont4.h" #include "gfx/BMfont4.h"
#include "gfx/test_jpg.h" #include "gfx/test_jpg.h"
#include "gfx/link.h"
// Tile stuff
#define TILE_DELAY 10
#define TILE_UP 12*0
#define TILE_RIGHT 12*1
#define TILE_DOWN 12*2
#define TILE_LEFT 12*3
#define TILE_UP2 12*4+9
#define TILE_RIGHT2 12*5+9
#define TILE_DOWN2 12*6+9
#define TILE_LEFT2 12*7+9
// RGBA Colors // RGBA Colors
#define GRRLIB_BLACK 0x000000FF #define GRRLIB_BLACK 0x000000FF
@ -32,7 +44,8 @@
Mtx GXmodelView2D; Mtx GXmodelView2D;
int main() { int main() {
int left = 0; int left = 0, top = 0, page = 0, frame = TILE_DOWN + 1;
unsigned int wait = TILE_DELAY, direction = TILE_DOWN, direction_new = TILE_DOWN;
ir_t ir1; ir_t ir1;
u32 wpaddown, wpadheld; u32 wpaddown, wpadheld;
@ -44,6 +57,9 @@ int main() {
GRRLIB_texImg tex_test_jpg = GRRLIB_LoadTextureJPG(test_jpg); GRRLIB_texImg tex_test_jpg = GRRLIB_LoadTextureJPG(test_jpg);
GRRLIB_texImg tex_link_png = GRRLIB_LoadTexturePNG(link);
GRRLIB_InitTileSet(&tex_link_png, 24, 32, 0);
GRRLIB_texImg tex_BMfont1 = GRRLIB_LoadTexturePNG(BMfont1); GRRLIB_texImg tex_BMfont1 = GRRLIB_LoadTexturePNG(BMfont1);
GRRLIB_InitTileSet(&tex_BMfont1, 32, 32, 32); GRRLIB_InitTileSet(&tex_BMfont1, 32, 32, 32);
@ -57,7 +73,7 @@ int main() {
GRRLIB_InitTileSet(&tex_BMfont4, 16, 16, 32); GRRLIB_InitTileSet(&tex_BMfont4, 16, 16, 32);
while(1){ while(1) {
WPAD_SetVRes(0, 640, 480); WPAD_SetVRes(0, 640, 480);
WPAD_ScanPads(); WPAD_ScanPads();
wpaddown = WPAD_ButtonsDown(0); wpaddown = WPAD_ButtonsDown(0);
@ -65,21 +81,112 @@ int main() {
WPAD_IR(WPAD_CHAN_0, &ir1); WPAD_IR(WPAD_CHAN_0, &ir1);
GRRLIB_FillScreen(GRRLIB_BLACK); GRRLIB_FillScreen(GRRLIB_BLACK); // Clear the screen
switch(page)
{
case 1: // Draw images
GRRLIB_Printf(5, 25, tex_BMfont2, GRRLIB_WHITE, 1, "IMAGES DEMO");
GRRLIB_DrawImg(10, 10, tex_test_jpg, 0, 1, 1, GRRLIB_WHITE); GRRLIB_DrawImg(10, 50, tex_test_jpg, 0, 1, 1, GRRLIB_WHITE);
// Draw a sprite
GRRLIB_DrawTile(600, 400, tex_link_png, 0, 2, 2, GRRLIB_WHITE, 12*4); // Rupy
GRRLIB_DrawTile(320+left, 240+top, tex_link_png, 0, 2, 2, GRRLIB_WHITE, frame);
if(direction_new != direction) {
// Direction has changed, modify frame immidiately
direction = direction_new;
frame = direction;
wait = 0;
}
wait++;
if(wait > TILE_DELAY) {
// wait is needed for the number of frame per second to be ok
wait = 0;
if(wpadheld & WPAD_BUTTON_LEFT || wpadheld & WPAD_BUTTON_RIGHT ||
wpadheld & WPAD_BUTTON_UP || wpadheld & WPAD_BUTTON_DOWN) {
frame++;
}
else {
frame = direction + 1; // Not moving
wait = TILE_DELAY; // Ready to move
}
if(frame > direction+2) frame = direction;
}
break;
case 2: // Draw shapes
GRRLIB_Printf(5, 25, tex_BMfont2, GRRLIB_WHITE, 1, "SHAPES DEMO");
GRRLIB_Printf(left, 200, tex_BMfont1, GRRLIB_WHITE, 1, "X VALUE:%d", (int)ir1.sx); GRRLIB_Rectangle(100, 100, 200, 100, GRRLIB_RED, 1);
GRRLIB_Printf(left, 250, tex_BMfont4, GRRLIB_WHITE, 1, "X VALUE:%d", (int)ir1.sx); GRRLIB_Rectangle(left + 150, top + 150, 200, 200, 0x0000FFC8, 1); // Blue with alpha
GRRLIB_Printf(left, 300, tex_BMfont3, GRRLIB_WHITE, 1, "X VALUE : %d", tex_test_jpg.w); GRRLIB_Line(100, 100, 350, 200, GRRLIB_SILVER);
GRRLIB_Printf(left, 350, tex_BMfont2, GRRLIB_WHITE, 1, "X VALUE : 1");
// Draw a yellow four pixel dot where the wiimote is pointing
GRRLIB_Plot(ir1.sx, ir1.sy, GRRLIB_YELLOW);
GRRLIB_Plot(ir1.sx + 1, ir1.sy, GRRLIB_YELLOW);
GRRLIB_Plot(ir1.sx, ir1.sy + 1, GRRLIB_YELLOW);
GRRLIB_Plot(ir1.sx + 1, ir1.sy + 1, GRRLIB_YELLOW);
break;
default: // Print some text
GRRLIB_Printf(5, 25, tex_BMfont2, GRRLIB_WHITE, 1, "TEXT DEMO");
GRRLIB_Printf(5, 100, tex_BMfont4, GRRLIB_WHITE, 1, "TO QUIT PRESS THE HOME BUTTON.");
GRRLIB_Printf(5, 140, tex_BMfont4, GRRLIB_YELLOW, 1, "USE + AND - TO MOVE ACROSS PAGES.");
GRRLIB_Printf(5, 180, tex_BMfont4, GRRLIB_GREEN, 1, "USE THE D-PAD TO MOVE STUFF.");
GRRLIB_Printf(left, top+250, tex_BMfont1, GRRLIB_WHITE, 1, "X VALUE: %d", (int)ir1.sx);
GRRLIB_Printf(left, top+300, tex_BMfont3, GRRLIB_WHITE, 1, "Y VALUE: %d", (int)ir1.sy);
}
GRRLIB_Render(); GRRLIB_Render();
if (wpaddown & WPAD_BUTTON_A) exit(0); if(wpaddown & WPAD_BUTTON_HOME) {
if (wpadheld & WPAD_BUTTON_LEFT) left--; exit(0);
if (wpadheld & WPAD_BUTTON_RIGHT) left++; }
if(wpadheld & WPAD_BUTTON_LEFT) {
if(wpadheld & WPAD_BUTTON_B || page == 1)
left -= 2;
else
left--;
direction_new = TILE_LEFT; // for tile example
}
if(wpadheld & WPAD_BUTTON_RIGHT) {
if(wpadheld & WPAD_BUTTON_B || page == 1)
left += 2;
else
left++;
direction_new = TILE_RIGHT; // for tile example
}
if(wpadheld & WPAD_BUTTON_UP) {
if(wpadheld & WPAD_BUTTON_B || page == 1)
top -= 2;
else
top--;
direction_new = TILE_UP; // for tile example
}
if(wpadheld & WPAD_BUTTON_DOWN) {
if(wpadheld & WPAD_BUTTON_B || page == 1)
top += 2;
else
top++;
direction_new = TILE_DOWN; // for tile example
}
if(wpaddown & WPAD_BUTTON_MINUS) {
page--;
left = 0;
top = 0;
if(page < 0) page = 2;
}
if(wpaddown & WPAD_BUTTON_PLUS) {
page++;
left = 0;
top = 0;
if(page > 2) page = 0;
}
} }
GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
// Free some textures
free(tex_test_jpg.data);
free(tex_link_png.data);
free(tex_BMfont1.data);
free(tex_BMfont2.data);
free(tex_BMfont3.data);
free(tex_BMfont4.data);
return 0; return 0;
} }