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-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>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
#define SPEED 2 // Scroll speed
// Algunos defines interesantes
#define SPEED 2 // Velocidad del scroll
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 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);
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
// Create top screen background
NF_CreateTiledBg(0, 3, "nfl");
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
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();
// Variables
s16 bg_x[4] = { 0, 0, 0, 0 };
s16 bg_y[4] = { 0, 0, 0, 0 };
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
while (1)
{
scanKeys(); // Read keypad
uint16_t keys = keysHeld(); // Keys currently pressed
// Inicializa el motor 2D
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
NF_Set2D(1, 0);
// If pressing left
if (keys & KEY_LEFT)
{
bg_x[0] -= SPEED;
if (bg_x[0] < 0)
bg_x[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
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior
// If pressing right
if (keys & KEY_RIGHT)
{
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
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla superior
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
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
// Scroll other layers less than layer 0
bg_x[1] = (int)(bg_x[0] / 1.5);
bg_x[2] = (int)(bg_x[1] / 1.5);
swiWaitForVBlank(); // Wait for the screen refresh
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "nfl");
// Crea los fondos de la pantalla inferior
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;
// Update background scroll during vertical blanking to avoid tearing
for (int n = 0; n < 4; n ++)
NF_ScrollBg(1, n, bg_x[n], bg_y[n]);
}
return 0;
}

View File

@ -1,128 +1,89 @@
// SPDX-License-Identifier: CC0-1.0
//
// 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 <string.h>
#include <unistd.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#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);
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
// Initialize storage buffers
NF_Init16bitsBgBuffers();
int main(int argc, char **argv) {
// Initialize backbuffers
NF_Init16bitsBackBuffer(0);
NF_Init16bitsBackBuffer(1);
// Pantalla de espera inicializando NitroFS
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();
// Enable backbuffers
NF_Enable16bitsBackBuffer(0);
NF_Enable16bitsBackBuffer(1);
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Load bitmap files from NitroFS
NF_Load16bitsBg("bmp/bitmap16", 0);
NF_Load16bitsImage("bmp/blueball", 1, 64, 64);
// Inicializa el motor 2D en modo BITMAP
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas
NF_Set2D(1, 5);
// Load image to VRAM of both screens
NF_Copy16bitsBuffer(0, 1, 0);
NF_Copy16bitsBuffer(1, 1, 0);
// Inicializa los fondos en modo "BITMAP"
NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1);
// Variables
s16 x = 0;
s16 y = 0;
s8 ix = 1;
s8 iy = 1;
// Inicializa los buffers para guardar fondos en formato BITMAP
NF_Init16bitsBgBuffers();
while (1)
{
// Move ball
x += ix;
if ((x <= 0) || (x >= 191))
ix *= -1;
y += iy;
if ((y <= 0) || (y >= 127))
iy *= -1;
// Inicializa el backbuffer
NF_Init16bitsBackBuffer(0);
NF_Init16bitsBackBuffer(1);
// Redraw top screen
NF_Draw16bitsImage(0, 1, x, y, true); // Ball (magenta is transparent)
// Habilita el backbuffer
NF_Enable16bitsBackBuffer(0);
NF_Enable16bitsBackBuffer(1);
// Redraw bottom screen
NF_Copy16bitsBuffer(1, 1, 0); // Background
NF_Draw16bitsImage(1, 1, x, y, true); // Ball (magenta is transparent)
// Carga el archivo BITMAP de imagen en formato RAW a la RAM
NF_Load16bitsBg("bmp/bitmap16", 0);
NF_Load16bitsImage("bmp/blueball", 1, 64, 64);
swiWaitForVBlank(); // Wait for the screen refresh
// Tranfiere la imagen a la VRAM de ambas pantallas
NF_Copy16bitsBuffer(0, 1, 0);
NF_Copy16bitsBuffer(1, 1, 0);
// 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;
// Send backbuffer to the screen
NF_Flip16bitsBackBuffer(0);
NF_Flip16bitsBackBuffer(1);
}
return 0;
}

View File

@ -1,182 +1,145 @@
// SPDX-License-Identifier: CC0-1.0
//
// 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 <time.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#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
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
// Initialize sprite backgrounds system
NF_InitSpriteBuffers(); // Initialize storage buffers
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
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();
// Load sprite files from NitroFS
NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64);
NF_LoadSpritePal("sprite/personaje", 0);
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
NF_LoadSpriteGfx("sprite/bola", 1, 32, 32);
NF_LoadSpritePal("sprite/bola", 1);
// Inicializa el motor 2D
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
NF_Set2D(1, 0);
// Create top screen background
NF_CreateTiledBg(0, 3, "nfl");
// 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); // Iniciliaza los fondos Tileados para la pantalla inferior
// Create bottom screen backgrounds
NF_CreateTiledBg(1, 3, "capa_3");
NF_CreateTiledBg(1, 2, "capa_2");
// Inicializa los Sprites
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas
NF_InitSpriteSys(0); // Inicializa los sprites para la pantalla superior
NF_InitSpriteSys(1); // Inicializa los sprites para la pantalla inferior
// Transfer the required sprites to VRAM
NF_VramSpriteGfx(1, 0, 0, true); // Ball: Keep unused frames in RAM
NF_VramSpritePal(1, 0, 0);
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla superior
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
NF_VramSpriteGfx(0, 1, 0, false); // Character: Keep unused frames in VRAM
NF_VramSpritePal(0, 1, 0);
// Set random seed based on the current time
srand(time(NULL));
// Carga los archivos de sprites desde la FAT / NitroFS a la RAM
NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64); // Personaje
NF_LoadSpritePal("sprite/personaje", 0);
// Setup character sprite
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);
NF_LoadSpriteGfx("sprite/bola", 1, 32, 32); // Bola azul
NF_LoadSpritePal("sprite/bola", 1);
// Setup ball sprites
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
NF_CreateTiledBg(0, 3, "nfl");
// Crea los fondos de la pantalla inferior
NF_CreateTiledBg(1, 3, "capa_3");
NF_CreateTiledBg(1, 2, "capa_2");
while (1)
{
// Move character
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);
// 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
NF_VramSpriteGfx(1, 0, 0, true); // Bola, manten los frames adicionales en RAM
NF_VramSpritePal(1, 0, 0);
// Move balls
for (int 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]);
}
NF_VramSpriteGfx(0, 1, 0, false); // Personaje, copia todos los frames a la VRAM
NF_VramSpritePal(0, 1, 0);
// Update OAM array
NF_SpriteOamSet(0);
NF_SpriteOamSet(1);
swiWaitForVBlank(); // Wait for the screen refresh
// Variables generales y inicializacion del random
u8 n = 0;
srand(time(NULL));
// 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;
// Update OAM
oamUpdate(&oamMain);
oamUpdate(&oamSub);
}
return 0;
}