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,60 +1,22 @@
// 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
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
consoleDemoInit(); consoleDemoInit();
@ -62,83 +24,70 @@ 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 2D // Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas NF_Set2D(0, 0);
NF_Set2D(1, 0); 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); // Iniciliaza los fondos Tileados para la pantalla inferior NF_InitTiledBgSys(1); // Bottom screen
// Carga los archivos de fondo desde la FAT/NitroFS // Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla superior NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256); // Carga el fondo para la capa 3, pantalla inferior NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256);
NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256); // Carga el fondo para la capa 2, pantalla inferior NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256);
NF_LoadTiledBg("bg/bg1", "capa_1", 1536, 256); // Carga el fondo para la capa 1, pantalla inferior NF_LoadTiledBg("bg/bg1", "capa_1", 1536, 256);
NF_LoadTiledBg("bg/bg0", "capa_0", 2048, 256); // Carga el fondo para la capa 0, pantalla inferior NF_LoadTiledBg("bg/bg0", "capa_0", 2048, 256);
// Create top screen background
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "nfl"); NF_CreateTiledBg(0, 3, "nfl");
// Crea los fondos de la pantalla inferior
// Create bottom screen backgrounds
NF_CreateTiledBg(1, 3, "capa_3"); NF_CreateTiledBg(1, 3, "capa_3");
NF_CreateTiledBg(1, 2, "capa_2"); NF_CreateTiledBg(1, 2, "capa_2");
NF_CreateTiledBg(1, 1, "capa_1"); NF_CreateTiledBg(1, 1, "capa_1");
NF_CreateTiledBg(1, 0, "capa_0"); NF_CreateTiledBg(1, 0, "capa_0");
// Variables // Variables
s16 bg_x[4]; s16 bg_x[4] = { 0, 0, 0, 0 };
s16 bg_y[4]; s16 bg_y[4] = { 0, 0, 0, 0 };
u16 keys = 0; while (1)
u8 n = 0; {
scanKeys(); // Read keypad
uint16_t keys = keysHeld(); // Keys currently pressed
// Inicializa las variables // If pressing left
for (n = 0; n < 4; n ++) { if (keys & KEY_LEFT)
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; bg_x[0] -= SPEED;
if (bg_x[0] < 0) bg_x[0] = 0; if (bg_x[0] < 0)
bg_x[0] = 0;
} }
// Si pulsas derecha // If pressing right
if (keys & KEY_RIGHT) { if (keys & KEY_RIGHT)
{
bg_x[0] += SPEED; bg_x[0] += SPEED;
if (bg_x[0] > 1663) bg_x[0] = 1663; // Limite fisico de la capa 0 if (bg_x[0] > 1663)
bg_x[0] = 1663; // Max scroll of layer 0
} }
// Calcula el efecto scroll parallax // Scroll other layers less than layer 0
bg_x[1] = (int)(bg_x[0] / 1.5); bg_x[1] = (int)(bg_x[0] / 1.5);
bg_x[2] = (int)(bg_x[1] / 1.5); bg_x[2] = (int)(bg_x[1] / 1.5);
swiWaitForVBlank(); // Espera al sincronismo vertical swiWaitForVBlank(); // Wait for the screen refresh
// Actualiza la posicion de los fondos // Update background scroll during vertical blanking to avoid tearing
for (n = 0; n < 4; n ++) { for (int n = 0; n < 4; n ++)
NF_ScrollBg(1, n, bg_x[n], bg_y[n]); NF_ScrollBg(1, n, bg_x[n], bg_y[n]);
} }
}
return 0; return 0;
} }

View File

