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");
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);
// Initialize tiled backgrounds system
@ -66,7 +66,7 @@ int main(int argc, char **argv)
s16 ix = 4;
s16 iy = 4;
// Create sprites
// Initialize sprite variables and create the sprites
for (int n = 0; n < MAXSPRITES; n ++)
{
x[n] = 128 - 32;

View File

@ -1,62 +1,26 @@
// SPDX-License-Identifier: CC0-1.0
//
// 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 <time.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
#define SPRITEMAXNUM 255
int main(int argc, char **argv) {
// Inicializa el random
int main(int argc, char **argv)
{
// Set random seed based on the current time
srand(time(NULL));
// Pantalla de espera inicializando NitroFS
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
@ -64,50 +28,45 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
NF_SetRootFolder("NITROFS");
// Inicializa el motor 3D
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior
// Initialize 3D engine in the top screen in mode 0
NF_Set3D(0, 0);
// Inicializa el motor 2D
NF_Set2D(1, 0); // Modo 2D_0 en la pantalla inferior
// Initialize 2D engine in the bottom
NF_Set2D(1, 0);
// Inicializa los fondos tileados
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
NF_InitTiledBgSys(1); // Inicializa los fondos Tileados para la pantalla inferior
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
// Inicializa los buffers de los Sprites
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas
// Inicializa el sistema de Sprites en 3D y OpenGL
// Initialize 3D sprite system
NF_InitSpriteBuffers(); // Initialize storage buffers
NF_Init3dSpriteSys();
// Carga los fondos tileados
// Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
NF_LoadTiledBg("bg/bg3", "bg3", 256, 256);
// Carga los graficos de los Sprites
u8 n = 0;
for (n = 0; n < SPRITEMAXNUM; n ++) {
// Load sprite files from NitroFS
for (int n = 0; n < SPRITEMAXNUM; n ++)
NF_LoadSpriteGfx("sprite/numbers", n, 16, 16);
}
NF_LoadSpritePal("sprite/numbers", 0);
// Manda los graficos y paletas a la VRAM
for (n = 0; n < SPRITEMAXNUM; n ++) {
// Transfer the required sprites to VRAM
for (int n = 0; n < SPRITEMAXNUM; n ++)
NF_Vram3dSpriteGfx(n, n, true);
}
NF_Vram3dSpritePal(0, 0);
// Crea los fondos en ambas pantallas
// Create backgrounds in both screens
NF_CreateTiledBg(0, 3, "bg3");
NF_CreateTiledBg(1, 3, "nfl");
// Variables
s16 x[SPRITEMAXNUM];
s16 y[SPRITEMAXNUM];
@ -116,64 +75,69 @@ int main(int argc, char **argv) {
u16 timer[SPRITEMAXNUM];
u8 frame[SPRITEMAXNUM];
// Inicializa las variables
for (n = 0; n < SPRITEMAXNUM; n ++) {
x[n] = (((int)(rand() % 239)));
y[n] = (((int)(rand() % 175)));
timer[n] = (((int)(rand() % 20)));
frame[n] = (((int)(rand() % 10)));
if ((rand() % 100) > 50) {
// Initialize sprite variables and create the sprites
for (int n = 0; n < SPRITEMAXNUM; n++)
{
x[n] = rand() % 239;
y[n] = rand() % 175;
timer[n] = rand() % 20;
frame[n] = rand() % 10;
if ((rand() % 100) > 50)
ix[n] = 1;
} else {
else
ix[n] = -1;
}
if ((rand() % 100) > 50) {
if ((rand() % 100) > 50)
iy[n] = 1;
} else {
else
iy[n] = -1;
}
// Crea los Sprites 3D
NF_Create3dSprite(n, n, 0, x[n], y[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();
// Bucle (repite para siempre)
while(1) {
// Mueve todos los Sprites
for (n = 0; n < SPRITEMAXNUM; n ++) {
while (1)
{
// Move sprites
for (int n = 0; n < SPRITEMAXNUM; 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];
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] ++;
if (timer[n] > 19) {
if (timer[n] > 19)
{
timer[n] = 0;
frame[n] ++;
if (frame[n] > 9) frame[n] = 0;
frame[n]++;
if (frame[n] > 9)
frame[n] = 0;
}
NF_Move3dSprite(n, x[n], y[n]);
NF_Set3dSpriteFrame(n, frame[n]);
}
// Dibuja los 3D Sprites
// Draw all 3D sprites
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);
// Espera al sincronismo vertical
// Wait for the screen refresh
swiWaitForVBlank();
// Actualiza las texturas de los 3D Sprites animados con KEEPFRAMES == TRUE
// Update textures of any 3D sprite with "keepframes == true"
NF_Update3dSpritesGfx();
}
return 0;
}

View File

@ -1,60 +1,26 @@
// SPDX-License-Identifier: CC0-1.0
//
// 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 <time.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
#define MAXSPRITES 32
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Inicializa el random
int main(int argc, char **argv)
{
// Set random seed based on the current time
srand(time(NULL));
// Pantalla de espera inicializando NitroFS
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
@ -62,122 +28,116 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
NF_SetRootFolder("NITROFS");
// Inicializa el motor 3D
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior
// Initialize 3D engine in the top screen in mode 0
NF_Set3D(0, 0);
// Inicializa el motor 2D
NF_Set2D(1, 0); // Modo 2D_0 en la pantalla inferior
// Initialize 2D engine in the bottom screen in mode 0
NF_Set2D(1, 0);
// Inicializa los fondos tileados
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
NF_InitTiledBgSys(1); // Inicializa los fondos Tileados para la pantalla inferior
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
// Inicializa los buffers de los Sprites
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas
// Inicializa el sistema de Sprites en 3D y OpenGL
// Initialize 3D sprite system
NF_InitSpriteBuffers(); // Initialize storage buffers
NF_Init3dSpriteSys();
// Carga los fondos tileados
// Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 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_LoadSpritePal("sprite/blueball", 0);
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
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_Vram3dSpritePal(0, 0);
NF_Vram3dSpriteGfx(1, 1, true);
NF_Vram3dSpritePal(1, 1);
// Crea los fondos en ambas pantallas
// Create backgrounds in both screens
NF_CreateTiledBg(0, 3, "bg3");
NF_CreateTiledBg(1, 3, "nfl");
// Variables
u16 n = 0;
u16 r = 0;
s16 x[MAXSPRITES];
s16 y[MAXSPRITES];
s16 ix[MAXSPRITES];
s16 iy[MAXSPRITES];
// Inicializa las variables
for (n = 0; n < MAXSPRITES; n ++) {
r = (n % 2);
x[n] = (((int)(rand() % 128)));
y[n] = (((int)(rand() % 112)));
if ((rand() % 100) > 50) {
// Initialize sprite variables and create the sprites
for (int n = 0; n < MAXSPRITES; n ++)
{
int r = n % 2;
x[n] = rand() % 128;
y[n] = rand() % 112;
if ((rand() % 100) > 50)
ix[n] = 1;
} else {
else
ix[n] = -1;
}
if ((rand() % 100) > 50) {
if ((rand() % 100) > 50)
iy[n] = 1;
} else {
else
iy[n] = -1;
}
// Crea los Sprites 3D
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();
// Variable para la lectura del teclado
u16 keys = 0;
// Bucle (repite para siempre)
while(1) {
// Lee el teclado
while (1)
{
// Read keys
scanKeys();
keys = keysDown();
u16 keys = keysDown();
// Mueve todos los Sprites
for (n = 0; n < MAXSPRITES; n ++) {
// Move sprites
for (int n = 0; n < MAXSPRITES; 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];
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]);
}
// Muestra u oculta los sprites pares
if (keys & KEY_A) {
for (n = 0; n < MAXSPRITES; n +=2) {
// Show or hide all sprites with even ID
if (keys & KEY_A)
{
for (int n = 0; n < MAXSPRITES; n += 2)
NF_Show3dSprite(n, true);
}
}
if (keys & KEY_B) {
for (n = 0; n < MAXSPRITES; n +=2) {
if (keys & KEY_B)
{
for (int n = 0; n < MAXSPRITES; n += 2)
NF_Show3dSprite(n, false);
}
}
// Dibuja los 3D Sprites
// Draw all 3D sprites
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);
// Espera al sincronismo vertical
// Wait for the screen refresh
swiWaitForVBlank();
}
return 0;
}

View File

@ -1,61 +1,26 @@
// SPDX-License-Identifier: CC0-1.0
//
// 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 <time.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
#define MAXSPRITES 8
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Inicializa el random
int main(int argc, char **argv)
{
// Set random seed based on the current time
srand(time(NULL));
// Pantalla de espera inicializando NitroFS
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
@ -63,46 +28,40 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
NF_SetRootFolder("NITROFS");
// Inicializa el motor 3D
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior
// Initialize 3D engine in the top screen in mode 0
NF_Set3D(0, 0);
// Inicializa los fondos tileados
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
// Inicializa los buffers de los Sprites
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas
// Inicializa el sistema de Sprites en 3D y OpenGL
// Initialize 3D sprite system
NF_InitSpriteBuffers(); // Initialize storage buffers
NF_Init3dSpriteSys();
// Carga los fondos tileados
// Load background files from NitroFS
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_LoadSpritePal("sprite/blueball", 0);
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
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_Vram3dSpritePal(0, 0);
NF_Vram3dSpriteGfx(1, 1, true);
NF_Vram3dSpritePal(1, 1);
// Crea los fondos en ambas pantallas
// Create background
NF_CreateTiledBg(0, 3, "bg3");
// Variables
u16 n = 0;
u16 r = 0;
s16 x[MAXSPRITES];
s16 y[MAXSPRITES];
s16 ix[MAXSPRITES];
@ -112,121 +71,144 @@ int main(int argc, char **argv) {
s16 rz[MAXSPRITES];
s16 scale[MAXSPRITES];
// Inicializa las variables
for (n = 0; n < MAXSPRITES; n ++) {
if ((n % 2) == 0) {
// Initialize sprite variables and create the sprites
for (int n = 0; n < MAXSPRITES; n++)
{
int r;
if ((n % 2) == 0)
r = 1;
} else {
else
r = 0;
}
x[n] = (((int)(rand() % 128)) + 1);
y[n] = (((int)(rand() % 112)) + 1);
if ((rand() % 100) > 50) {
x[n] = (rand() % 128) + 1;
y[n] = (rand() % 112) + 1;
if ((rand() % 100) > 50)
ix[n] = 1;
} else {
else
ix[n] = -1;
}
if ((rand() % 100) > 50) {
if ((rand() % 100) > 50)
iy[n] = 1;
} else {
else
iy[n] = -1;
}
rx[n] = 0;
ry[n] = 0;
rz[n] = 0;
scale[n] = 64;
// Crea los Sprites 3D
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();
// Variable para la lectura del teclado
u16 press = 0;
u16 held = 0;
// Variable that contains the ID of the sprite selected by the user
s16 id = 0;
// Bucle (repite para siempre)
while(1) {
// Lee el teclado
while (1)
{
// Read keys
scanKeys();
press = keysDown();
held = keysHeld();
u16 press = keysDown();
u16 held = keysHeld();
// Mueve todos los Sprites
for (n = 0; n < MAXSPRITES; n ++) {
// Move sprites
for (int n = 0; n < MAXSPRITES; 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];
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]);
}
// Selecciona el Sprite con A y B
if (press & KEY_A) {
id ++;
if (id > (MAXSPRITES - 1)) id = 0;
// Change the selected sprite by pressing A or B
if (press & KEY_A)
{
id++;
if (id > (MAXSPRITES - 1))
id = 0;
}
if (press & KEY_B) {
id --;
if (id < 0) id = (MAXSPRITES - 1);
if (press & KEY_B)
{
id--;
if (id < 0)
id = MAXSPRITES - 1;
}
// Rota el Z del Sprite ID
if (held & KEY_RIGHT) {
// Rotate Z axis of the selcted sprite
if (held & KEY_RIGHT)
{
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;
if (rz[id] < 0) rz[id] += 512;
if (rz[id] < 0)
rz[id] += 512;
}
// Rota el Y del Sprite ID
if (held & KEY_DOWN) {
// Rotate Y axis of the selcted sprite
if (held & KEY_DOWN)
{
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;
if (ry[id] < 0) ry[id] += 512;
if (ry[id] < 0)
ry[id] += 512;
}
// Rota el X del Sprite ID
if (held & KEY_X) {
// Rotate X axis of the selcted sprite
if (held & KEY_X)
{
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;
if (rx[id] < 0) rx[id] += 512;
if (rx[id] < 0)
rx[id] += 512;
}
// Escala el sprite
if (held & KEY_R) {
// Scale sprite
if (held & KEY_R)
{
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;
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]);
// Aplica el escalado
NF_Scale3dSprite(id, scale[id], scale[id]);
// Dibuja los 3D Sprites
// Draw all 3D sprites
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);
// Debug
// Print debug information
consoleClear();
printf("A / B - Sprite select %d\n", 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("Scale (R/L) %d\n", scale[id]);
// Espera al sincronismo vertical
// Wait for the screen refresh
swiWaitForVBlank();
}
return 0;
}

View File

@ -1,61 +1,27 @@
// SPDX-License-Identifier: CC0-1.0
//
// 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 <time.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
#define MAXSPRITES 16
#define TARGET 8
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Inicializa el random
int main(int argc, char **argv)
{
// Set random seed based on the current time
srand(time(NULL));
// Pantalla de espera inicializando NitroFS
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
@ -63,132 +29,141 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
NF_SetRootFolder("NITROFS");
// Inicializa el motor 3D
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior
// Initialize 3D engine in the top screen in mode 0
NF_Set3D(0, 0);
// Inicializa los fondos tileados
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
// Inicializa los buffers de los Sprites
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas
// Inicializa el sistema de Sprites en 3D y OpenGL
// Initialize 3D sprite system
NF_InitSpriteBuffers(); // Initialize storage buffers
NF_Init3dSpriteSys();
// Carga los fondos tileados
// Load background files from NitroFS
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_LoadSpritePal("sprite/blueball", 0);
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
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_Vram3dSpritePal(0, 0);
NF_Vram3dSpriteGfx(1, 1, true);
NF_Vram3dSpritePal(1, 1);
// Crea los fondos en ambas pantallas
// Create background
NF_CreateTiledBg(0, 3, "bg3");
// Variables
u16 n = 0;
u16 r = 0;
s16 x[MAXSPRITES];
s16 y[MAXSPRITES];
s16 ix[MAXSPRITES];
s16 iy[MAXSPRITES];
// Inicializa las variables
for (n = 0; n < MAXSPRITES; n ++) {
if (n == TARGET) {
// Initialize sprite variables and create the sprites
for (int n = 0; n < MAXSPRITES; n++)
{
int r;
if (n == TARGET)
r = 1;
} else {
else
r = 0;
}
x[n] = (((int)(rand() % 128)));
y[n] = (((int)(rand() % 112)));
if ((rand() % 100) > 50) {
x[n] = rand() % 128;
y[n] = rand() % 112;
if ((rand() % 100) > 50)
ix[n] = 1;
} else {
else
ix[n] = -1;
}
if ((rand() % 100) > 50) {
if ((rand() % 100) > 50)
iy[n] = 1;
} else {
else
iy[n] = -1;
}
// Crea los Sprites 3D
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();
// Variable para la lectura del teclado
u16 keys = 0;
// Variable that holds the current priority of the user-controlled sprite
s16 prio = TARGET;
// Bucle (repite para siempre)
while(1) {
// Lee el teclado
while (1)
{
// Read keys
scanKeys();
keys = keysDown();
u16 keys = keysDown();
// Mueve todos los Sprites
for (n = 0; n < MAXSPRITES; n ++) {
// Move sprites
for (int n = 0; n < MAXSPRITES; 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];
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]);
}
// Cambia la prioridad del Sprite seleccionado
if ((keys & KEY_A) && (prio > 0)) {
// Change the priority of the sprite
if ((keys & KEY_A) && (prio > 0))
{
prio --;
NF_Set3dSpritePriority(TARGET, prio);
}
if ((keys & KEY_B) && (prio < (MAXSPRITES - 1))) {
if ((keys & KEY_B) && (prio < (MAXSPRITES - 1)))
{
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();
// 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);
// Debug
// Print debug information
consoleClear();
for (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);
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("\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");
// Espera al sincronismo vertical
// Wait for the screen refresh
swiWaitForVBlank();
}
return 0;
}

View File

@ -1,61 +1,26 @@
// SPDX-License-Identifier: CC0-1.0
//
// 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 <time.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
#define MAXSPRITES 32
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Inicializa el random
int main(int argc, char **argv)
{
// Set random seed based on the current time
srand(time(NULL));
// Pantalla de espera inicializando NitroFS
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
@ -63,121 +28,117 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
NF_SetRootFolder("NITROFS");
// Inicializa el motor 3D
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior
// Initialize 3D engine in the top screen in mode 0
NF_Set3D(0, 0);
// Inicializa los fondos tileados
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
// Inicializa los buffers de los Sprites
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas
// Inicializa el sistema de Sprites en 3D y OpenGL
// Initialize 3D sprite system
NF_InitSpriteBuffers(); // Initialize storage buffers
NF_Init3dSpriteSys();
// Carga los fondos tileados
// Load background files from NitroFS
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_LoadSpritePal("sprite/blueball", 0);
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
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_Vram3dSpritePal(0, 0);
NF_Vram3dSpriteGfx(1, 1, true);
NF_Vram3dSpritePal(1, 1);
// Crea los fondos en ambas pantallas
// Create background
NF_CreateTiledBg(0, 3, "bg3");
// Variables
u16 n = 0;
u16 r = 0;
s16 x[MAXSPRITES];
s16 y[MAXSPRITES];
s16 ix[MAXSPRITES];
s16 iy[MAXSPRITES];
// Inicializa las variables
for (n = 0; n < MAXSPRITES; n ++) {
if ((n == 0) || (n == (MAXSPRITES - 1))) {
// Initialize sprite variables and create the sprites
for (int n = 0; n < MAXSPRITES; n++)
{
int r;
if ((n == 0) || (n == (MAXSPRITES - 1)))
r = 1;
} else {
else
r = 0;
}
x[n] = (((int)(rand() % 128)) + 1);
y[n] = (((int)(rand() % 112)) + 1);
if ((rand() % 100) > 50) {
x[n] = (rand() % 128) + 1;
y[n] = (rand() % 112) + 1;
if ((rand() % 100) > 50)
ix[n] = 1;
} else {
else
ix[n] = -1;
}
if ((rand() % 100) > 50) {
if ((rand() % 100) > 50)
iy[n] = 1;
} else {
else
iy[n] = -1;
}
// Crea los Sprites 3D
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();
// Variable para la lectura del teclado
u16 keys = 0;
// Bucle (repite para siempre)
while(1) {
// Lee el teclado
while (1)
{
// Read keys
scanKeys();
keys = keysDown();
u16 keys = keysDown();
// Mueve todos los Sprites
for (n = 0; n < MAXSPRITES; n ++) {
// Move sprites
for (int n = 0; n < MAXSPRITES; 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];
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]);
}
// Muestra u oculta los sprites pares
if (keys & KEY_A) {
NF_Swap3dSpritePriority(0, (MAXSPRITES - 1));
}
if (keys & KEY_B) {
NF_Swap3dSpritePriority((MAXSPRITES - 1), 0);
}
// Show or hide sprites with even ID
if (keys & KEY_A)
NF_Swap3dSpritePriority(0, MAXSPRITES - 1);
// Dibuja los 3D Sprites
if (keys & KEY_B)
NF_Swap3dSpritePriority(MAXSPRITES - 1, 0);
// Draw all 3D sprites
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);
// Debug
// Print debug information
consoleClear();
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("A or B - Swap 0 & %d", (MAXSPRITES - 1));
printf("Sprite Id%02d is on %02d priority\n\n",
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();
}
return 0;
}