examples: Cleanup and translate more examples to English

This commit is contained in:
Antonio Niño Díaz 2023-05-20 18:42:39 +01:00
parent eb91123a9a
commit c6d6883caf
6 changed files with 605 additions and 765 deletions

View File

@ -30,7 +30,7 @@ int main(int argc, char **argv)
NF_SetRootFolder("NITROFS"); NF_SetRootFolder("NITROFS");
consoleClear(); consoleClear();
// Initialize 3D engine in the top screen in mode 0 // Initialize 3D engine in the bottom screen in mode 0
NF_Set3D(1, 0); NF_Set3D(1, 0);
// Initialize tiled backgrounds system // Initialize tiled backgrounds system
@ -66,7 +66,7 @@ int main(int argc, char **argv)
s16 ix = 4; s16 ix = 4;
s16 iy = 4; s16 iy = 4;
// Create sprites // Initialize sprite variables and create the sprites
for (int n = 0; n < MAXSPRITES; n ++) for (int n = 0; n < MAXSPRITES; n ++)
{ {
x[n] = 128 - 32; x[n] = 128 - 32;

View File

@ -1,62 +1,26 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// 3D animated sprite example
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de 3D Sprites animados
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>
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
#define SPRITEMAXNUM 255 #define SPRITEMAXNUM 255
int main(int argc, char **argv) { int main(int argc, char **argv)
{
// Inicializa el random // Set random seed based on the current time
srand(time(NULL)); srand(time(NULL));
// Pantalla de espera inicializando NitroFS // Prepare a NitroFS initialization screen
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
consoleDemoInit(); consoleDemoInit();
@ -64,50 +28,45 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n"); printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank(); swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos // Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL); nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS NF_SetRootFolder("NITROFS");
// Inicializa el motor 3D // Initialize 3D engine in the top screen in mode 0
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior NF_Set3D(0, 0);
// Inicializa el motor 2D // Initialize 2D engine in the bottom
NF_Set2D(1, 0); // Modo 2D_0 en la pantalla inferior NF_Set2D(1, 0);
// Inicializa los fondos tileados // Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Inicializa los fondos Tileados para la pantalla inferior NF_InitTiledBgSys(1); // Bottom screen
// Inicializa los buffers de los Sprites // Initialize 3D sprite system
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_InitSpriteBuffers(); // Initialize storage buffers
// Inicializa el sistema de Sprites en 3D y OpenGL
NF_Init3dSpriteSys(); NF_Init3dSpriteSys();
// Carga los fondos tileados // Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
NF_LoadTiledBg("bg/bg3", "bg3", 256, 256); NF_LoadTiledBg("bg/bg3", "bg3", 256, 256);
// Carga los graficos de los Sprites // Load sprite files from NitroFS
u8 n = 0; for (int n = 0; n < SPRITEMAXNUM; n ++)
for (n = 0; n < SPRITEMAXNUM; n ++) {
NF_LoadSpriteGfx("sprite/numbers", n, 16, 16); NF_LoadSpriteGfx("sprite/numbers", n, 16, 16);
}
NF_LoadSpritePal("sprite/numbers", 0); NF_LoadSpritePal("sprite/numbers", 0);
// Transfer the required sprites to VRAM
// Manda los graficos y paletas a la VRAM for (int n = 0; n < SPRITEMAXNUM; n ++)
for (n = 0; n < SPRITEMAXNUM; n ++) {
NF_Vram3dSpriteGfx(n, n, true); NF_Vram3dSpriteGfx(n, n, true);
}
NF_Vram3dSpritePal(0, 0); NF_Vram3dSpritePal(0, 0);
// Crea los fondos en ambas pantallas // Create backgrounds in both screens
NF_CreateTiledBg(0, 3, "bg3"); NF_CreateTiledBg(0, 3, "bg3");
NF_CreateTiledBg(1, 3, "nfl"); NF_CreateTiledBg(1, 3, "nfl");
// Variables // Variables
s16 x[SPRITEMAXNUM]; s16 x[SPRITEMAXNUM];
s16 y[SPRITEMAXNUM]; s16 y[SPRITEMAXNUM];
@ -116,64 +75,69 @@ int main(int argc, char **argv) {
u16 timer[SPRITEMAXNUM]; u16 timer[SPRITEMAXNUM];
u8 frame[SPRITEMAXNUM]; u8 frame[SPRITEMAXNUM];
// Inicializa las variables // Initialize sprite variables and create the sprites
for (n = 0; n < SPRITEMAXNUM; n ++) { for (int n = 0; n < SPRITEMAXNUM; n++)
x[n] = (((int)(rand() % 239))); {
y[n] = (((int)(rand() % 175))); x[n] = rand() % 239;
timer[n] = (((int)(rand() % 20))); y[n] = rand() % 175;
frame[n] = (((int)(rand() % 10))); timer[n] = rand() % 20;
if ((rand() % 100) > 50) { frame[n] = rand() % 10;
if ((rand() % 100) > 50)
ix[n] = 1; ix[n] = 1;
} else { else
ix[n] = -1; ix[n] = -1;
}
if ((rand() % 100) > 50) { if ((rand() % 100) > 50)
iy[n] = 1; iy[n] = 1;
} else { else
iy[n] = -1; iy[n] = -1;
}
// Crea los Sprites 3D
NF_Create3dSprite(n, n, 0, x[n], y[n]); NF_Create3dSprite(n, n, 0, x[n], y[n]);
NF_Set3dSpriteFrame(n, frame[n]); NF_Set3dSpriteFrame(n, frame[n]);
} }
// Y ordenalos en la cola segun su ID (El mas bajo tiene prioridad) // Sort their priorites based on their IDs (lower IDs have higher priority)
NF_Sort3dSprites(); NF_Sort3dSprites();
// Bucle (repite para siempre) while (1)
while(1) { {
// Move sprites
// Mueve todos los Sprites for (int n = 0; n < SPRITEMAXNUM; n ++)
for (n = 0; n < SPRITEMAXNUM; n ++) { {
x[n] += ix[n]; x[n] += ix[n];
if ((x[n] < 0) || (x[n] > (255 - NF_3DSPRITE[n].width))) ix[n] = -ix[n]; if ((x[n] < 0) || (x[n] > (255 - NF_3DSPRITE[n].width)))
ix[n] = -ix[n];
y[n] += iy[n]; y[n] += iy[n];
if ((y[n] < 0) || (y[n] > (191 - NF_3DSPRITE[n].height))) iy[n] = -iy[n]; if ((y[n] < 0) || (y[n] > (191 - NF_3DSPRITE[n].height)))
iy[n] = -iy[n];
timer[n] ++; timer[n] ++;
if (timer[n] > 19) { if (timer[n] > 19)
{
timer[n] = 0; timer[n] = 0;
frame[n]++; frame[n]++;
if (frame[n] > 9) frame[n] = 0; if (frame[n] > 9)
frame[n] = 0;
} }
NF_Move3dSprite(n, x[n], y[n]); NF_Move3dSprite(n, x[n], y[n]);
NF_Set3dSpriteFrame(n, frame[n]); NF_Set3dSpriteFrame(n, frame[n]);
} }
// Dibuja los 3D Sprites // Draw all 3D sprites
NF_Draw3dSprites(); NF_Draw3dSprites();
// Actualiza la escena 3D, si no lo haces, no se mostrara en pantalla // Tell the GPU to draw the scene and wait until it's done
glFlush(0); glFlush(0);
// Espera al sincronismo vertical // Wait for the screen refresh
swiWaitForVBlank(); swiWaitForVBlank();
// Actualiza las texturas de los 3D Sprites animados con KEEPFRAMES == TRUE // Update textures of any 3D sprite with "keepframes == true"
NF_Update3dSpritesGfx(); NF_Update3dSpritesGfx();
} }
return 0; return 0;
} }

View File

@ -1,60 +1,26 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Basic 3D sprite example.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de 3D 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>
#define MAXSPRITES 32 #define MAXSPRITES 32
int main(int argc, char **argv)
/* {
------------------------------------------------- // Set random seed based on the current time
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Inicializa el random
srand(time(NULL)); srand(time(NULL));
// Pantalla de espera inicializando NitroFS // Prepare a NitroFS initialization screen
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
consoleDemoInit(); consoleDemoInit();
@ -62,122 +28,116 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n"); printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank(); swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos // Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL); nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS NF_SetRootFolder("NITROFS");
// Inicializa el motor 3D // Initialize 3D engine in the top screen in mode 0
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior NF_Set3D(0, 0);
// Inicializa el motor 2D // Initialize 2D engine in the bottom screen in mode 0
NF_Set2D(1, 0); // Modo 2D_0 en la pantalla inferior NF_Set2D(1, 0);
// Inicializa los fondos tileados // Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Inicializa los fondos Tileados para la pantalla inferior NF_InitTiledBgSys(1); // Bottom screen
// Inicializa los buffers de los Sprites // Initialize 3D sprite system
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_InitSpriteBuffers(); // Initialize storage buffers
// Inicializa el sistema de Sprites en 3D y OpenGL
NF_Init3dSpriteSys(); NF_Init3dSpriteSys();
// Carga los fondos tileados // Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
NF_LoadTiledBg("bg/bg3", "bg3", 256, 256); NF_LoadTiledBg("bg/bg3", "bg3", 256, 256);
// Carga los graficos de los Sprites // Load sprite files from NitroFS
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64); NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
NF_LoadSpritePal("sprite/blueball", 0); NF_LoadSpritePal("sprite/blueball", 0);
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64); NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
NF_LoadSpritePal("sprite/redcar", 1); NF_LoadSpritePal("sprite/redcar", 1);
// Manda los graficos y paletas a la VRAM // Transfer the required sprites to VRAM
NF_Vram3dSpriteGfx(0, 0, true); NF_Vram3dSpriteGfx(0, 0, true);
NF_Vram3dSpritePal(0, 0); NF_Vram3dSpritePal(0, 0);
NF_Vram3dSpriteGfx(1, 1, true); NF_Vram3dSpriteGfx(1, 1, true);
NF_Vram3dSpritePal(1, 1); NF_Vram3dSpritePal(1, 1);
// Create backgrounds in both screens
// Crea los fondos en ambas pantallas
NF_CreateTiledBg(0, 3, "bg3"); NF_CreateTiledBg(0, 3, "bg3");
NF_CreateTiledBg(1, 3, "nfl"); NF_CreateTiledBg(1, 3, "nfl");
// Variables // Variables
u16 n = 0;
u16 r = 0;
s16 x[MAXSPRITES]; s16 x[MAXSPRITES];
s16 y[MAXSPRITES]; s16 y[MAXSPRITES];
s16 ix[MAXSPRITES]; s16 ix[MAXSPRITES];
s16 iy[MAXSPRITES]; s16 iy[MAXSPRITES];
// Inicializa las variables // Initialize sprite variables and create the sprites
for (n = 0; n < MAXSPRITES; n ++) { for (int n = 0; n < MAXSPRITES; n ++)
r = (n % 2); {
x[n] = (((int)(rand() % 128))); int r = n % 2;
y[n] = (((int)(rand() % 112)));
if ((rand() % 100) > 50) { x[n] = rand() % 128;
y[n] = rand() % 112;
if ((rand() % 100) > 50)
ix[n] = 1; ix[n] = 1;
} else { else
ix[n] = -1; ix[n] = -1;
}
if ((rand() % 100) > 50) { if ((rand() % 100) > 50)
iy[n] = 1; iy[n] = 1;
} else { else
iy[n] = -1; iy[n] = -1;
}
// Crea los Sprites 3D
NF_Create3dSprite(n, r, r, x[n], y[n]); NF_Create3dSprite(n, r, r, x[n], y[n]);
} }
// Y ordenalos en la cola segun su ID (El mas bajo tiene prioridad) // Sort their priorites based on their IDs (lower IDs have higher priority)
NF_Sort3dSprites(); NF_Sort3dSprites();
// Variable para la lectura del teclado while (1)
u16 keys = 0; {
// Read keys
// Bucle (repite para siempre)
while(1) {
// Lee el teclado
scanKeys(); scanKeys();
keys = keysDown(); u16 keys = keysDown();
// Mueve todos los Sprites // Move sprites
for (n = 0; n < MAXSPRITES; n ++) { for (int n = 0; n < MAXSPRITES; n ++)
{
x[n] += ix[n]; x[n] += ix[n];
if ((x[n] < 0) || (x[n] > (255 - NF_3DSPRITE[n].width))) ix[n] = -ix[n]; if ((x[n] < 0) || (x[n] > (255 - NF_3DSPRITE[n].width)))
ix[n] = -ix[n];
y[n] += iy[n]; y[n] += iy[n];
if ((y[n] < 0) || (y[n] > (191 - NF_3DSPRITE[n].height))) iy[n] = -iy[n]; if ((y[n] < 0) || (y[n] > (191 - NF_3DSPRITE[n].height)))
iy[n] = -iy[n];
NF_Move3dSprite(n, x[n], y[n]); NF_Move3dSprite(n, x[n], y[n]);
} }
// Muestra u oculta los sprites pares // Show or hide all sprites with even ID
if (keys & KEY_A) { if (keys & KEY_A)
for (n = 0; n < MAXSPRITES; n +=2) { {
for (int n = 0; n < MAXSPRITES; n += 2)
NF_Show3dSprite(n, true); NF_Show3dSprite(n, true);
} }
}
if (keys & KEY_B) { if (keys & KEY_B)
for (n = 0; n < MAXSPRITES; n +=2) { {
for (int n = 0; n < MAXSPRITES; n += 2)
NF_Show3dSprite(n, false); NF_Show3dSprite(n, false);
} }
} // Draw all 3D sprites
// Dibuja los 3D Sprites
NF_Draw3dSprites(); NF_Draw3dSprites();
// Actualiza la escena 3D, si no lo haces, no se mostrara en pantalla // Tell the GPU to draw the scene and wait until it's done
glFlush(0); glFlush(0);
// Espera al sincronismo vertical // Wait for the screen refresh
swiWaitForVBlank(); swiWaitForVBlank();
} }
return 0; return 0;
} }

View File

@ -1,61 +1,26 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Example of rotating and scaling 3D sprites.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de 3D Sprites
Rotacion y escalado
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>
#define MAXSPRITES 8 #define MAXSPRITES 8
int main(int argc, char **argv)
/* {
------------------------------------------------- // Set random seed based on the current time
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Inicializa el random
srand(time(NULL)); srand(time(NULL));
// Pantalla de espera inicializando NitroFS // Prepare a NitroFS initialization screen
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
consoleDemoInit(); consoleDemoInit();
@ -63,46 +28,40 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n"); printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank(); swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos // Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL); nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS NF_SetRootFolder("NITROFS");
// Inicializa el motor 3D // Initialize 3D engine in the top screen in mode 0
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior NF_Set3D(0, 0);
// Inicializa los fondos tileados // Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior NF_InitTiledBgSys(0); // Top screen
// Inicializa los buffers de los Sprites // Initialize 3D sprite system
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_InitSpriteBuffers(); // Initialize storage buffers
// Inicializa el sistema de Sprites en 3D y OpenGL
NF_Init3dSpriteSys(); NF_Init3dSpriteSys();
// Carga los fondos tileados // Load background files from NitroFS
NF_LoadTiledBg("bg/bg3", "bg3", 256, 256); NF_LoadTiledBg("bg/bg3", "bg3", 256, 256);
// Carga los graficos de los Sprites // Load sprite files from NitroFS
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64); NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
NF_LoadSpritePal("sprite/blueball", 0); NF_LoadSpritePal("sprite/blueball", 0);
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64); NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
NF_LoadSpritePal("sprite/redcar", 1); NF_LoadSpritePal("sprite/redcar", 1);
// Manda los graficos y paletas a la VRAM // Transfer the required sprites to VRAM
NF_Vram3dSpriteGfx(0, 0, true); NF_Vram3dSpriteGfx(0, 0, true);
NF_Vram3dSpritePal(0, 0); NF_Vram3dSpritePal(0, 0);
NF_Vram3dSpriteGfx(1, 1, true); NF_Vram3dSpriteGfx(1, 1, true);
NF_Vram3dSpritePal(1, 1); NF_Vram3dSpritePal(1, 1);
// Create background
// Crea los fondos en ambas pantallas
NF_CreateTiledBg(0, 3, "bg3"); NF_CreateTiledBg(0, 3, "bg3");
// Variables // Variables
u16 n = 0;
u16 r = 0;
s16 x[MAXSPRITES]; s16 x[MAXSPRITES];
s16 y[MAXSPRITES]; s16 y[MAXSPRITES];
s16 ix[MAXSPRITES]; s16 ix[MAXSPRITES];
@ -112,121 +71,144 @@ int main(int argc, char **argv) {
s16 rz[MAXSPRITES]; s16 rz[MAXSPRITES];
s16 scale[MAXSPRITES]; s16 scale[MAXSPRITES];
// Inicializa las variables // Initialize sprite variables and create the sprites
for (n = 0; n < MAXSPRITES; n ++) { for (int n = 0; n < MAXSPRITES; n++)
if ((n % 2) == 0) { {
int r;
if ((n % 2) == 0)
r = 1; r = 1;
} else { else
r = 0; r = 0;
}
x[n] = (((int)(rand() % 128)) + 1); x[n] = (rand() % 128) + 1;
y[n] = (((int)(rand() % 112)) + 1); y[n] = (rand() % 112) + 1;
if ((rand() % 100) > 50) { if ((rand() % 100) > 50)
ix[n] = 1; ix[n] = 1;
} else { else
ix[n] = -1; ix[n] = -1;
}
if ((rand() % 100) > 50) { if ((rand() % 100) > 50)
iy[n] = 1; iy[n] = 1;
} else { else
iy[n] = -1; iy[n] = -1;
}
rx[n] = 0; rx[n] = 0;
ry[n] = 0; ry[n] = 0;
rz[n] = 0; rz[n] = 0;
scale[n] = 64; scale[n] = 64;
// Crea los Sprites 3D
NF_Create3dSprite(n, r, r, x[n], y[n]); NF_Create3dSprite(n, r, r, x[n], y[n]);
} }
// Y ordenalos en la cola segun su ID (El mas bajo tiene prioridad) // Sort their priorites based on their IDs (lower IDs have higher priority)
NF_Sort3dSprites(); NF_Sort3dSprites();
// Variable para la lectura del teclado // Variable that contains the ID of the sprite selected by the user
u16 press = 0;
u16 held = 0;
s16 id = 0; s16 id = 0;
// Bucle (repite para siempre) while (1)
while(1) { {
// Read keys
// Lee el teclado
scanKeys(); scanKeys();
press = keysDown(); u16 press = keysDown();
held = keysHeld(); u16 held = keysHeld();
// Mueve todos los Sprites // Move sprites
for (n = 0; n < MAXSPRITES; n ++) { for (int n = 0; n < MAXSPRITES; n++)
{
x[n] += ix[n]; x[n] += ix[n];
if ((x[n] < 1) || (x[n] > (255 - NF_3DSPRITE[n].width))) ix[n] = -ix[n]; if ((x[n] < 1) || (x[n] > (255 - NF_3DSPRITE[n].width)))
ix[n] = -ix[n];
y[n] += iy[n]; y[n] += iy[n];
if ((y[n] < 1) || (y[n] > (191 - NF_3DSPRITE[n].height))) iy[n] = -iy[n]; if ((y[n] < 1) || (y[n] > (191 - NF_3DSPRITE[n].height)))
iy[n] = -iy[n];
NF_Move3dSprite(n, x[n], y[n]); NF_Move3dSprite(n, x[n], y[n]);
} }
// Selecciona el Sprite con A y B // Change the selected sprite by pressing A or B
if (press & KEY_A) { if (press & KEY_A)
{
id++; id++;
if (id > (MAXSPRITES - 1)) id = 0; if (id > (MAXSPRITES - 1))
id = 0;
} }
if (press & KEY_B) { if (press & KEY_B)
{
id--; id--;
if (id < 0) id = (MAXSPRITES - 1); if (id < 0)
id = MAXSPRITES - 1;
} }
// Rota el Z del Sprite ID // Rotate Z axis of the selcted sprite
if (held & KEY_RIGHT) { if (held & KEY_RIGHT)
{
rz[id] += 2; rz[id] += 2;
if (rz[id] > 512) rz[id] -= 512; if (rz[id] > 512)
rz[id] -= 512;
} }
if (held & KEY_LEFT) { if (held & KEY_LEFT)
{
rz[id] -= 2; rz[id] -= 2;
if (rz[id] < 0) rz[id] += 512; if (rz[id] < 0)
rz[id] += 512;
} }
// Rota el Y del Sprite ID // Rotate Y axis of the selcted sprite
if (held & KEY_DOWN) { if (held & KEY_DOWN)
{
ry[id] += 2; ry[id] += 2;
if (ry[id] > 512) ry[id] -= 512; if (ry[id] > 512)
ry[id] -= 512;
} }
if (held & KEY_UP) { if (held & KEY_UP)
{
ry[id] -= 2; ry[id] -= 2;
if (ry[id] < 0) ry[id] += 512; if (ry[id] < 0)
ry[id] += 512;
} }
// Rota el X del Sprite ID // Rotate X axis of the selcted sprite
if (held & KEY_X) { if (held & KEY_X)
{
rx[id] += 2; rx[id] += 2;
if (rx[id] > 512) rx[id] -= 512; if (rx[id] > 512)
rx[id] -= 512;
} }
if (held & KEY_Y) { if (held & KEY_Y)
{
rx[id] -= 2; rx[id] -= 2;
if (rx[id] < 0) rx[id] += 512; if (rx[id] < 0)
rx[id] += 512;
} }
// Escala el sprite // Scale sprite
if (held & KEY_R) { if (held & KEY_R)
{
scale[id] += 2; scale[id] += 2;
if (scale[id] > 512) scale[id] = 512; if (scale[id] > 512)
scale[id] = 512;
} }
if (held & KEY_L) { if (held & KEY_L)
{
scale[id] -= 2; scale[id] -= 2;
if (scale[id] < 0) scale[id] = 0; if (scale[id] < 0)
scale[id] = 0;
} }
// Aplica la rotacion // Apply rotation and scale
NF_Rotate3dSprite(id, rx[id], ry[id], rz[id]); NF_Rotate3dSprite(id, rx[id], ry[id], rz[id]);
// Aplica el escalado
NF_Scale3dSprite(id, scale[id], scale[id]); NF_Scale3dSprite(id, scale[id], scale[id]);
// Dibuja los 3D Sprites // Draw all 3D sprites
NF_Draw3dSprites(); NF_Draw3dSprites();
// Actualiza la escena 3D, si no lo haces, no se mostrara en pantalla // Tell the GPU to draw the scene and wait until it's done
glFlush(0); glFlush(0);
// Debug // Print debug information
consoleClear(); consoleClear();
printf("A / B - Sprite select %d\n", id); printf("A / B - Sprite select %d\n", id);
printf("Rotate Z (LEFT/RIGHT) %d\n", rz[id]); printf("Rotate Z (LEFT/RIGHT) %d\n", rz[id]);
@ -234,11 +216,9 @@ int main(int argc, char **argv) {
printf("Rotate X (X/Y) %d\n", rx[id]); printf("Rotate X (X/Y) %d\n", rx[id]);
printf("Scale (R/L) %d\n", scale[id]); printf("Scale (R/L) %d\n", scale[id]);
// Espera al sincronismo vertical // Wait for the screen refresh
swiWaitForVBlank(); swiWaitForVBlank();
} }
return 0; return 0;
} }

View File

@ -1,61 +1,27 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Priority change example.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de 3D Sprites - Cambio de prioridad
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>
#define MAXSPRITES 16 #define MAXSPRITES 16
#define TARGET 8 #define TARGET 8
int main(int argc, char **argv)
/* {
------------------------------------------------- // Set random seed based on the current time
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Inicializa el random
srand(time(NULL)); srand(time(NULL));
// Pantalla de espera inicializando NitroFS // Prepare a NitroFS initialization screen
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
consoleDemoInit(); consoleDemoInit();
@ -63,132 +29,141 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n"); printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank(); swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos // Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL); nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS NF_SetRootFolder("NITROFS");
// Inicializa el motor 3D // Initialize 3D engine in the top screen in mode 0
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior NF_Set3D(0, 0);
// Inicializa los fondos tileados // Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior NF_InitTiledBgSys(0); // Top screen
// Inicializa los buffers de los Sprites // Initialize 3D sprite system
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_InitSpriteBuffers(); // Initialize storage buffers
// Inicializa el sistema de Sprites en 3D y OpenGL
NF_Init3dSpriteSys(); NF_Init3dSpriteSys();
// Carga los fondos tileados // Load background files from NitroFS
NF_LoadTiledBg("bg/bg3", "bg3", 256, 256); NF_LoadTiledBg("bg/bg3", "bg3", 256, 256);
// Carga los graficos de los Sprites // Load sprite files from NitroFS
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64); NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
NF_LoadSpritePal("sprite/blueball", 0); NF_LoadSpritePal("sprite/blueball", 0);
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64); NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
NF_LoadSpritePal("sprite/redcar", 1); NF_LoadSpritePal("sprite/redcar", 1);
// Manda los graficos y paletas a la VRAM // Transfer the required sprites to VRAM
NF_Vram3dSpriteGfx(0, 0, true); NF_Vram3dSpriteGfx(0, 0, true);
NF_Vram3dSpritePal(0, 0); NF_Vram3dSpritePal(0, 0);
NF_Vram3dSpriteGfx(1, 1, true); NF_Vram3dSpriteGfx(1, 1, true);
NF_Vram3dSpritePal(1, 1); NF_Vram3dSpritePal(1, 1);
// Create background
// Crea los fondos en ambas pantallas
NF_CreateTiledBg(0, 3, "bg3"); NF_CreateTiledBg(0, 3, "bg3");
// Variables // Variables
u16 n = 0;
u16 r = 0;
s16 x[MAXSPRITES]; s16 x[MAXSPRITES];
s16 y[MAXSPRITES]; s16 y[MAXSPRITES];
s16 ix[MAXSPRITES]; s16 ix[MAXSPRITES];
s16 iy[MAXSPRITES]; s16 iy[MAXSPRITES];
// Inicializa las variables // Initialize sprite variables and create the sprites
for (n = 0; n < MAXSPRITES; n ++) { for (int n = 0; n < MAXSPRITES; n++)
if (n == TARGET) { {
int r;
if (n == TARGET)
r = 1; r = 1;
} else { else
r = 0; r = 0;
}
x[n] = (((int)(rand() % 128))); x[n] = rand() % 128;
y[n] = (((int)(rand() % 112))); y[n] = rand() % 112;
if ((rand() % 100) > 50) {
if ((rand() % 100) > 50)
ix[n] = 1; ix[n] = 1;
} else { else
ix[n] = -1; ix[n] = -1;
}
if ((rand() % 100) > 50) { if ((rand() % 100) > 50)
iy[n] = 1; iy[n] = 1;
} else { else
iy[n] = -1; iy[n] = -1;
}
// Crea los Sprites 3D
NF_Create3dSprite(n, r, r, x[n], y[n]); NF_Create3dSprite(n, r, r, x[n], y[n]);
} }
// Y ordenalos en la cola segun su ID (El mas bajo tiene prioridad) // Sort their priorites based on their IDs (lower IDs have higher priority)
NF_Sort3dSprites(); NF_Sort3dSprites();
// Variable para la lectura del teclado // Variable that holds the current priority of the user-controlled sprite
u16 keys = 0;
s16 prio = TARGET; s16 prio = TARGET;
// Bucle (repite para siempre) while (1)
while(1) { {
// Read keys
// Lee el teclado
scanKeys(); scanKeys();
keys = keysDown(); u16 keys = keysDown();
// Mueve todos los Sprites // Move sprites
for (n = 0; n < MAXSPRITES; n ++) { for (int n = 0; n < MAXSPRITES; n++)
{
x[n] += ix[n]; x[n] += ix[n];
if ((x[n] < 0) || (x[n] > (255 - NF_3DSPRITE[n].width))) ix[n] = -ix[n]; if ((x[n] < 0) || (x[n] > (255 - NF_3DSPRITE[n].width)))
ix[n] = -ix[n];
y[n] += iy[n]; y[n] += iy[n];
if ((y[n] < 0) || (y[n] > (191 - NF_3DSPRITE[n].height))) iy[n] = -iy[n]; if ((y[n] < 0) || (y[n] > (191 - NF_3DSPRITE[n].height)))
iy[n] = -iy[n];
NF_Move3dSprite(n, x[n], y[n]); NF_Move3dSprite(n, x[n], y[n]);
} }
// Cambia la prioridad del Sprite seleccionado // Change the priority of the sprite
if ((keys & KEY_A) && (prio > 0)) { if ((keys & KEY_A) && (prio > 0))
{
prio --; prio --;
NF_Set3dSpritePriority(TARGET, prio); NF_Set3dSpritePriority(TARGET, prio);
} }
if ((keys & KEY_B) && (prio < (MAXSPRITES - 1))) { if ((keys & KEY_B) && (prio < (MAXSPRITES - 1)))
{
prio ++; prio ++;
NF_Set3dSpritePriority(TARGET, prio); NF_Set3dSpritePriority(TARGET, prio);
} }
// Restaura la prioridad por defecto
if (keys & KEY_X) NF_3dSpriteSetDepth(TARGET, 0);
// Fuerza estar al frente
if (keys & KEY_R) NF_3dSpriteSetDepth(TARGET, -512);
// Fuerza estar al fondo
if (keys & KEY_L) NF_3dSpriteSetDepth(TARGET, 512);
// Dibuja los 3D Sprites // Restore default priority
if (keys & KEY_X)
NF_3dSpriteSetDepth(TARGET, 0);
// Move sprite on top of everything
if (keys & KEY_R)
NF_3dSpriteSetDepth(TARGET, -512);
// Move sprite to the back
if (keys & KEY_L)
NF_3dSpriteSetDepth(TARGET, 512);
// Draw all 3D sprites
NF_Draw3dSprites(); NF_Draw3dSprites();
// Actualiza la escena 3D, si no lo haces, no se mostrara en pantalla // Tell the GPU to draw the scene and wait until it's done
glFlush(0); glFlush(0);
// Debug // Print debug information
consoleClear(); consoleClear();
for (n = 0; n < NF_CREATED_3DSPRITE.total; n ++) { for (int n = 0; n < NF_CREATED_3DSPRITE.total; n++)
printf("Pri:%02d Spr:%02d Spr:%02d Pri:%02d\n", n, NF_CREATED_3DSPRITE.id[n], n, NF_3DSPRITE[n].prio); {
printf("Pri:%02d Spr:%02d Spr:%02d Pri:%02d\n",
n, NF_CREATED_3DSPRITE.id[n], n, NF_3DSPRITE[n].prio);
} }
printf("\nSprite Id%02d is on %02d priority\n\n", TARGET, NF_3DSPRITE[TARGET].prio); printf("\nSprite Id%02d is on %02d priority\n\n",
TARGET, NF_3DSPRITE[TARGET].prio);
printf("A - Near B - Far"); printf("A - Near B - Far");
// Espera al sincronismo vertical // Wait for the screen refresh
swiWaitForVBlank(); swiWaitForVBlank();
} }
return 0; return 0;
} }

View File

@ -1,61 +1,26 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Priority swap example.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de 3D Sprites
Intercambio de prioridades
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>
#define MAXSPRITES 32 #define MAXSPRITES 32
int main(int argc, char **argv)
/* {
------------------------------------------------- // Set random seed based on the current time
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Inicializa el random
srand(time(NULL)); srand(time(NULL));
// Pantalla de espera inicializando NitroFS // Prepare a NitroFS initialization screen
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
consoleDemoInit(); consoleDemoInit();
@ -63,121 +28,117 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n"); printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank(); swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos // Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL); nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS NF_SetRootFolder("NITROFS");
// Inicializa el motor 3D // Initialize 3D engine in the top screen in mode 0
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior NF_Set3D(0, 0);
// Inicializa los fondos tileados // Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior NF_InitTiledBgSys(0); // Top screen
// Inicializa los buffers de los Sprites // Initialize 3D sprite system
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_InitSpriteBuffers(); // Initialize storage buffers
// Inicializa el sistema de Sprites en 3D y OpenGL
NF_Init3dSpriteSys(); NF_Init3dSpriteSys();
// Carga los fondos tileados // Load background files from NitroFS
NF_LoadTiledBg("bg/bg3", "bg3", 256, 256); NF_LoadTiledBg("bg/bg3", "bg3", 256, 256);
// Carga los graficos de los Sprites // Load sprite files from NitroFS
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64); NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
NF_LoadSpritePal("sprite/blueball", 0); NF_LoadSpritePal("sprite/blueball", 0);
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64); NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
NF_LoadSpritePal("sprite/redcar", 1); NF_LoadSpritePal("sprite/redcar", 1);
// Manda los graficos y paletas a la VRAM // Transfer the required sprites to VRAM
NF_Vram3dSpriteGfx(0, 0, true); NF_Vram3dSpriteGfx(0, 0, true);
NF_Vram3dSpritePal(0, 0); NF_Vram3dSpritePal(0, 0);
NF_Vram3dSpriteGfx(1, 1, true); NF_Vram3dSpriteGfx(1, 1, true);
NF_Vram3dSpritePal(1, 1); NF_Vram3dSpritePal(1, 1);
// Create background
// Crea los fondos en ambas pantallas
NF_CreateTiledBg(0, 3, "bg3"); NF_CreateTiledBg(0, 3, "bg3");
// Variables // Variables
u16 n = 0;
u16 r = 0;
s16 x[MAXSPRITES]; s16 x[MAXSPRITES];
s16 y[MAXSPRITES]; s16 y[MAXSPRITES];
s16 ix[MAXSPRITES]; s16 ix[MAXSPRITES];
s16 iy[MAXSPRITES]; s16 iy[MAXSPRITES];
// Inicializa las variables // Initialize sprite variables and create the sprites
for (n = 0; n < MAXSPRITES; n ++) { for (int n = 0; n < MAXSPRITES; n++)
if ((n == 0) || (n == (MAXSPRITES - 1))) { {
int r;
if ((n == 0) || (n == (MAXSPRITES - 1)))
r = 1; r = 1;
} else { else
r = 0; r = 0;
}
x[n] = (((int)(rand() % 128)) + 1); x[n] = (rand() % 128) + 1;
y[n] = (((int)(rand() % 112)) + 1); y[n] = (rand() % 112) + 1;
if ((rand() % 100) > 50) {
if ((rand() % 100) > 50)
ix[n] = 1; ix[n] = 1;
} else { else
ix[n] = -1; ix[n] = -1;
}
if ((rand() % 100) > 50) { if ((rand() % 100) > 50)
iy[n] = 1; iy[n] = 1;
} else { else
iy[n] = -1; iy[n] = -1;
}
// Crea los Sprites 3D
NF_Create3dSprite(n, r, r, x[n], y[n]); NF_Create3dSprite(n, r, r, x[n], y[n]);
} }
// Y ordenalos en la cola segun su ID (El mas bajo tiene prioridad) // Sort their priorites based on their IDs (lower IDs have higher priority)
NF_Sort3dSprites(); NF_Sort3dSprites();
// Variable para la lectura del teclado while (1)
u16 keys = 0; {
// Read keys
// Bucle (repite para siempre)
while(1) {
// Lee el teclado
scanKeys(); scanKeys();
keys = keysDown(); u16 keys = keysDown();
// Mueve todos los Sprites // Move sprites
for (n = 0; n < MAXSPRITES; n ++) { for (int n = 0; n < MAXSPRITES; n++)
{
x[n] += ix[n]; x[n] += ix[n];
if ((x[n] < 1) || (x[n] > (255 - NF_3DSPRITE[n].width))) ix[n] = -ix[n]; if ((x[n] < 1) || (x[n] > (255 - NF_3DSPRITE[n].width)))
ix[n] = -ix[n];
y[n] += iy[n]; y[n] += iy[n];
if ((y[n] < 1) || (y[n] > (191 - NF_3DSPRITE[n].height))) iy[n] = -iy[n]; if ((y[n] < 1) || (y[n] > (191 - NF_3DSPRITE[n].height)))
iy[n] = -iy[n];
NF_Move3dSprite(n, x[n], y[n]); NF_Move3dSprite(n, x[n], y[n]);
} }
// Muestra u oculta los sprites pares // Show or hide sprites with even ID
if (keys & KEY_A) { if (keys & KEY_A)
NF_Swap3dSpritePriority(0, (MAXSPRITES - 1)); NF_Swap3dSpritePriority(0, MAXSPRITES - 1);
}
if (keys & KEY_B) {
NF_Swap3dSpritePriority((MAXSPRITES - 1), 0);
}
// Dibuja los 3D Sprites if (keys & KEY_B)
NF_Swap3dSpritePriority(MAXSPRITES - 1, 0);
// Draw all 3D sprites
NF_Draw3dSprites(); NF_Draw3dSprites();
// Actualiza la escena 3D, si no lo haces, no se mostrara en pantalla // Tell the GPU to draw the scene and wait until it's done
glFlush(0); glFlush(0);
// Debug // Print debug information
consoleClear(); consoleClear();
printf("\nSprite Id%02d is on %02d priority\n", 0, NF_3DSPRITE[0].prio); printf("\nSprite Id%02d is on %02d priority\n", 0, NF_3DSPRITE[0].prio);
printf("Sprite Id%02d is on %02d priority\n\n", (MAXSPRITES - 1), NF_3DSPRITE[(MAXSPRITES - 1)].prio); printf("Sprite Id%02d is on %02d priority\n\n",
printf("A or B - Swap 0 & %d", (MAXSPRITES - 1)); MAXSPRITES - 1, NF_3DSPRITE[MAXSPRITES - 1].prio);
printf("A or B - Swap 0 & %d", MAXSPRITES - 1);
// Espera al sincronismo vertical // Wait for the screen refresh
swiWaitForVBlank(); swiWaitForVBlank();
} }
return 0; return 0;
} }