examples: Cleanup and translate 3dprites/alpha to English

This commit is contained in:
Antonio Niño Díaz 2023-05-20 12:44:11 +01:00
parent a097eb3762
commit 25511c82dd
2 changed files with 99 additions and 134 deletions

View File

@ -1,172 +1,137 @@
// 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 using transparency with 3D sprites.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de 3D Sprites
Transparencias (Alpha Blending)
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)
{
// 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);
Main() - Bloque general del programa NF_SetRootFolder("NITROFS");
------------------------------------------------- consoleClear();
*/
int main(int argc, char **argv) { // Initialize 3D engine in the top screen in mode 0
NF_Set3D(1, 0);
// Pantalla de espera inicializando NitroFS // Initialize tiled backgrounds system
NF_Set2D(0, 0); NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_Set2D(1, 0); NF_InitTiledBgSys(0); // Top screen
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos // Initialize 3D sprite system
nitroFSInit(NULL); NF_InitSpriteBuffers(); // Initialize storage buffers
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS NF_Init3dSpriteSys();
consoleClear();
// Inicializa el motor 3D // Load background files from NitroFS
NF_Set3D(1, 0); // Modo 3D_0 en la pantalla superior NF_LoadTiledBg("bg/nature", "bg3", 256, 256);
// Inicializa los fondos tileados // Load sprite files from NitroFS
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior NF_LoadSpritePal("sprite/blueball", 0);
// Inicializa los buffers de los Sprites // Transfer the required sprites to VRAM
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_Vram3dSpriteGfx(0, 0, true);
NF_Vram3dSpritePal(0, 0);
// Inicializa el sistema de Sprites en 3D y OpenGL // Create background
NF_Init3dSpriteSys(); NF_CreateTiledBg(0, 3, "bg3");
// Carga los fondos tileados // Enable alpha blending between 3D sprites over 3D backgrounds
NF_LoadTiledBg("bg/nature", "bg3", 256, 256); REG_BLDCNT = BLEND_ALPHA | BLEND_SRC_BG0 | BLEND_DST_BG1 | BLEND_DST_BG2 | BLEND_DST_BG3;
// Carga los graficos de los Sprites // Variables
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64); s16 x[MAXSPRITES];
NF_LoadSpritePal("sprite/blueball", 0); s16 y[MAXSPRITES];
s16 ix = 4;
s16 iy = 4;
// Manda los graficos y paletas a la VRAM // Create sprites
NF_Vram3dSpriteGfx(0, 0, true); for (int n = 0; n < MAXSPRITES; n ++)
NF_Vram3dSpritePal(0, 0); {
x[n] = 128 - 32;
y[n] = 96 - 32;
// Crea los fondos en ambas pantallas NF_Create3dSprite(n, 0, 0, x[n], y[n]);
NF_CreateTiledBg(0, 3, "bg3"); }
// Habilita el ALPHA de los Sprites 3D sobre fondos 2D // Sort their priorites based on their IDs (lower IDs have higher priority)
REG_BLDCNT = BLEND_ALPHA | BLEND_SRC_BG0 | (BLEND_DST_BG1 + BLEND_DST_BG2 + BLEND_DST_BG3); NF_Sort3dSprites();
// Variables while (1)
u16 n = 0; {
s16 x[MAXSPRITES]; // Read keys and touchscreen
s16 y[MAXSPRITES]; scanKeys();
s16 ix = 4; touchPosition touchscreen;
s16 iy = 4; touchRead(&touchscreen);
u16 keys = keysHeld(); // Keys currently pressed
// Inicializa las variables // Move sprites that follow the main one
for (n = 0; n < MAXSPRITES; n ++) { for (int n = MAXSPRITES - 1; n > 0; n --)
x[n] = (128 - 32); {
y[n] = (96 - 32); x[n] = x[n - 1];
// Crea los Sprites 3D y[n] = y[n - 1];
NF_Create3dSprite(n, 0, 0, x[n], y[n]);
}
// Y ordenalos en la cola segun su ID (El mas bajo tiene prioridad) NF_Blend3dSprite(n, n + 1, 31 - (n << 2));
NF_Sort3dSprites(); NF_Move3dSprite(n, x[n], y[n]);
}
// Variable para la lectura del teclado // Move the main sprite
u16 held = 0; if (keys & KEY_TOUCH)
{
x[0] = touchscreen.px - 32;
y[0] = touchscreen.py - 32;
// Variables para la lectura del touchpad if (x[0] < 8)
touchPosition touchscreen; x[0] = 8;
if (x[0] > 183)
x[0] = 183;
// Bucle (repite para siempre) if (y[0] < 8)
while(1) { y[0] = 8;
if (y[0] > 119)
y[0] = 119;
}
else
{
x[0] += ix;
if ((x[0] < 8) || (x[0] > 183))
ix = -ix;
// Lee el teclado y[0] += iy;
scanKeys(); if ((y[0] < 8) || (y[0] > 119))
held = keysHeld(); iy = -iy;
}
// Lee el TOUCHPAD via Libnds NF_Move3dSprite(0, x[0], y[0]);
touchRead(&touchscreen);
// Mueve todos los Sprites // Draw all 3D sprites
for (n = (MAXSPRITES - 1); n > 0; n --) { NF_Draw3dSprites();
// Calcula la estela del movimiento
x[n] = x[(n - 1)];
y[n] = y[(n - 1)];
// Calcula el blending
NF_Blend3dSprite(n, (n + 1), (31 - (n << 2)));
// Mueve el sprite
NF_Move3dSprite(n, x[n], y[n]);
}
// Mueve el Sprite principal // Tell the GPU to draw the scene and wait until it's done
if (held & KEY_TOUCH) { glFlush(0);
x[0] = (touchscreen.px - 32);
y[0] = (touchscreen.py - 32);
if (x[0] < 8) x[0] = 8;
if (x[0] > 183) x[0] = 183;
if (y[0] < 8) y[0] = 8;
if (y[0] > 119) y[0] = 119;
} else {
x[0] += ix;
if ((x[0] < 8) || (x[0] > 183)) ix = -ix;
y[0] += iy;
if ((y[0] < 8) || (y[0] > 119)) iy = -iy;
}
NF_Move3dSprite(0, x[0], y[0]);
// Dibuja los 3D Sprites // Wait for the screen refresh
NF_Draw3dSprites(); swiWaitForVBlank();
}
// Actualiza la escena 3D, si no lo haces, no se mostrara en pantalla
glFlush(0);
// Espera al sincronismo vertical
swiWaitForVBlank();
}
return 0;
return 0;
} }

View File

@ -32,10 +32,10 @@ int main(int argc, char **argv)
nitroFSInit(NULL); nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); NF_SetRootFolder("NITROFS");
// Initialize 3D engine in bottom screens in mode 0 // Initialize 3D engine in the top screen in mode 0
NF_Set3D(0, 0); NF_Set3D(0, 0);
// Initialize 2D engine in bottom screens in mode 0 // Initialize 2D engine in the bottom screen in mode 0
NF_Set2D(1, 0); NF_Set2D(1, 0);
// Initialize tiled backgrounds system // Initialize tiled backgrounds system