@ -1,58 +1,22 @@
// 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
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
consoleDemoInit(); consoleDemoInit();
@ -60,34 +24,34 @@ 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 2D en modo BITMAP // Initialize 2D engine in both screens and use bitmap mode
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas NF_Set2D(0, 5);
NF_Set2D(1, 5); NF_Set2D(1, 5);
// Inicializa los fondos en modo "BITMAP" // Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1); NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1); NF_InitBitmapBgSys(1, 1);
// Inicializa los buffers para guardar fondos en formato BITMAP // Initialize storage buffers
NF_Init16bitsBgBuffers(); NF_Init16bitsBgBuffers();
// Inicializa el backbuffer // Initialize backbuffers
NF_Init16bitsBackBuffer(0); NF_Init16bitsBackBuffer(0);
NF_Init16bitsBackBuffer(1); NF_Init16bitsBackBuffer(1);
// Habilita el backbuffer // Enable backbuffers
NF_Enable16bitsBackBuffer(0); NF_Enable16bitsBackBuffer(0);
NF_Enable16bitsBackBuffer(1); NF_Enable16bitsBackBuffer(1);
// Carga el archivo BITMAP de imagen en formato RAW a la RAM // Load bitmap files from NitroFS
NF_Load16bitsBg("bmp/bitmap16", 0); NF_Load16bitsBg("bmp/bitmap16", 0);
NF_Load16bitsImage("bmp/blueball", 1, 64, 64); NF_Load16bitsImage("bmp/blueball", 1, 64, 64);
// Tranfiere la imagen a la VRAM de ambas pantallas // Load image to VRAM of both screens
NF_Copy16bitsBuffer(0, 1, 0); NF_Copy16bitsBuffer(0, 1, 0);
NF_Copy16bitsBuffer(1, 1, 0); NF_Copy16bitsBuffer(1, 1, 0);
@ -97,32 +61,29 @@ int main(int argc, char **argv) {
s8 ix = 1; s8 ix = 1;
s8 iy = 1; s8 iy = 1;
// Repite para siempre while (1)
while (1) { {
// Move ball
// Calcula el movimiento
x += ix; x += ix;
if ((x <= 0) || (x >= 191)) ix *= -1; if ((x <= 0) || (x >= 191))
ix *= -1;
y += iy; y += iy;
if ((y <= 0) || (y >= 127)) iy *= -1; if ((y <= 0) || (y >= 127))
iy *= -1;
// Redibuja la escena (Superior) // Redraw top screen
NF_Draw16bitsImage(0, 1, x, y, true); // Bola (con magenta como transparente) NF_Draw16bitsImage(0, 1, x, y, true); // Ball (magenta is transparent)
// Redibuja la escena (Inferior) // Redraw bottom screen
NF_Copy16bitsBuffer(1, 1, 0); // Fondo NF_Copy16bitsBuffer(1, 1, 0); // Background
NF_Draw16bitsImage(1, 1, x, y, true); // Bola (con magenta como transparente) NF_Draw16bitsImage(1, 1, x, y, true); // Ball (magenta is transparent)
// Sincronismo Vertical swiWaitForVBlank(); // Wait for the screen refresh
swiWaitForVBlank();
// Manda el backbuffer a la pantalla // Send backbuffer to the screen
NF_Flip16bitsBackBuffer(0); NF_Flip16bitsBackBuffer(0);
NF_Flip16bitsBackBuffer(1); NF_Flip16bitsBackBuffer(1);
} }
return 0; return 0;
} }

View File

