Image unavailable (removed by its host)
1. Initializing the homebrew
First of all open "Programmer's Notepad", and do "File" and "New" => "C/C++".
Alright let's go, let's code!
Add these lines, these are the libraries we're going to call in our program.
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <ogcsys.h>
#include <unistd.h>
#include <ogc/pad.h> // Librairie pour la Manette Gamecube
#include <wiiuse/wpad.h> // Librairie pour la WiimoteCode: Select all
#define gotoXY(x,y) printf("\x1b[%i;%iH", x, y)
static void *xfb = NULL;
static GXRModeObj *rmode = NULL;
//---------------------------------------------------------------------------------
int main(int argc, char **argv)
{
VIDEO_Init(); //Initialise la vidéo
WPAD_Init(); // Initialise la wiimote
rmode = VIDEO_GetPreferredMode(NULL);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
console_init(xfb,0,0,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
VIDEO_Configure(rmode);
VIDEO_SetNextFramebuffer(xfb);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 2. Using controllers. Let's use the wiimote, the Gamecube Controller, Classic Controller, Nunchuk Controller! (and yes that's a lot!)
Wiimote:
Code: Select all
printf("Premier Programme Wii -- https://www.tgames.fr"); // Écrit à l'écran ces mots
gotoXY(2, 3); // Emplacement du texte à l'écran
u32 pressed;
struct expansion_t ext;
if (b & WPAD_BUTTON_A)
wpad_status &= PSX_BUTTON_START;
WPAD_ScanPads();
/* Voici différentes lignes qui sont identiques mais fonctionnent toutes différemment.
Ces lignes servent à synchroniser les boutons à la reconnaissance sur la wii
A l'appui sur un touche un condition se déroule, si elle n'est pas respecté elle est remplacé par une autre */
// Etat des bouttons de la Wiimote avec WPAD_ButtonsDown
pressed = WPAD_ButtonsDown(WPAD_CHAN_0);
gotoXY(5, 3);
printf("Boutons Wiimote avec WPAD_ButtonsDown: ");
if (pressed & WPAD_BUTTON_A) { printf ("A"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_B) { printf ("B"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_1) { printf ("1"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_2) { printf ("2"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_MINUS) { printf ("-"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_PLUS) { printf ("+"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_LEFT) { printf (" Gauche"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_RIGHT) { printf (" Droit"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_UP) { printf (" Haut"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_DOWN) { printf (" Bas"); } else { printf (" "); }
// Etat des bouttons de la Wiimote avec WPAD_ButtonsHeld
pressed = WPAD_ButtonsHeld(WPAD_CHAN_0);
gotoXY(6, 3);
printf("Boutons Wiimote avec WPAD_ButtonsHeld: ");
if (pressed & WPAD_BUTTON_A) { printf ("A"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_B) { printf ("B"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_1) { printf ("1"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_2) { printf ("2"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_MINUS) { printf ("-"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_PLUS) { printf ("+"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_LEFT) { printf (" Gauche"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_RIGHT) { printf (" Droit"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_UP) { printf (" Haut"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_DOWN) { printf (" Bas"); } else { printf (" "); }
// Etat des bouttons de la Wiimote avec WPAD_ButtonsUp
pressed = WPAD_ButtonsUp(WPAD_CHAN_0);
gotoXY(7, 3);
printf("Boutons Wiimote avec WPAD_ButtonsUp: ");
if (pressed & WPAD_BUTTON_A) { printf ("A"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_B) { printf ("B"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_1) { printf ("1"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_2) { printf ("2"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_MINUS) { printf ("-"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_PLUS) { printf ("+"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_LEFT) { printf (" Gauche"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_RIGHT) { printf (" Droit"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_UP) { printf (" Haut"); } else { printf (" "); }
if (pressed & WPAD_BUTTON_DOWN) { printf (" Bas"); } else { printf (" "); }
Code: Select all
// Extension Wiimote
WPAD_Expansion(WPAD_CHAN_0, &ext);
gotoXY(9, 3);
printf("Extension: ");
switch (ext.type)
{
case WPAD_EXP_NONE: printf ("Aucun "); break;
case WPAD_EXP_NUNCHUK: printf ("Nunchuk "); break;
case WPAD_EXP_CLASSIC: printf ("Manette classique"); break;
case WPAD_EXP_GUITARHERO3: printf ("Guitar Hero 3 "); break;
case WPAD_EXP_UNKNOWN: printf ("Manette inconnue "); break;
}Code: Select all
// Etat des bouttons de la Wiimote avec WPAD_ButtonsDown
pressed = WPAD_ButtonsDown(WPAD_CHAN_0);
gotoXY (3, 5);
printf("Boutons Nunchuk avec WPAD_ButtonsDown: ");
if (pressed & WPAD_NUNCHUK_BUTTON_Z) { printf ("Z"); } else { printf (" "); }
if (pressed & WPAD_NUNCHUK_BUTTON_C) { printf ("C"); } else { printf (" "); }
// Etat des bouttons de la Wiimote avec WPAD_ButtonsHeld
pressed = WPAD_ButtonsHeld(WPAD_CHAN_0);
gotoXY (3, 6);
printf("Boutons Nunchuk avec WPAD_ButtonsHeld: ");
if (pressed & WPAD_NUNCHUK_BUTTON_Z) { printf ("Z"); } else { printf (" "); }
if (pressed & WPAD_NUNCHUK_BUTTON_C) { printf ("C"); } else { printf (" "); }
// Etat des bouttons de la Wiimote avec WPAD_ButtonsUp
pressed = WPAD_ButtonsUp(WPAD_CHAN_0);
gotoXY (3, 7);
printf("Boutons Nunchuk avec WPAD_ButtonsUp: ");
if (pressed & WPAD_NUNCHUK_BUTTON_Z) { printf ("Z"); } else { printf (" "); }
if (pressed & WPAD_NUNCHUK_BUTTON_C) { printf ("C"); } else { printf (" "); }
// Joypad du nunchuk
WPAD_Expansion(WPAD_CHAN_0, &ext);
gotoXY (3, 9);
printf("Joypad Position X:%3i - Y:%3i ", ext.nunchuk.js.pos.x, ext.nunchuk.js.pos.y);
printf("Joypad Center X:%3i - Y:%3i ", ext.nunchuk.js.center.x, ext.nunchuk.js.center.y);
gotoXY (3, 10);
printf("Joypad Min X:%3i - Y:%3i ", ext.nunchuk.js.min.x, ext.nunchuk.js.min.y);
printf("Joypad Max X:%3i - Y:%3i ", ext.nunchuk.js.max.x, ext.nunchuk.js.max.y);
X = ext.nunchuk.js.pos.x - ext.nunchuk.js.center.x;
Y = - (ext.nunchuk.js.pos.y - ext.nunchuk.js.center.y);
gotoXY (3, 12);
printf ("Valeur joypad par calcul X:%4i - Y:%4i ", X, Y);
X /= 4*2; Y /= 8*2;
gotoXY (35, 20);
printf ("+");
gotoXY (35+X, 20+Y);
printf ("*");
Code: Select all
WPAD_ScanPads();
gotoXY (20+X1, 22+Y1); printf (".");
gotoXY (55+X2, 22+Y2); printf (".");
// Etat des bouttons de la Wiimote avec WPAD_ButtonsDown
pressed = WPAD_ButtonsDown(WPAD_CHAN_0);
gotoXY (3, 5);
printf("Boutons Nunchuk avec WPAD_ButtonsDown: ");
if (pressed & WPAD_CLASSIC_BUTTON_LEFT) { printf ("G"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_RIGHT) { printf ("D"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_UP) { printf ("H"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_DOWN) { printf ("B"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_A) { printf ("A"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_B) { printf ("B"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_X) { printf ("X"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_Y) { printf ("Y"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_PLUS) { printf ("+"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_MINUS) { printf ("-"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_ZL) { printf (" ZL"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_ZR) { printf (" ZR"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_FULL_L) { printf (" L"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_FULL_R) { printf ("R "); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_HOME) { printf ("Home"); } else { printf (" "); }
// Etat des bouttons de la Wiimote avec WPAD_ButtonsHeld
pressed = WPAD_ButtonsHeld(WPAD_CHAN_0);
gotoXY (3, 6);
printf("Boutons Nunchuk avec WPAD_ButtonsHeld: ");
if (pressed & WPAD_CLASSIC_BUTTON_LEFT) { printf ("G"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_RIGHT) { printf ("D"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_UP) { printf ("H"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_DOWN) { printf ("B"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_A) { printf ("A"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_B) { printf ("B"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_X) { printf ("X"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_Y) { printf ("Y"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_PLUS) { printf ("+"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_MINUS) { printf ("-"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_ZL) { printf (" ZL"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_ZR) { printf (" ZR"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_FULL_L) { printf (" L"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_FULL_R) { printf ("R "); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_HOME) { printf ("Home"); } else { printf (" "); }
// Etat des bouttons de la Wiimote avec WPAD_ButtonsUp
pressed = WPAD_ButtonsUp(WPAD_CHAN_0);
gotoXY (3, 7);
printf("Boutons Nunchuk avec WPAD_ButtonsUp: ");
if (pressed & WPAD_CLASSIC_BUTTON_LEFT) { printf ("G"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_RIGHT) { printf ("D"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_UP) { printf ("H"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_DOWN) { printf ("B"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_A) { printf ("A"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_B) { printf ("B"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_X) { printf ("X"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_Y) { printf ("Y"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_PLUS) { printf ("+"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_MINUS) { printf ("-"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_ZL) { printf (" ZL"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_ZR) { printf (" ZR"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_FULL_L) { printf (" L"); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_FULL_R) { printf ("R "); } else { printf (" "); }
if (pressed & WPAD_CLASSIC_BUTTON_HOME) { printf ("Home"); } else { printf (" "); }
// Joypads
WPAD_Expansion(WPAD_CHAN_0, &ext);
gotoXY (3, 9);
printf("Joypad Pos. Left X:%2i Y:%2i Right X:%2i Y:%2i ", ext.classic.ljs.pos.x, ext.classic.ljs.pos.y, ext.classic.rjs.pos.x, ext.classic.rjs.pos.y);
gotoXY (3, 10);
printf("Joypad Center Left X:%2i Y:%2i Right X:%2i Y:%2i ", ext.classic.ljs.center.x, ext.classic.ljs.center.y, ext.classic.rjs.center.x, ext.classic.rjs.center.y);
gotoXY (3, 11);
printf("Joypad Min Left X:%2i Y:%2i Right X:%2i Y:%2i ", ext.classic.ljs.min.x, ext.classic.ljs.min.y, ext.classic.rjs.min.x, ext.classic.rjs.min.y);
gotoXY (3, 12);
printf("Joypad Max Left X:%2i Y:%2i Right X:%2i Y:%2i ", ext.classic.ljs.max.x, ext.classic.ljs.max.y, ext.classic.rjs.max.x, ext.classic.rjs.max.y);
X1 = ((ext.classic.ljs.pos.x - ext.classic.ljs.center.x) * 200 / (ext.classic.ljs.max.x - ext.classic.ljs.min.x));
Y1 = - ((ext.classic.ljs.pos.y - ext.classic.ljs.center.y) * 200 / (ext.classic.ljs.max.y - ext.classic.ljs.min.y));
X2 = ((ext.classic.rjs.pos.x - ext.classic.rjs.center.x) * 200 / (ext.classic.rjs.max.x - ext.classic.rjs.min.x));
Y2 = - ((ext.classic.rjs.pos.y - ext.classic.rjs.center.y) * 200 / (ext.classic.rjs.max.y - ext.classic.rjs.min.y));
gotoXY (3, 14);
printf ("Valeur joypad par calcul Left X:%4i Y:%4i Right X:%4i Y:%4i ", X1, Y1, X2, Y2);
X1 /= 4*3; Y1 /= 8*3;
gotoXY (20, 22); printf ("+");
gotoXY (20+X1, 22+Y1); printf ("*");
X2 /= 4*3; Y2 /= 8*3;
gotoXY (55, 22); printf ("+");
gotoXY (55+X2, 22+Y2); printf ("*");
Code: Select all
u32 pressed;
PAD_ScanPads();
gotoXY (20+X1, 22-Y1); printf (".");
gotoXY (55+X2, 22-Y2); printf (".");
// Etat des bouttons de la manette GameCube avec PAD_ButtonsDown
pressed = PAD_ButtonsDown(PAD_CHAN0);
gotoXY(3, 5);
printf("Boutons manette GameCube avec PAD_ButtonsDown: ");
if (pressed & PAD_BUTTON_A) { printf ("A"); } else { printf (" "); }
if (pressed & PAD_BUTTON_B) { printf ("B"); } else { printf (" "); }
if (pressed & PAD_BUTTON_X) { printf ("X"); } else { printf (" "); }
if (pressed & PAD_BUTTON_Y) { printf ("Y"); } else { printf (" "); }
if (pressed & PAD_TRIGGER_Z) { printf ("Z"); } else { printf (" "); }
if (pressed & PAD_TRIGGER_L) { printf ("L"); } else { printf (" "); }
if (pressed & PAD_TRIGGER_R) { printf ("R"); } else { printf (" "); }
if (pressed & PAD_BUTTON_LEFT) { printf (" Gauche"); } else { printf (" "); }
if (pressed & PAD_BUTTON_RIGHT) { printf (" Droit"); } else { printf (" "); }
if (pressed & PAD_BUTTON_UP) { printf (" Haut"); } else { printf (" "); }
if (pressed & PAD_BUTTON_DOWN) { printf (" Bas"); } else { printf (" "); }
// Etat des bouttons de la manette GameCube avec PAD_ButtonsHeld
pressed = PAD_ButtonsHeld(PAD_CHAN0);
gotoXY(3, 6);
printf("Boutons manette GameCube avec PAD_ButtonsHeld: ");
if (pressed & PAD_BUTTON_A) { printf ("A"); } else { printf (" "); }
if (pressed & PAD_BUTTON_B) { printf ("B"); } else { printf (" "); }
if (pressed & PAD_BUTTON_X) { printf ("X"); } else { printf (" "); }
if (pressed & PAD_BUTTON_Y) { printf ("Y"); } else { printf (" "); }
if (pressed & PAD_TRIGGER_Z) { printf ("Z"); } else { printf (" "); }
if (pressed & PAD_TRIGGER_L) { printf ("L"); } else { printf (" "); }
if (pressed & PAD_TRIGGER_R) { printf ("R"); } else { printf (" "); }
if (pressed & PAD_BUTTON_LEFT) { printf (" Gauche"); } else { printf (" "); }
if (pressed & PAD_BUTTON_RIGHT) { printf (" Droit"); } else { printf (" "); }
if (pressed & PAD_BUTTON_UP) { printf (" Haut"); } else { printf (" "); }
if (pressed & PAD_BUTTON_DOWN) { printf (" Bas"); } else { printf (" "); }
// Etat des bouttons de la manette GameCube avec PAD_ButtonsUp
pressed = PAD_ButtonsUp(PAD_CHAN0);
gotoXY(3, 7);
printf("Boutons manette GameCube avec PAD_ButtonsUp: ");
if (pressed & PAD_BUTTON_A) { printf ("A"); } else { printf (" "); }
if (pressed & PAD_BUTTON_B) { printf ("B"); } else { printf (" "); }
if (pressed & PAD_BUTTON_X) { printf ("X"); } else { printf (" "); }
if (pressed & PAD_BUTTON_Y) { printf ("Y"); } else { printf (" "); }
if (pressed & PAD_TRIGGER_Z) { printf ("Z"); } else { printf (" "); }
if (pressed & PAD_TRIGGER_L) { printf ("L"); } else { printf (" "); }
if (pressed & PAD_TRIGGER_R) { printf ("R"); } else { printf (" "); }
if (pressed & PAD_BUTTON_LEFT) { printf (" Gauche"); } else { printf (" "); }
if (pressed & PAD_BUTTON_RIGHT) { printf (" Droit"); } else { printf (" "); }
if (pressed & PAD_BUTTON_UP) { printf (" Haut"); } else { printf (" "); }
if (pressed & PAD_BUTTON_DOWN) { printf (" Bas"); } else { printf (" "); }
// Etat des joypads de la manette GameCube
X1 = PAD_StickX(PAD_CHAN0);
Y1 = PAD_StickY(PAD_CHAN0);
X2 = PAD_SubStickX(PAD_CHAN0);
Y2 = PAD_SubStickY(PAD_CHAN0);
gotoXY (3, 9);
printf("PAD_StickX: %3i - PAD_StickY: %3i ", X1, Y1);
gotoXY (3, 10);
printf("PAD_SubStickX:%3i - PAD_SubStickY:%3i ", X2, Y2);
gotoXY (3, 11);
printf("PAD_TriggerL: %3i - PAD_TriggerR: %3i ", PAD_TriggerL(PAD_CHAN0), PAD_TriggerR(PAD_CHAN0));
X1 /= 4*2; Y1 /= 8*2;
gotoXY (20, 22); printf ("+");
gotoXY (20+X1, 22-Y1); printf ("*");
X2 /= 4*2; Y2 /= 8*2;
gotoXY (55, 22); printf ("+");
gotoXY (55+X2, 22-Y2); printf ("*");
3. Using the wii's restart modes! Now that I've covered everything about using controllers, we're going to talk about the wii's restart modes, turning off the wii, returning to the loader.
For this add the line for the wiimote:
To return to the loader:
Code: Select all
if ( pressed & WPAD_BUTTON_HOME ) { exit(0); }Code: Select all
if ( pressed & WPAD_BUTTON_HOME ) { SYS_ResetSystem(SYS_RETURNTOMENU,0,0); }Code: Select all
if ( pressed & WPAD_BUTTON_HOME ) { SYS_ResetSystem(SYS_RESTART,0,0); }Code: Select all
if ( pressed & WPAD_BUTTON_HOME ) { SYS_ResetSystem(SYS_POWEROFF,0,0); }To be added after the other if (pressed & WPAD_BUTTON_xx )....
For the classic controller just replace
pressed & WPAD_BUTTON_HOME with pressed & WPAD_CLASSIC_BUTTON_HOME
That will still work.
For the Gamecube controller just replace
pressed & WPAD_BUTTON_HOME with pressed & PAD_BUTTON_START
There we go, we're done with the tutorial on Controller functions, video/controller initialization and the wii's restart modes!!
If you want to make a good 2D game, start by reading section 2 of the Zéro site, SDL is also available on wii, it will let you make complex programs.
