// Contructor clase CBackground CBackground::CBackground(const char *background, u16 width, u16 height) { _layer = CBackground::Layer++; if(CBackground::Layer >= CBackground::MAX_LAYER_BACKGROUND){ CBackground::Layer = 0; } //_name = background; strcpy(_name,background); NF_LoadTiledBg(background, background, width, height); } // CBackground
// Contructor clase CBackground CBackground::CBackground(const char *background, u16 width, u16 height) { _layer = CBackground::Layer++; if(CBackground::Layer >= CBackground::MAX_LAYER_BACKGROUND){ CBackground::Layer = 1; } //_name = background; u8 size = strlen(background); _name = (char*)malloc(sizeof(char)*size+1); strcpy(_name,background); _name[size] = '\0'; NF_LoadTiledBg(background, background, width, height); } // CBackground
int main(int argc, char **argv) { // Chargement de NitroFS / NitroFS loading NF_Set2D(0, 0); NF_Set2D(1, 0); consoleDemoInit(); iprintf("\n NitroFS init. Please wait.\n\n"); iprintf(" Chargement de NitroFS. Veuillez patienter.\n\n"); swiWaitForVBlank(); iprintf("OK !\n\n"); NF_SetRootFolder("NITROFS"); // Défini le dossier root comme celui de NitroFS // Moteur 2D / 2D Engine NF_Set2D(0, 0); NF_Set2D(1, 0); soundEnable(); // Les fonds / Backgrounds NF_InitTiledBgBuffers(); // buffer NF_InitTiledBgSys(0); // haut / top NF_InitTiledBgSys(1); // bas / bottom //Texte / Text NF_InitTextSys(0); //haut / top NF_InitTextSys(1); //bas / bottom // Buffers du son / Sound buffer NF_InitRawSoundBuffers(); // Chargement de la police de caractère / Loading font NF_LoadTextFont("fnt/default", "haut", 256, 256, 0); NF_LoadTextFont("fnt/default", "bas", 256, 256, 0); // Calque police et couleur/ Font layer and color NF_CreateTextLayer(0, 0, 0, "haut"); NF_CreateTextLayer(1, 0, 0, "bas"); NF_BgSetPalColor(0, 0, 1, 0, 31, 0); NF_BgSetPalColor(1, 0, 1, 0, 31, 0); //Vars touchPosition touch; u16 newpress; s16 x; s16 y; u8 beat = 0; //high 0 / low 1 NF_ResetRawSoundBuffers(); NF_ClearTextLayer(1, 0); NF_ClearTextLayer(0, 0); NF_WriteText(0, 0, 0, 1, "___ ____ ___ ____ ____ ___ "); NF_WriteText(0, 0, 0, 2, "| \\ [__ | \\ |__| |___ | "); NF_WriteText(0, 0, 0, 3, "|__/ ___] |__/ | | | | "); NF_WriteText(0, 0, 25, 5, "1.0"); NF_WriteText(0, 0, 0, 22, "Corenting (www.corenting.fr)"); NF_UpdateTextLayers(); // Actualisation du texte NF_LoadTiledBg("bg/1", "1", 256, 256); NF_CreateTiledBg(1, 3, "1"); //Harder Better Faster Stronger while(1) { // Scan touches et tactile scanKeys(); touchRead(&touch); newpress = keysDown(); x = touch.px; y = touch.py ; if (newpress&&(x > 51)&&(y > 182)&&(x < 92)&&(y < 192)) { if (beat == 1) { beat = 0; } else { beat = 1; } } if(beat == 0) { NF_WriteText(1, 0, 7, 23, "High"); NF_UpdateTextLayers(); // Actualisation du texte // Chargement des samples do { NF_ResetRawSoundBuffers(); NF_LoadRawSound("sfx/workit1", 0, 16384, 0); NF_LoadRawSound("sfx/makeit1", 1, 16384, 0); NF_LoadRawSound("sfx/doit1", 2, 16384, 0); NF_LoadRawSound("sfx/makesus1", 3, 16384, 0); NF_LoadRawSound("sfx/harder1", 4, 16384, 0); NF_LoadRawSound("sfx/better1", 5, 16384, 0); NF_LoadRawSound("sfx/faster1", 6, 16384, 0); NF_LoadRawSound("sfx/stronger1", 7, 16384, 0); NF_LoadRawSound("sfx/morethan1", 8, 16384, 0); NF_LoadRawSound("sfx/hour1", 9, 16384, 0); NF_LoadRawSound("sfx/our1", 10, 16384, 0); NF_LoadRawSound("sfx/never1", 11, 16384, 0); NF_LoadRawSound("sfx/ever1", 12, 16384, 0); NF_LoadRawSound("sfx/after1", 13, 16384, 0); NF_LoadRawSound("sfx/workis1", 14, 16384, 0); NF_LoadRawSound("sfx/over1", 15, 16384, 0); } while (0==1); } if(beat == 1) { NF_WriteText(1, 0, 7, 23, "Low "); NF_UpdateTextLayers(); // Actualisation du texte do { NF_ResetRawSoundBuffers(); NF_LoadRawSound("sfx/workit2", 0, 16384, 0); NF_LoadRawSound("sfx/makeit2", 1, 16384, 0); NF_LoadRawSound("sfx/doit2", 2, 16384, 0); NF_LoadRawSound("sfx/makesus2", 3, 16384, 0); NF_LoadRawSound("sfx/harder2", 4, 16384, 0); NF_LoadRawSound("sfx/better2", 5, 16384, 0); NF_LoadRawSound("sfx/faster2", 6, 16384, 0); NF_LoadRawSound("sfx/stronger2", 7, 16384, 0); NF_LoadRawSound("sfx/morethan2", 8, 16384, 0); NF_LoadRawSound("sfx/hour2", 9, 16384, 0); NF_LoadRawSound("sfx/our2", 10, 16384, 0); NF_LoadRawSound("sfx/never2", 11, 16384, 0); NF_LoadRawSound("sfx/ever2", 12, 16384, 0); NF_LoadRawSound("sfx/after2", 13, 16384, 0); NF_LoadRawSound("sfx/workis2", 14, 16384, 0); NF_LoadRawSound("sfx/over2", 15, 16384, 0); } while (0==1); } if (newpress&&(x > 0)&&(y > 0)&&(x < 58)&&(y < 35)) { NF_PlayRawSound(0, 127, 127, false, 0); } if (newpress&&(x >= 66)&&(y >= 0)&&(x < 123)&&(y < 35)) { NF_PlayRawSound(1, 127, 127, false, 0); } if (newpress&&(x >= 132)&&(y >= 0)&&(x < 187)&&(y < 35)) { NF_PlayRawSound(2, 127, 127, false, 0); } if (newpress&&(x >= 197)&&(y >= 0)&&(x < 255)&&(y < 35)) { NF_PlayRawSound(3, 127, 127, false, 0); } if (newpress&&(x >= 0)&&(y >= 45)&&(x < 58)&&(y < 80)) { NF_PlayRawSound(4, 127, 127, false, 0); } if (newpress&&(x >= 67)&&(y >= 45)&&(x < 122)&&(y < 80)) { NF_PlayRawSound(5, 127, 127, false, 0); } if (newpress&&(x >= 133)&&(y >= 45)&&(x < 189)&&(y < 80)) { NF_PlayRawSound(6, 127, 127, false, 0); } if (newpress&&(x >= 197)&&(y >= 45)&&(x < 252)&&(y < 80)) { NF_PlayRawSound(7, 127, 127, false, 0); } if (newpress&&(x >= 0)&&(y >= 89)&&(x < 58)&&(y < 125)) { NF_PlayRawSound(8, 127, 127, false, 0); } if (newpress&&(x >= 67)&&(y >= 89)&&(x < 122)&&(y < 125)) { NF_PlayRawSound(9, 127, 127, false, 0); } if (newpress&&(x >= 132)&&(y >= 89)&&(x < 190)&&(y < 125)) { NF_PlayRawSound(10, 127, 127, false, 0); } if (newpress&&(x >= 198)&&(y >= 89)&&(x < 253)&&(y < 125)) { NF_PlayRawSound(11, 127, 127, false, 0); } if (newpress&&(x >= 0)&&(y >= 132)&&(x < 57)&&(y < 168)) { NF_PlayRawSound(12, 127, 127, false, 0); } if (newpress&&(x >= 66)&&(y >= 132)&&(x < 123)&&(y < 168)) { NF_PlayRawSound(13, 127, 127, false, 0); } if (newpress&&(x >= 132)&&(y >= 132)&&(x < 187)&&(y < 168)) { NF_PlayRawSound(14, 127, 127, false, 0); } if (newpress&&(x >= 197)&&(y >= 132)&&(x < 253)&&(y < 168)) { NF_PlayRawSound(15, 127, 127, false, 0); } swiWaitForVBlank(); } return 0; }
int main(int argc, char **argv) { // Pantalla de espera inicializando NitroFS NF_Set2D(0, 0); NF_Set2D(1, 0); consoleDemoInit(); iprintf("\n NitroFS init. Please wait.\n\n"); iprintf(" Iniciando NitroFS,\n por favor, espere.\n\n"); swiWaitForVBlank(); // Define el ROOT e inicializa el sistema de archivos NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS // Inicializa el motor 2D NF_Set2D(0, 0); // Modo 2D_0 en la pantalla superior // Inicializa los fondos tileados NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior // Inicializa los Sprites NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_InitSpriteSys(0); // Inicializa los sprites para la pantalla superior // Inicializa los buffers de mapas de colisiones NF_InitCmapBuffers(); // Carga los archivos de fondo NF_LoadTiledBg("bg/pdemo_bg", "bg3", 256, 256); // Carga el fondo para la capa 3, pantalla superior // Carga los archivos de sprites NF_LoadSpriteGfx("sprite/whiteball", 0, 16, 16); // Pelota NF_LoadSpritePal("sprite/whitepal", 0); // Carga el fondo de colisiones NF_LoadColisionBg("maps/pdemo_colmap", 0, 256, 256); // Crea los fondos de la pantalla superior NF_CreateTiledBg(0, 3, "bg3"); // Transfiere a la VRAM los sprites necesarios NF_VramSpriteGfx(0, 0, 0, true); // Puntero NF_VramSpritePal(0, 0, 0); // Variables de uso genereal u8 b = 0; u8 n = 0; // Crea el Sprite del puntero en la pantalla inferior for (b = 0; b < 3; b ++) { NF_CreateSprite(0, b, 0, 0, -16, -16); // Crea el puntero en la pantalla inferior NF_SpriteLayer(0, b, 3); // Y la capa sobre la que se dibujara } // Variables para el control de movimiento s16 x[3]; s16 y[3]; x[0] = 32; y[0] = -16; x[1] = 228; y[1] = 32; x[2] = 10; y[2] = 100; // Variables de control de colisiones, define todos los puntos de colision del sprite por debajo s16 py[16]; py[0] = 11; py[1] = 13; py[2] = 14; py[3] = 15; py[4] = 15; py[5] = 16; py[6] = 16; py[7] = 16; py[8] = 16; py[9] = 16; py[10] = 16; py[11] = 15; py[12] = 15; py[13] = 14; py[14] = 13; py[15] = 11; // Control de movimiento bool down = false; bool left = false; bool right = false; // Bucle (repite para siempre) while(1) { // Borra la pantalal de texto consoleClear(); // Bola a bola for (b = 0; b < 3; b ++) { // Control de colisiones, caida down = true; // Flag de descenso arriba // Busca pixel por pixel, si hay colisiones (pixel azul, nº4) for (n = 0; n < 16; n ++) { if (NF_GetPoint(0, (x[b] + n), (y[b] + py[n])) == 4) down = false; } // Control de colisiones, decide derecha o izquierda right = true; // Flag de movimiento lateral arriba left = true; // Caida a izquierda if (NF_GetPoint(0, (x[b] - 1), (y[b] + 16)) == 4) left = false; // Caida a derecha if (NF_GetPoint(0, (x[b] + 16), (y[b] + 16)) == 4) right = false; // Si hay caida libre, no te muevas en horizontal if (left && right) { right = false; left = false; } // Si es necesario, caida libre if (down) y[b] ++; // Muevete a la derecha if (right) x[b] ++; // Muevete a la izquierda if (left) x[b] --; // Recoloca la pelota si sale de los limites de pantalla if (y[b] > 192) { x[b] = 32; y[b] = -16; } // Posicion del Sprite NF_MoveSprite(0, b, x[b], y[b]); // Imprime la posicion de la pelota printf("x:%03d y:%03d\n", x[b], y[b]); } NF_SpriteOamSet(0); // Actualiza el Array del OAM swiWaitForVBlank(); // Espera al sincronismo vertical oamUpdate(&oamMain); // Actualiza a VRAM el OAM Secundario } return 0; }