@ -1,57 +1,21 @@
// 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
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Pantalla de espera inicializando NitroFS
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
consoleDemoInit(); consoleDemoInit();
@ -59,58 +23,54 @@ 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 2D // Inicialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas NF_Set2D(0, 0);
NF_Set2D(1, 0); 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); // Iniciliaza los fondos Tileados para la pantalla inferior NF_InitTiledBgSys(1); // Bottom screen
// Inicializa los Sprites // Initialize sprite backgrounds system
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_InitSpriteBuffers(); // Initialize storage buffers
NF_InitSpriteSys(0); // Inicializa los sprites para la pantalla superior NF_InitSpriteSys(0); // Top screen
NF_InitSpriteSys(1); // Inicializa los sprites para la pantalla inferior NF_InitSpriteSys(1); // Bottom screen
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM // Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla superior NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256); // Carga el fondo para la capa 3, pantalla inferior NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256);
NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256); // Carga el fondo para la capa 2, pantalla inferior NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256);
// Load sprite files from NitroFS
// Carga los archivos de sprites desde la FAT / NitroFS a la RAM NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64);
NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64); // Personaje
NF_LoadSpritePal("sprite/personaje", 0); NF_LoadSpritePal("sprite/personaje", 0);
NF_LoadSpriteGfx("sprite/bola", 1, 32, 32); // Bola azul NF_LoadSpriteGfx("sprite/bola", 1, 32, 32);
NF_LoadSpritePal("sprite/bola", 1); NF_LoadSpritePal("sprite/bola", 1);
// Create top screen background
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "nfl"); NF_CreateTiledBg(0, 3, "nfl");
// Crea los fondos de la pantalla inferior
// Create bottom screen backgrounds
NF_CreateTiledBg(1, 3, "capa_3"); NF_CreateTiledBg(1, 3, "capa_3");
NF_CreateTiledBg(1, 2, "capa_2"); NF_CreateTiledBg(1, 2, "capa_2");
// Transfer the required sprites to VRAM
// Transfiere a la VRAM los sprites necesarios NF_VramSpriteGfx(1, 0, 0, true); // Ball: Keep unused frames in RAM
NF_VramSpriteGfx(1, 0, 0, true); // Bola, manten los frames adicionales en RAM
NF_VramSpritePal(1, 0, 0); NF_VramSpritePal(1, 0, 0);
NF_VramSpriteGfx(0, 1, 0, false); // Personaje, copia todos los frames a la VRAM NF_VramSpriteGfx(0, 1, 0, false); // Character: Keep unused frames in VRAM
NF_VramSpritePal(0, 1, 0); NF_VramSpritePal(0, 1, 0);
// Set random seed based on the current time
// Variables generales y inicializacion del random
u8 n = 0;
srand(time(NULL)); srand(time(NULL));
// Crea el sprite del personaje en pantalla // Setup character sprite
s16 pj_x = 0; s16 pj_x = 0;
s16 pj_y = 127; s16 pj_y = 127;
u8 pj_frame = 0; u8 pj_frame = 0;
@ -118,65 +78,68 @@ int main(int argc, char **argv) {
s8 pj_speed = 1; s8 pj_speed = 1;
NF_CreateSprite(1, 0, 0, 0, pj_x, pj_y); NF_CreateSprite(1, 0, 0, 0, pj_x, pj_y);
// Crea las bolas en la pantalla superior // Setup ball sprites
s16 bola_x[32]; s16 bola_x[32];
s16 bola_y[32]; s16 bola_y[32];
s8 bola_spx[32]; s8 bola_spx[32];
s8 bola_spy[32]; s8 bola_spy[32];
for (n = 0; n < 32; n ++) {
bola_x[n] = (rand() % 223); for (int n = 0; n < 32; n ++)
bola_y[n] = (rand() % 159); {
bola_x[n] = rand() % 223;
bola_y[n] = rand() % 159;
bola_spx[n] = (rand() % 3) + 1; bola_spx[n] = (rand() % 3) + 1;
bola_spy[n] = (rand() % 3) + 1; bola_spy[n] = (rand() % 3) + 1;
NF_CreateSprite(0, n, 0, 0, bola_x[n], bola_y[n]); NF_CreateSprite(0, n, 0, 0, bola_x[n], bola_y[n]);
} }
while (1)
// Bucle (repite para siempre) {
while(1) { // Move character
// Mueve el personaje
pj_x += pj_speed; pj_x += pj_speed;
if ((pj_x < 0) || (pj_x > 191)) { if ((pj_x < 0) || (pj_x > 191))
{
pj_speed *= -1; pj_speed *= -1;
if (pj_speed > 0) { if (pj_speed > 0)
NF_HflipSprite(1, 0, false); NF_HflipSprite(1, 0, false);
} else { else
NF_HflipSprite(1, 0, true); NF_HflipSprite(1, 0, true);
} }
}
NF_MoveSprite(1, 0, pj_x, pj_y); NF_MoveSprite(1, 0, pj_x, pj_y);
// Animacion del personaje // Animate character
pj_anim ++; pj_anim ++;
if (pj_anim > 5) { if (pj_anim > 5)
{
pj_anim = 0; pj_anim = 0;
pj_frame ++; pj_frame ++;
if (pj_frame > 11) pj_frame = 0; if (pj_frame > 11)
pj_frame = 0;
NF_SpriteFrame(1, 0, pj_frame); NF_SpriteFrame(1, 0, pj_frame);
} }
// Mueve las bolas // Move balls
for (n = 0; n < 32; n ++) { for (int n = 0; n < 32; n ++)
{
bola_x[n] += bola_spx[n]; bola_x[n] += bola_spx[n];
if ((bola_x[n] < 0) || (bola_x[n] > 223)) bola_spx[n] *= -1; if ((bola_x[n] < 0) || (bola_x[n] > 223))
bola_spx[n] *= -1;
bola_y[n] += bola_spy[n]; bola_y[n] += bola_spy[n];
if ((bola_y[n] < 0) || (bola_y[n] > 159)) bola_spy[n] *= -1; if ((bola_y[n] < 0) || (bola_y[n] > 159))
bola_spy[n] *= -1;
NF_MoveSprite(0, n, bola_x[n], bola_y[n]); NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
} }
// Actualiza el array de OAM // Update OAM array
NF_SpriteOamSet(0); NF_SpriteOamSet(0);
NF_SpriteOamSet(1); NF_SpriteOamSet(1);
swiWaitForVBlank(); // Espera al sincronismo vertical swiWaitForVBlank(); // Wait for the screen refresh
// Actualiza el OAM // Update OAM
oamUpdate(&oamMain); oamUpdate(&oamMain);
oamUpdate(&oamSub); oamUpdate(&oamSub);
} }
return 0; return 0;
} }