mirror of
https://github.com/knightfox75/nds_nflib.git
synced 2025-06-18 16:55:32 -04:00
examples: Cleanup and translate 3dprites/alpha to English
This commit is contained in:
parent
a097eb3762
commit
25511c82dd
@ -1,172 +1,137 @@
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
//
|
||||
// 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 <time.h>
|
||||
|
||||
// Includes propietarios NDS
|
||||
#include <nds.h>
|
||||
#include <filesystem.h>
|
||||
|
||||
// Includes librerias propias
|
||||
#include <nf_lib.h>
|
||||
|
||||
|
||||
#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();
|
||||
|
||||
/*
|
||||
-------------------------------------------------
|
||||
Main() - Bloque general del programa
|
||||
-------------------------------------------------
|
||||
*/
|
||||
// Initialize NitroFS and set it as the root folder of the filesystem
|
||||
nitroFSInit(NULL);
|
||||
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
|
||||
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 tiled backgrounds system
|
||||
NF_InitTiledBgBuffers(); // Initialize storage buffers
|
||||
NF_InitTiledBgSys(0); // Top screen
|
||||
|
||||
// Define el ROOT e inicializa el sistema de archivos
|
||||
nitroFSInit(NULL);
|
||||
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
|
||||
consoleClear();
|
||||
// Initialize 3D sprite system
|
||||
NF_InitSpriteBuffers(); // Initialize storage buffers
|
||||
NF_Init3dSpriteSys();
|
||||
|
||||
// Inicializa el motor 3D
|
||||
NF_Set3D(1, 0); // Modo 3D_0 en la pantalla superior
|
||||
// Load background files from NitroFS
|
||||
NF_LoadTiledBg("bg/nature", "bg3", 256, 256);
|
||||
|
||||
// Inicializa los fondos tileados
|
||||
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
|
||||
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
|
||||
// Load sprite files from NitroFS
|
||||
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
|
||||
NF_LoadSpritePal("sprite/blueball", 0);
|
||||
|
||||
// Inicializa los buffers de los Sprites
|
||||
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas
|
||||
// Transfer the required sprites to VRAM
|
||||
NF_Vram3dSpriteGfx(0, 0, true);
|
||||
NF_Vram3dSpritePal(0, 0);
|
||||
|
||||
// Inicializa el sistema de Sprites en 3D y OpenGL
|
||||
NF_Init3dSpriteSys();
|
||||
// Create background
|
||||
NF_CreateTiledBg(0, 3, "bg3");
|
||||
|
||||
// Carga los fondos tileados
|
||||
NF_LoadTiledBg("bg/nature", "bg3", 256, 256);
|
||||
// Enable alpha blending between 3D sprites over 3D backgrounds
|
||||
REG_BLDCNT = BLEND_ALPHA | BLEND_SRC_BG0 | BLEND_DST_BG1 | BLEND_DST_BG2 | BLEND_DST_BG3;
|
||||
|
||||
// Carga los graficos de los Sprites
|
||||
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
|
||||
NF_LoadSpritePal("sprite/blueball", 0);
|
||||
// Variables
|
||||
s16 x[MAXSPRITES];
|
||||
s16 y[MAXSPRITES];
|
||||
s16 ix = 4;
|
||||
s16 iy = 4;
|
||||
|
||||
// Manda los graficos y paletas a la VRAM
|
||||
NF_Vram3dSpriteGfx(0, 0, true);
|
||||
NF_Vram3dSpritePal(0, 0);
|
||||
// Create sprites
|
||||
for (int n = 0; n < MAXSPRITES; n ++)
|
||||
{
|
||||
x[n] = 128 - 32;
|
||||
y[n] = 96 - 32;
|
||||
|
||||
// Crea los fondos en ambas pantallas
|
||||
NF_CreateTiledBg(0, 3, "bg3");
|
||||
NF_Create3dSprite(n, 0, 0, x[n], y[n]);
|
||||
}
|
||||
|
||||
// Habilita el ALPHA de los Sprites 3D sobre fondos 2D
|
||||
REG_BLDCNT = BLEND_ALPHA | BLEND_SRC_BG0 | (BLEND_DST_BG1 + BLEND_DST_BG2 + BLEND_DST_BG3);
|
||||
// Sort their priorites based on their IDs (lower IDs have higher priority)
|
||||
NF_Sort3dSprites();
|
||||
|
||||
// Variables
|
||||
u16 n = 0;
|
||||
s16 x[MAXSPRITES];
|
||||
s16 y[MAXSPRITES];
|
||||
s16 ix = 4;
|
||||
s16 iy = 4;
|
||||
while (1)
|
||||
{
|
||||
// Read keys and touchscreen
|
||||
scanKeys();
|
||||
touchPosition touchscreen;
|
||||
touchRead(&touchscreen);
|
||||
u16 keys = keysHeld(); // Keys currently pressed
|
||||
|
||||
// Inicializa las variables
|
||||
for (n = 0; n < MAXSPRITES; n ++) {
|
||||
x[n] = (128 - 32);
|
||||
y[n] = (96 - 32);
|
||||
// Crea los Sprites 3D
|
||||
NF_Create3dSprite(n, 0, 0, x[n], y[n]);
|
||||
}
|
||||
// Move sprites that follow the main one
|
||||
for (int n = MAXSPRITES - 1; n > 0; n --)
|
||||
{
|
||||
x[n] = x[n - 1];
|
||||
y[n] = y[n - 1];
|
||||
|
||||
// Y ordenalos en la cola segun su ID (El mas bajo tiene prioridad)
|
||||
NF_Sort3dSprites();
|
||||
NF_Blend3dSprite(n, n + 1, 31 - (n << 2));
|
||||
NF_Move3dSprite(n, x[n], y[n]);
|
||||
}
|
||||
|
||||
// Variable para la lectura del teclado
|
||||
u16 held = 0;
|
||||
// Move the main sprite
|
||||
if (keys & KEY_TOUCH)
|
||||
{
|
||||
x[0] = touchscreen.px - 32;
|
||||
y[0] = touchscreen.py - 32;
|
||||
|
||||
// Variables para la lectura del touchpad
|
||||
touchPosition touchscreen;
|
||||
if (x[0] < 8)
|
||||
x[0] = 8;
|
||||
if (x[0] > 183)
|
||||
x[0] = 183;
|
||||
|
||||
// Bucle (repite para siempre)
|
||||
while(1) {
|
||||
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;
|
||||
|
||||
// Lee el teclado
|
||||
scanKeys();
|
||||
held = keysHeld();
|
||||
y[0] += iy;
|
||||
if ((y[0] < 8) || (y[0] > 119))
|
||||
iy = -iy;
|
||||
}
|
||||
|
||||
// Lee el TOUCHPAD via Libnds
|
||||
touchRead(&touchscreen);
|
||||
NF_Move3dSprite(0, x[0], y[0]);
|
||||
|
||||
// Mueve todos los Sprites
|
||||
for (n = (MAXSPRITES - 1); n > 0; n --) {
|
||||
// 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]);
|
||||
}
|
||||
// Draw all 3D sprites
|
||||
NF_Draw3dSprites();
|
||||
|
||||
// Mueve el Sprite principal
|
||||
if (held & KEY_TOUCH) {
|
||||
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]);
|
||||
// Tell the GPU to draw the scene and wait until it's done
|
||||
glFlush(0);
|
||||
|
||||
// Dibuja los 3D Sprites
|
||||
NF_Draw3dSprites();
|
||||
|
||||
// Actualiza la escena 3D, si no lo haces, no se mostrara en pantalla
|
||||
glFlush(0);
|
||||
|
||||
// Espera al sincronismo vertical
|
||||
swiWaitForVBlank();
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
// Wait for the screen refresh
|
||||
swiWaitForVBlank();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,10 +32,10 @@ int main(int argc, char **argv)
|
||||
nitroFSInit(NULL);
|
||||
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);
|
||||
|
||||
// Initialize 2D engine in bottom screens in mode 0
|
||||
// Initialize 2D engine in the bottom screen in mode 0
|
||||
NF_Set2D(1, 0);
|
||||
|
||||
// Initialize tiled backgrounds system
|
||||
|
Loading…
Reference in New Issue
Block a user