examples: Cleanup and translate some examples to English

This commit is contained in:
Antonio Niño Díaz 2023-05-18 02:19:38 +01:00
parent 37e1d5cb56
commit 4c92c8c864
3 changed files with 236 additions and 363 deletions

View File

@ -1,144 +1,93 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Background loading example
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de carga de fondos
Requiere DevkitARM
Requiere NightFox's Lib
Codigo por NightFox
http://www.nightfoxandco.com
Inicio 10 de Octubre del 2009
-------------------------------------------------
*/
/*
-------------------------------------------------
Includes
-------------------------------------------------
*/
// Includes C
#include <stdio.h> #include <stdio.h>
// Includes propietarios NDS
#include <nds.h> #include <nds.h>
#include <filesystem.h> #include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h> #include <nf_lib.h>
#define SPEED 2 // Scroll speed
// Algunos defines interesantes int main(int argc, char **argv)
#define SPEED 2 // Velocidad del scroll {
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0);
NF_Set2D(1, 0);
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
// Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256);
NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256);
NF_LoadTiledBg("bg/bg1", "capa_1", 1536, 256);
NF_LoadTiledBg("bg/bg0", "capa_0", 2048, 256);
/* // Create top screen background
------------------------------------------------- NF_CreateTiledBg(0, 3, "nfl");
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) { // Create bottom screen backgrounds
NF_CreateTiledBg(1, 3, "capa_3");
NF_CreateTiledBg(1, 2, "capa_2");
NF_CreateTiledBg(1, 1, "capa_1");
NF_CreateTiledBg(1, 0, "capa_0");
// Pantalla de espera inicializando NitroFS // Variables
NF_Set2D(0, 0); s16 bg_x[4] = { 0, 0, 0, 0 };
NF_Set2D(1, 0); s16 bg_y[4] = { 0, 0, 0, 0 };
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos while (1)
nitroFSInit(NULL); {
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS scanKeys(); // Read keypad
uint16_t keys = keysHeld(); // Keys currently pressed
// Inicializa el motor 2D // If pressing left
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas if (keys & KEY_LEFT)
NF_Set2D(1, 0); {
bg_x[0] -= SPEED;
if (bg_x[0] < 0)
bg_x[0] = 0;
}
// Inicializa los fondos tileados // If pressing right
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos if (keys & KEY_RIGHT)
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior {
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior bg_x[0] += SPEED;
if (bg_x[0] > 1663)
bg_x[0] = 1663; // Max scroll of layer 0
}
// Carga los archivos de fondo desde la FAT/NitroFS // Scroll other layers less than layer 0
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla superior bg_x[1] = (int)(bg_x[0] / 1.5);
NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256); // Carga el fondo para la capa 3, pantalla inferior bg_x[2] = (int)(bg_x[1] / 1.5);
NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256); // Carga el fondo para la capa 2, pantalla inferior
NF_LoadTiledBg("bg/bg1", "capa_1", 1536, 256); // Carga el fondo para la capa 1, pantalla inferior
NF_LoadTiledBg("bg/bg0", "capa_0", 2048, 256); // Carga el fondo para la capa 0, pantalla inferior
swiWaitForVBlank(); // Wait for the screen refresh
// Crea los fondos de la pantalla superior // Update background scroll during vertical blanking to avoid tearing
NF_CreateTiledBg(0, 3, "nfl"); for (int n = 0; n < 4; n ++)
// Crea los fondos de la pantalla inferior NF_ScrollBg(1, n, bg_x[n], bg_y[n]);
NF_CreateTiledBg(1, 3, "capa_3"); }
NF_CreateTiledBg(1, 2, "capa_2");
NF_CreateTiledBg(1, 1, "capa_1");
NF_CreateTiledBg(1, 0, "capa_0");
// Variables
s16 bg_x[4];
s16 bg_y[4];
u16 keys = 0;
u8 n = 0;
// Inicializa las variables
for (n = 0; n < 4; n ++) {
bg_x[n] = 0;
bg_y[n] = 0;
}
// Bucle (repite para siempre)
while(1) {
// Lee el keypad
scanKeys();
keys = keysHeld(); // Teclas presionadas
// Si pulsas izquierda
if (keys & KEY_LEFT) {
bg_x[0] -= SPEED;
if (bg_x[0] < 0) bg_x[0] = 0;
}
// Si pulsas derecha
if (keys & KEY_RIGHT) {
bg_x[0] += SPEED;
if (bg_x[0] > 1663) bg_x[0] = 1663; // Limite fisico de la capa 0
}
// Calcula el efecto scroll parallax
bg_x[1] = (int)(bg_x[0] / 1.5);
bg_x[2] = (int)(bg_x[1] / 1.5);
swiWaitForVBlank(); // Espera al sincronismo vertical
// Actualiza la posicion de los fondos
for (n = 0; n < 4; n ++) {
NF_ScrollBg(1, n, bg_x[n], bg_y[n]);
}
}
return 0;
return 0;
} }

View File

@ -1,128 +1,89 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Draw 16-bit images
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Dibujado de imagenes de 16 bits
Requiere DevkitARM
Requiere NightFox's Lib
Codigo por NightFox
http://www.nightfoxandco.com
Inicio 10 de Octubre del 2009
-------------------------------------------------
*/
/*
-------------------------------------------------
Includes
-------------------------------------------------
*/
// Includes C
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
// Includes propietarios NDS
#include <nds.h> #include <nds.h>
#include <filesystem.h> #include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h> #include <nf_lib.h>
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Initialize 2D engine in both screens and use bitmap mode
NF_Set2D(0, 5);
NF_Set2D(1, 5);
// Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1);
/* // Initialize storage buffers
------------------------------------------------- NF_Init16bitsBgBuffers();
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) { // Initialize backbuffers
NF_Init16bitsBackBuffer(0);
NF_Init16bitsBackBuffer(1);
// Pantalla de espera inicializando NitroFS // Enable backbuffers
NF_Set2D(0, 0); NF_Enable16bitsBackBuffer(0);
NF_Set2D(1, 0); NF_Enable16bitsBackBuffer(1);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos // Load bitmap files from NitroFS
nitroFSInit(NULL); NF_Load16bitsBg("bmp/bitmap16", 0);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS NF_Load16bitsImage("bmp/blueball", 1, 64, 64);
// Inicializa el motor 2D en modo BITMAP // Load image to VRAM of both screens
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas NF_Copy16bitsBuffer(0, 1, 0);
NF_Set2D(1, 5); NF_Copy16bitsBuffer(1, 1, 0);
// Inicializa los fondos en modo "BITMAP" // Variables
NF_InitBitmapBgSys(0, 1); s16 x = 0;
NF_InitBitmapBgSys(1, 1); s16 y = 0;
s8 ix = 1;
s8 iy = 1;
// Inicializa los buffers para guardar fondos en formato BITMAP while (1)
NF_Init16bitsBgBuffers(); {
// Move ball
x += ix;
if ((x <= 0) || (x >= 191))
ix *= -1;
y += iy;
if ((y <= 0) || (y >= 127))
iy *= -1;
// Inicializa el backbuffer // Redraw top screen
NF_Init16bitsBackBuffer(0); NF_Draw16bitsImage(0, 1, x, y, true); // Ball (magenta is transparent)
NF_Init16bitsBackBuffer(1);
// Habilita el backbuffer // Redraw bottom screen
NF_Enable16bitsBackBuffer(0); NF_Copy16bitsBuffer(1, 1, 0); // Background
NF_Enable16bitsBackBuffer(1); NF_Draw16bitsImage(1, 1, x, y, true); // Ball (magenta is transparent)
// Carga el archivo BITMAP de imagen en formato RAW a la RAM swiWaitForVBlank(); // Wait for the screen refresh
NF_Load16bitsBg("bmp/bitmap16", 0);
NF_Load16bitsImage("bmp/blueball", 1, 64, 64);
// Tranfiere la imagen a la VRAM de ambas pantallas // Send backbuffer to the screen
NF_Copy16bitsBuffer(0, 1, 0); NF_Flip16bitsBackBuffer(0);
NF_Copy16bitsBuffer(1, 1, 0); NF_Flip16bitsBackBuffer(1);
}
// Variables
s16 x = 0;
s16 y = 0;
s8 ix = 1;
s8 iy = 1;
// Repite para siempre
while (1) {
// Calcula el movimiento
x += ix;
if ((x <= 0) || (x >= 191)) ix *= -1;
y += iy;
if ((y <= 0) || (y >= 127)) iy *= -1;
// Redibuja la escena (Superior)
NF_Draw16bitsImage(0, 1, x, y, true); // Bola (con magenta como transparente)
// Redibuja la escena (Inferior)
NF_Copy16bitsBuffer(1, 1, 0); // Fondo
NF_Draw16bitsImage(1, 1, x, y, true); // Bola (con magenta como transparente)
// Sincronismo Vertical
swiWaitForVBlank();
// Manda el backbuffer a la pantalla
NF_Flip16bitsBackBuffer(0);
NF_Flip16bitsBackBuffer(1);
}
return 0;
return 0;
} }

View File

@ -1,182 +1,145 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Sprite loading example
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de carga de sprites
Requiere DevkitARM
Requiere NightFox's Lib
Codigo por NightFox
http://www.nightfoxandco.com
Inicio 10 de Octubre del 2009
-------------------------------------------------
*/
/*
-------------------------------------------------
Includes
-------------------------------------------------
*/
// Includes C
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
// Includes propietarios NDS
#include <nds.h> #include <nds.h>
#include <filesystem.h> #include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h> #include <nf_lib.h>
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Inicialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0);
NF_Set2D(1, 0);
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
/* // Initialize sprite backgrounds system
------------------------------------------------- NF_InitSpriteBuffers(); // Initialize storage buffers
Main() - Bloque general del programa NF_InitSpriteSys(0); // Top screen
------------------------------------------------- NF_InitSpriteSys(1); // Bottom screen
*/
int main(int argc, char **argv) { // Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256);
NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256);
// Pantalla de espera inicializando NitroFS // Load sprite files from NitroFS
NF_Set2D(0, 0); NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64);
NF_Set2D(1, 0); NF_LoadSpritePal("sprite/personaje", 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos NF_LoadSpriteGfx("sprite/bola", 1, 32, 32);
nitroFSInit(NULL); NF_LoadSpritePal("sprite/bola", 1);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Inicializa el motor 2D // Create top screen background
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas NF_CreateTiledBg(0, 3, "nfl");
NF_Set2D(1, 0);
// Inicializa los fondos tileados // Create bottom screen backgrounds
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos NF_CreateTiledBg(1, 3, "capa_3");
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior NF_CreateTiledBg(1, 2, "capa_2");
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior
// Inicializa los Sprites // Transfer the required sprites to VRAM
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_VramSpriteGfx(1, 0, 0, true); // Ball: Keep unused frames in RAM
NF_InitSpriteSys(0); // Inicializa los sprites para la pantalla superior NF_VramSpritePal(1, 0, 0);
NF_InitSpriteSys(1); // Inicializa los sprites para la pantalla inferior
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM NF_VramSpriteGfx(0, 1, 0, false); // Character: Keep unused frames in VRAM
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla superior NF_VramSpritePal(0, 1, 0);
NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256); // Carga el fondo para la capa 3, pantalla inferior
NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256); // Carga el fondo para la capa 2, pantalla inferior
// Set random seed based on the current time
srand(time(NULL));
// Carga los archivos de sprites desde la FAT / NitroFS a la RAM // Setup character sprite
NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64); // Personaje s16 pj_x = 0;
NF_LoadSpritePal("sprite/personaje", 0); s16 pj_y = 127;
u8 pj_frame = 0;
u8 pj_anim = 0;
s8 pj_speed = 1;
NF_CreateSprite(1, 0, 0, 0, pj_x, pj_y);
NF_LoadSpriteGfx("sprite/bola", 1, 32, 32); // Bola azul // Setup ball sprites
NF_LoadSpritePal("sprite/bola", 1); s16 bola_x[32];
s16 bola_y[32];
s8 bola_spx[32];
s8 bola_spy[32];
for (int n = 0; n < 32; n ++)
{
bola_x[n] = rand() % 223;
bola_y[n] = rand() % 159;
bola_spx[n] = (rand() % 3) + 1;
bola_spy[n] = (rand() % 3) + 1;
NF_CreateSprite(0, n, 0, 0, bola_x[n], bola_y[n]);
}
// Crea los fondos de la pantalla superior while (1)
NF_CreateTiledBg(0, 3, "nfl"); {
// Crea los fondos de la pantalla inferior // Move character
NF_CreateTiledBg(1, 3, "capa_3"); pj_x += pj_speed;
NF_CreateTiledBg(1, 2, "capa_2"); if ((pj_x < 0) || (pj_x > 191))
{
pj_speed *= -1;
if (pj_speed > 0)
NF_HflipSprite(1, 0, false);
else
NF_HflipSprite(1, 0, true);
}
NF_MoveSprite(1, 0, pj_x, pj_y);
// Animate character
pj_anim ++;
if (pj_anim > 5)
{
pj_anim = 0;
pj_frame ++;
if (pj_frame > 11)
pj_frame = 0;
NF_SpriteFrame(1, 0, pj_frame);
}
// Transfiere a la VRAM los sprites necesarios // Move balls
NF_VramSpriteGfx(1, 0, 0, true); // Bola, manten los frames adicionales en RAM for (int n = 0; n < 32; n ++)
NF_VramSpritePal(1, 0, 0); {
bola_x[n] += bola_spx[n];
if ((bola_x[n] < 0) || (bola_x[n] > 223))
bola_spx[n] *= -1;
bola_y[n] += bola_spy[n];
if ((bola_y[n] < 0) || (bola_y[n] > 159))
bola_spy[n] *= -1;
NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
}
NF_VramSpriteGfx(0, 1, 0, false); // Personaje, copia todos los frames a la VRAM // Update OAM array
NF_VramSpritePal(0, 1, 0); NF_SpriteOamSet(0);
NF_SpriteOamSet(1);
swiWaitForVBlank(); // Wait for the screen refresh
// Variables generales y inicializacion del random // Update OAM
u8 n = 0; oamUpdate(&oamMain);
srand(time(NULL)); oamUpdate(&oamSub);
}
// Crea el sprite del personaje en pantalla
s16 pj_x = 0;
s16 pj_y = 127;
u8 pj_frame = 0;
u8 pj_anim = 0;
s8 pj_speed = 1;
NF_CreateSprite(1, 0, 0, 0, pj_x, pj_y);
// Crea las bolas en la pantalla superior
s16 bola_x[32];
s16 bola_y[32];
s8 bola_spx[32];
s8 bola_spy[32];
for (n = 0; n < 32; n ++) {
bola_x[n] = (rand() % 223);
bola_y[n] = (rand() % 159);
bola_spx[n] = (rand() % 3) + 1;
bola_spy[n] = (rand() % 3) + 1;
NF_CreateSprite(0, n, 0, 0, bola_x[n], bola_y[n]);
}
// Bucle (repite para siempre)
while(1) {
// Mueve el personaje
pj_x += pj_speed;
if ((pj_x < 0) || (pj_x > 191)) {
pj_speed *= -1;
if (pj_speed > 0) {
NF_HflipSprite(1, 0, false);
} else {
NF_HflipSprite(1, 0, true);
}
}
NF_MoveSprite(1, 0, pj_x, pj_y);
// Animacion del personaje
pj_anim ++;
if (pj_anim > 5) {
pj_anim = 0;
pj_frame ++;
if (pj_frame > 11) pj_frame = 0;
NF_SpriteFrame(1, 0, pj_frame);
}
// Mueve las bolas
for (n = 0; n < 32; n ++) {
bola_x[n] += bola_spx[n];
if ((bola_x[n] < 0) || (bola_x[n] > 223)) bola_spx[n] *= -1;
bola_y[n] += bola_spy[n];
if ((bola_y[n] < 0) || (bola_y[n] > 159)) bola_spy[n] *= -1;
NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
}
// Actualiza el array de OAM
NF_SpriteOamSet(0);
NF_SpriteOamSet(1);
swiWaitForVBlank(); // Espera al sincronismo vertical
// Actualiza el OAM
oamUpdate(&oamMain);
oamUpdate(&oamSub);
}
return 0;
return 0;
} }