mirror of
https://github.com/knightfox75/nds_nflib.git
synced 2025-06-19 01:05:34 -04:00
examples: Cleanup and translate 3dprites/alpha to English
This commit is contained in:
parent
a097eb3762
commit
25511c82dd
@ -1,58 +1,23 @@
|
|||||||
// 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
|
||||||
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,113 +25,113 @@ 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");
|
||||||
consoleClear();
|
consoleClear();
|
||||||
|
|
||||||
// Inicializa el motor 3D
|
// Initialize 3D engine in the top screen in mode 0
|
||||||
NF_Set3D(1, 0); // Modo 3D_0 en la pantalla superior
|
NF_Set3D(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
|
||||||
|
|
||||||
// Inicializa los buffers de los Sprites
|
// Initialize 3D sprite system
|
||||||
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas
|
NF_InitSpriteBuffers(); // Initialize storage buffers
|
||||||
|
|
||||||
// Inicializa el sistema de Sprites en 3D y OpenGL
|
|
||||||
NF_Init3dSpriteSys();
|
NF_Init3dSpriteSys();
|
||||||
|
|
||||||
// Carga los fondos tileados
|
// Load background files from NitroFS
|
||||||
NF_LoadTiledBg("bg/nature", "bg3", 256, 256);
|
NF_LoadTiledBg("bg/nature", "bg3", 256, 256);
|
||||||
|
|
||||||
// Carga los graficos de los Sprites
|
// Load sprite files from NitroFS
|
||||||
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
|
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
|
||||||
NF_LoadSpritePal("sprite/blueball", 0);
|
NF_LoadSpritePal("sprite/blueball", 0);
|
||||||
|
|
||||||
// Manda los graficos y paletas a la VRAM
|
// Transfer the required sprites to VRAM
|
||||||
NF_Vram3dSpriteGfx(0, 0, true);
|
NF_Vram3dSpriteGfx(0, 0, true);
|
||||||
NF_Vram3dSpritePal(0, 0);
|
NF_Vram3dSpritePal(0, 0);
|
||||||
|
|
||||||
// Crea los fondos en ambas pantallas
|
// Create background
|
||||||
NF_CreateTiledBg(0, 3, "bg3");
|
NF_CreateTiledBg(0, 3, "bg3");
|
||||||
|
|
||||||
// Habilita el ALPHA de los Sprites 3D sobre fondos 2D
|
// 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);
|
REG_BLDCNT = BLEND_ALPHA | BLEND_SRC_BG0 | BLEND_DST_BG1 | BLEND_DST_BG2 | BLEND_DST_BG3;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
u16 n = 0;
|
|
||||||
s16 x[MAXSPRITES];
|
s16 x[MAXSPRITES];
|
||||||
s16 y[MAXSPRITES];
|
s16 y[MAXSPRITES];
|
||||||
s16 ix = 4;
|
s16 ix = 4;
|
||||||
s16 iy = 4;
|
s16 iy = 4;
|
||||||
|
|
||||||
// Inicializa las variables
|
// Create sprites
|
||||||
for (n = 0; n < MAXSPRITES; n ++) {
|
for (int n = 0; n < MAXSPRITES; n ++)
|
||||||
x[n] = (128 - 32);
|
{
|
||||||
y[n] = (96 - 32);
|
x[n] = 128 - 32;
|
||||||
// Crea los Sprites 3D
|
y[n] = 96 - 32;
|
||||||
|
|
||||||
NF_Create3dSprite(n, 0, 0, x[n], y[n]);
|
NF_Create3dSprite(n, 0, 0, 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();
|
NF_Sort3dSprites();
|
||||||
|
|
||||||
// Variable para la lectura del teclado
|
while (1)
|
||||||
u16 held = 0;
|
{
|
||||||
|
// Read keys and touchscreen
|
||||||
// Variables para la lectura del touchpad
|
|
||||||
touchPosition touchscreen;
|
|
||||||
|
|
||||||
// Bucle (repite para siempre)
|
|
||||||
while(1) {
|
|
||||||
|
|
||||||
// Lee el teclado
|
|
||||||
scanKeys();
|
scanKeys();
|
||||||
held = keysHeld();
|
touchPosition touchscreen;
|
||||||
|
|
||||||
// Lee el TOUCHPAD via Libnds
|
|
||||||
touchRead(&touchscreen);
|
touchRead(&touchscreen);
|
||||||
|
u16 keys = keysHeld(); // Keys currently pressed
|
||||||
|
|
||||||
// Mueve todos los Sprites
|
// Move sprites that follow the main one
|
||||||
for (n = (MAXSPRITES - 1); n > 0; n --) {
|
for (int n = MAXSPRITES - 1; n > 0; n --)
|
||||||
// Calcula la estela del movimiento
|
{
|
||||||
x[n] = x[(n - 1)];
|
x[n] = x[n - 1];
|
||||||
y[n] = y[(n - 1)];
|
y[n] = y[n - 1];
|
||||||
// Calcula el blending
|
|
||||||
NF_Blend3dSprite(n, (n + 1), (31 - (n << 2)));
|
NF_Blend3dSprite(n, n + 1, 31 - (n << 2));
|
||||||
// Mueve el sprite
|
|
||||||
NF_Move3dSprite(n, x[n], y[n]);
|
NF_Move3dSprite(n, x[n], y[n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mueve el Sprite principal
|
// Move the main sprite
|
||||||
if (held & KEY_TOUCH) {
|
if (keys & KEY_TOUCH)
|
||||||
x[0] = (touchscreen.px - 32);
|
{
|
||||||
y[0] = (touchscreen.py - 32);
|
x[0] = touchscreen.px - 32;
|
||||||
if (x[0] < 8) x[0] = 8;
|
y[0] = touchscreen.py - 32;
|
||||||
if (x[0] > 183) x[0] = 183;
|
|
||||||
if (y[0] < 8) y[0] = 8;
|
if (x[0] < 8)
|
||||||
if (y[0] > 119) y[0] = 119;
|
x[0] = 8;
|
||||||
} else {
|
if (x[0] > 183)
|
||||||
x[0] += ix;
|
x[0] = 183;
|
||||||
if ((x[0] < 8) || (x[0] > 183)) ix = -ix;
|
|
||||||
y[0] += iy;
|
if (y[0] < 8)
|
||||||
if ((y[0] < 8) || (y[0] > 119)) iy = -iy;
|
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]);
|
NF_Move3dSprite(0, x[0], y[0]);
|
||||||
|
|
||||||
// Dibuja los 3D Sprites
|
// Draw all 3D sprites
|
||||||
NF_Draw3dSprites();
|
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);
|
glFlush(0);
|
||||||
|
|
||||||
// Espera al sincronismo vertical
|
// Wait for the screen refresh
|
||||||
swiWaitForVBlank();
|
swiWaitForVBlank();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user