mirror of
https://github.com/knightfox75/nds_nflib.git
synced 2025-06-18 16:55:32 -04:00
examples: Cleanup and translate more examples to English
This commit is contained in:
parent
eb91123a9a
commit
c6d6883caf
@ -30,7 +30,7 @@ int main(int argc, char **argv)
|
||||
NF_SetRootFolder("NITROFS");
|
||||
consoleClear();
|
||||
|
||||
// Initialize 3D engine in the top screen in mode 0
|
||||
// Initialize 3D engine in the bottom screen in mode 0
|
||||
NF_Set3D(1, 0);
|
||||
|
||||
// Initialize tiled backgrounds system
|
||||
@ -66,7 +66,7 @@ int main(int argc, char **argv)
|
||||
s16 ix = 4;
|
||||
s16 iy = 4;
|
||||
|
||||
// Create sprites
|
||||
// Initialize sprite variables and create the sprites
|
||||
for (int n = 0; n < MAXSPRITES; n ++)
|
||||
{
|
||||
x[n] = 128 - 32;
|
||||
|
@ -1,179 +1,143 @@
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
//
|
||||
// SPDX-FileContributor: NightFox & Co., 2009-2011
|
||||
//
|
||||
// 3D animated sprite example
|
||||
// http://www.nightfoxandco.com
|
||||
|
||||
/*
|
||||
-------------------------------------------------
|
||||
|
||||
NightFox's Lib Template
|
||||
Ejemplo de 3D Sprites animados
|
||||
|
||||
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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
-------------------------------------------------
|
||||
Main() - Bloque general del programa
|
||||
-------------------------------------------------
|
||||
*/
|
||||
|
||||
#define SPRITEMAXNUM 255
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Set random seed based on the current time
|
||||
srand(time(NULL));
|
||||
|
||||
// Inicializa el random
|
||||
srand(time(NULL));
|
||||
// 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();
|
||||
|
||||
// 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 NitroFS and set it as the root folder of the filesystem
|
||||
nitroFSInit(NULL);
|
||||
NF_SetRootFolder("NITROFS");
|
||||
|
||||
// Define el ROOT e inicializa el sistema de archivos
|
||||
nitroFSInit(NULL);
|
||||
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
|
||||
// Initialize 3D engine in the top screen in mode 0
|
||||
NF_Set3D(0, 0);
|
||||
|
||||
// Inicializa el motor 3D
|
||||
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior
|
||||
// Initialize 2D engine in the bottom
|
||||
NF_Set2D(1, 0);
|
||||
|
||||
// Inicializa el motor 2D
|
||||
NF_Set2D(1, 0); // Modo 2D_0 en la pantalla inferior
|
||||
// Initialize tiled backgrounds system
|
||||
NF_InitTiledBgBuffers(); // Initialize storage buffers
|
||||
NF_InitTiledBgSys(0); // Top screen
|
||||
NF_InitTiledBgSys(1); // Bottom screen
|
||||
|
||||
// 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); // Inicializa los fondos Tileados para la pantalla inferior
|
||||
// Initialize 3D sprite system
|
||||
NF_InitSpriteBuffers(); // Initialize storage buffers
|
||||
NF_Init3dSpriteSys();
|
||||
|
||||
// Inicializa los buffers de los Sprites
|
||||
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas
|
||||
// Load background files from NitroFS
|
||||
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
|
||||
NF_LoadTiledBg("bg/bg3", "bg3", 256, 256);
|
||||
|
||||
// Inicializa el sistema de Sprites en 3D y OpenGL
|
||||
NF_Init3dSpriteSys();
|
||||
// Load sprite files from NitroFS
|
||||
for (int n = 0; n < SPRITEMAXNUM; n ++)
|
||||
NF_LoadSpriteGfx("sprite/numbers", n, 16, 16);
|
||||
|
||||
// Carga los fondos tileados
|
||||
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
|
||||
NF_LoadTiledBg("bg/bg3", "bg3", 256, 256);
|
||||
NF_LoadSpritePal("sprite/numbers", 0);
|
||||
|
||||
// Carga los graficos de los Sprites
|
||||
u8 n = 0;
|
||||
for (n = 0; n < SPRITEMAXNUM; n ++) {
|
||||
NF_LoadSpriteGfx("sprite/numbers", n, 16, 16);
|
||||
}
|
||||
NF_LoadSpritePal("sprite/numbers", 0);
|
||||
// Transfer the required sprites to VRAM
|
||||
for (int n = 0; n < SPRITEMAXNUM; n ++)
|
||||
NF_Vram3dSpriteGfx(n, n, true);
|
||||
|
||||
NF_Vram3dSpritePal(0, 0);
|
||||
|
||||
// Manda los graficos y paletas a la VRAM
|
||||
for (n = 0; n < SPRITEMAXNUM; n ++) {
|
||||
NF_Vram3dSpriteGfx(n, n, true);
|
||||
}
|
||||
NF_Vram3dSpritePal(0, 0);
|
||||
// Create backgrounds in both screens
|
||||
NF_CreateTiledBg(0, 3, "bg3");
|
||||
NF_CreateTiledBg(1, 3, "nfl");
|
||||
|
||||
// Crea los fondos en ambas pantallas
|
||||
NF_CreateTiledBg(0, 3, "bg3");
|
||||
NF_CreateTiledBg(1, 3, "nfl");
|
||||
// Variables
|
||||
s16 x[SPRITEMAXNUM];
|
||||
s16 y[SPRITEMAXNUM];
|
||||
s8 ix[SPRITEMAXNUM];
|
||||
s8 iy[SPRITEMAXNUM];
|
||||
u16 timer[SPRITEMAXNUM];
|
||||
u8 frame[SPRITEMAXNUM];
|
||||
|
||||
// Initialize sprite variables and create the sprites
|
||||
for (int n = 0; n < SPRITEMAXNUM; n++)
|
||||
{
|
||||
x[n] = rand() % 239;
|
||||
y[n] = rand() % 175;
|
||||
timer[n] = rand() % 20;
|
||||
frame[n] = rand() % 10;
|
||||
|
||||
// Variables
|
||||
s16 x[SPRITEMAXNUM];
|
||||
s16 y[SPRITEMAXNUM];
|
||||
s8 ix[SPRITEMAXNUM];
|
||||
s8 iy[SPRITEMAXNUM];
|
||||
u16 timer[SPRITEMAXNUM];
|
||||
u8 frame[SPRITEMAXNUM];
|
||||
if ((rand() % 100) > 50)
|
||||
ix[n] = 1;
|
||||
else
|
||||
ix[n] = -1;
|
||||
|
||||
// Inicializa las variables
|
||||
for (n = 0; n < SPRITEMAXNUM; n ++) {
|
||||
x[n] = (((int)(rand() % 239)));
|
||||
y[n] = (((int)(rand() % 175)));
|
||||
timer[n] = (((int)(rand() % 20)));
|
||||
frame[n] = (((int)(rand() % 10)));
|
||||
if ((rand() % 100) > 50) {
|
||||
ix[n] = 1;
|
||||
} else {
|
||||
ix[n] = -1;
|
||||
}
|
||||
if ((rand() % 100) > 50) {
|
||||
iy[n] = 1;
|
||||
} else {
|
||||
iy[n] = -1;
|
||||
}
|
||||
// Crea los Sprites 3D
|
||||
NF_Create3dSprite(n, n, 0, x[n], y[n]);
|
||||
NF_Set3dSpriteFrame(n, frame[n]);
|
||||
}
|
||||
if ((rand() % 100) > 50)
|
||||
iy[n] = 1;
|
||||
else
|
||||
iy[n] = -1;
|
||||
|
||||
// Y ordenalos en la cola segun su ID (El mas bajo tiene prioridad)
|
||||
NF_Sort3dSprites();
|
||||
NF_Create3dSprite(n, n, 0, x[n], y[n]);
|
||||
NF_Set3dSpriteFrame(n, frame[n]);
|
||||
}
|
||||
|
||||
// Bucle (repite para siempre)
|
||||
while(1) {
|
||||
// Sort their priorites based on their IDs (lower IDs have higher priority)
|
||||
NF_Sort3dSprites();
|
||||
|
||||
// Mueve todos los Sprites
|
||||
for (n = 0; n < SPRITEMAXNUM; n ++) {
|
||||
x[n] += ix[n];
|
||||
if ((x[n] < 0) || (x[n] > (255 - NF_3DSPRITE[n].width))) ix[n] = -ix[n];
|
||||
y[n] += iy[n];
|
||||
if ((y[n] < 0) || (y[n] > (191 - NF_3DSPRITE[n].height))) iy[n] = -iy[n];
|
||||
timer[n] ++;
|
||||
if (timer[n] > 19) {
|
||||
timer[n] = 0;
|
||||
frame[n] ++;
|
||||
if (frame[n] > 9) frame[n] = 0;
|
||||
}
|
||||
NF_Move3dSprite(n, x[n], y[n]);
|
||||
NF_Set3dSpriteFrame(n, frame[n]);
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
// Move sprites
|
||||
for (int n = 0; n < SPRITEMAXNUM; n ++)
|
||||
{
|
||||
x[n] += ix[n];
|
||||
if ((x[n] < 0) || (x[n] > (255 - NF_3DSPRITE[n].width)))
|
||||
ix[n] = -ix[n];
|
||||
|
||||
// Dibuja los 3D Sprites
|
||||
NF_Draw3dSprites();
|
||||
y[n] += iy[n];
|
||||
if ((y[n] < 0) || (y[n] > (191 - NF_3DSPRITE[n].height)))
|
||||
iy[n] = -iy[n];
|
||||
|
||||
// Actualiza la escena 3D, si no lo haces, no se mostrara en pantalla
|
||||
glFlush(0);
|
||||
timer[n] ++;
|
||||
if (timer[n] > 19)
|
||||
{
|
||||
timer[n] = 0;
|
||||
frame[n]++;
|
||||
if (frame[n] > 9)
|
||||
frame[n] = 0;
|
||||
}
|
||||
|
||||
// Espera al sincronismo vertical
|
||||
swiWaitForVBlank();
|
||||
NF_Move3dSprite(n, x[n], y[n]);
|
||||
NF_Set3dSpriteFrame(n, frame[n]);
|
||||
}
|
||||
|
||||
// Actualiza las texturas de los 3D Sprites animados con KEEPFRAMES == TRUE
|
||||
NF_Update3dSpritesGfx();
|
||||
// Draw all 3D sprites
|
||||
NF_Draw3dSprites();
|
||||
|
||||
// Tell the GPU to draw the scene and wait until it's done
|
||||
glFlush(0);
|
||||
|
||||
}
|
||||
// Wait for the screen refresh
|
||||
swiWaitForVBlank();
|
||||
|
||||
return 0;
|
||||
// Update textures of any 3D sprite with "keepframes == true"
|
||||
NF_Update3dSpritesGfx();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,183 +1,143 @@
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
//
|
||||
// SPDX-FileContributor: NightFox & Co., 2009-2011
|
||||
//
|
||||
// Basic 3D sprite example.
|
||||
// http://www.nightfoxandco.com
|
||||
|
||||
/*
|
||||
-------------------------------------------------
|
||||
|
||||
NightFox's Lib Template
|
||||
Ejemplo de 3D 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>
|
||||
|
||||
|
||||
#define MAXSPRITES 32
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Set random seed based on the current time
|
||||
srand(time(NULL));
|
||||
|
||||
/*
|
||||
-------------------------------------------------
|
||||
Main() - Bloque general del programa
|
||||
-------------------------------------------------
|
||||
*/
|
||||
// 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();
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Initialize NitroFS and set it as the root folder of the filesystem
|
||||
nitroFSInit(NULL);
|
||||
NF_SetRootFolder("NITROFS");
|
||||
|
||||
// Inicializa el random
|
||||
srand(time(NULL));
|
||||
// Initialize 3D engine in the top screen in mode 0
|
||||
NF_Set3D(0, 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 2D engine in the bottom screen in mode 0
|
||||
NF_Set2D(1, 0);
|
||||
|
||||
// Define el ROOT e inicializa el sistema de archivos
|
||||
nitroFSInit(NULL);
|
||||
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
|
||||
// Initialize tiled backgrounds system
|
||||
NF_InitTiledBgBuffers(); // Initialize storage buffers
|
||||
NF_InitTiledBgSys(0); // Top screen
|
||||
NF_InitTiledBgSys(1); // Bottom screen
|
||||
|
||||
// Inicializa el motor 3D
|
||||
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior
|
||||
// Initialize 3D sprite system
|
||||
NF_InitSpriteBuffers(); // Initialize storage buffers
|
||||
NF_Init3dSpriteSys();
|
||||
|
||||
// Inicializa el motor 2D
|
||||
NF_Set2D(1, 0); // Modo 2D_0 en la pantalla inferior
|
||||
// Load background files from NitroFS
|
||||
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
|
||||
NF_LoadTiledBg("bg/bg3", "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
|
||||
NF_InitTiledBgSys(1); // Inicializa los fondos Tileados para la pantalla inferior
|
||||
// Load sprite files from NitroFS
|
||||
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
|
||||
NF_LoadSpritePal("sprite/blueball", 0);
|
||||
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
|
||||
NF_LoadSpritePal("sprite/redcar", 1);
|
||||
|
||||
// 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);
|
||||
NF_Vram3dSpriteGfx(1, 1, true);
|
||||
NF_Vram3dSpritePal(1, 1);
|
||||
|
||||
// Inicializa el sistema de Sprites en 3D y OpenGL
|
||||
NF_Init3dSpriteSys();
|
||||
// Create backgrounds in both screens
|
||||
NF_CreateTiledBg(0, 3, "bg3");
|
||||
NF_CreateTiledBg(1, 3, "nfl");
|
||||
|
||||
// Carga los fondos tileados
|
||||
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
|
||||
NF_LoadTiledBg("bg/bg3", "bg3", 256, 256);
|
||||
// Variables
|
||||
s16 x[MAXSPRITES];
|
||||
s16 y[MAXSPRITES];
|
||||
s16 ix[MAXSPRITES];
|
||||
s16 iy[MAXSPRITES];
|
||||
|
||||
// Carga los graficos de los Sprites
|
||||
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
|
||||
NF_LoadSpritePal("sprite/blueball", 0);
|
||||
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
|
||||
NF_LoadSpritePal("sprite/redcar", 1);
|
||||
// Initialize sprite variables and create the sprites
|
||||
for (int n = 0; n < MAXSPRITES; n ++)
|
||||
{
|
||||
int r = n % 2;
|
||||
|
||||
// Manda los graficos y paletas a la VRAM
|
||||
NF_Vram3dSpriteGfx(0, 0, true);
|
||||
NF_Vram3dSpritePal(0, 0);
|
||||
NF_Vram3dSpriteGfx(1, 1, true);
|
||||
NF_Vram3dSpritePal(1, 1);
|
||||
x[n] = rand() % 128;
|
||||
y[n] = rand() % 112;
|
||||
if ((rand() % 100) > 50)
|
||||
ix[n] = 1;
|
||||
else
|
||||
ix[n] = -1;
|
||||
|
||||
if ((rand() % 100) > 50)
|
||||
iy[n] = 1;
|
||||
else
|
||||
iy[n] = -1;
|
||||
|
||||
// Crea los fondos en ambas pantallas
|
||||
NF_CreateTiledBg(0, 3, "bg3");
|
||||
NF_CreateTiledBg(1, 3, "nfl");
|
||||
NF_Create3dSprite(n, r, r, x[n], y[n]);
|
||||
}
|
||||
|
||||
// Sort their priorites based on their IDs (lower IDs have higher priority)
|
||||
NF_Sort3dSprites();
|
||||
|
||||
// Variables
|
||||
u16 n = 0;
|
||||
u16 r = 0;
|
||||
s16 x[MAXSPRITES];
|
||||
s16 y[MAXSPRITES];
|
||||
s16 ix[MAXSPRITES];
|
||||
s16 iy[MAXSPRITES];
|
||||
while (1)
|
||||
{
|
||||
// Read keys
|
||||
scanKeys();
|
||||
u16 keys = keysDown();
|
||||
|
||||
// Inicializa las variables
|
||||
for (n = 0; n < MAXSPRITES; n ++) {
|
||||
r = (n % 2);
|
||||
x[n] = (((int)(rand() % 128)));
|
||||
y[n] = (((int)(rand() % 112)));
|
||||
if ((rand() % 100) > 50) {
|
||||
ix[n] = 1;
|
||||
} else {
|
||||
ix[n] = -1;
|
||||
}
|
||||
if ((rand() % 100) > 50) {
|
||||
iy[n] = 1;
|
||||
} else {
|
||||
iy[n] = -1;
|
||||
}
|
||||
// Crea los Sprites 3D
|
||||
NF_Create3dSprite(n, r, r, x[n], y[n]);
|
||||
}
|
||||
// Move sprites
|
||||
for (int n = 0; n < MAXSPRITES; n ++)
|
||||
{
|
||||
x[n] += ix[n];
|
||||
if ((x[n] < 0) || (x[n] > (255 - NF_3DSPRITE[n].width)))
|
||||
ix[n] = -ix[n];
|
||||
|
||||
// Y ordenalos en la cola segun su ID (El mas bajo tiene prioridad)
|
||||
NF_Sort3dSprites();
|
||||
y[n] += iy[n];
|
||||
if ((y[n] < 0) || (y[n] > (191 - NF_3DSPRITE[n].height)))
|
||||
iy[n] = -iy[n];
|
||||
|
||||
// Variable para la lectura del teclado
|
||||
u16 keys = 0;
|
||||
NF_Move3dSprite(n, x[n], y[n]);
|
||||
}
|
||||
|
||||
// Bucle (repite para siempre)
|
||||
while(1) {
|
||||
// Show or hide all sprites with even ID
|
||||
if (keys & KEY_A)
|
||||
{
|
||||
for (int n = 0; n < MAXSPRITES; n += 2)
|
||||
NF_Show3dSprite(n, true);
|
||||
}
|
||||
|
||||
// Lee el teclado
|
||||
scanKeys();
|
||||
keys = keysDown();
|
||||
if (keys & KEY_B)
|
||||
{
|
||||
for (int n = 0; n < MAXSPRITES; n += 2)
|
||||
NF_Show3dSprite(n, false);
|
||||
}
|
||||
|
||||
// Mueve todos los Sprites
|
||||
for (n = 0; n < MAXSPRITES; n ++) {
|
||||
x[n] += ix[n];
|
||||
if ((x[n] < 0) || (x[n] > (255 - NF_3DSPRITE[n].width))) ix[n] = -ix[n];
|
||||
y[n] += iy[n];
|
||||
if ((y[n] < 0) || (y[n] > (191 - NF_3DSPRITE[n].height))) iy[n] = -iy[n];
|
||||
NF_Move3dSprite(n, x[n], y[n]);
|
||||
}
|
||||
// Draw all 3D sprites
|
||||
NF_Draw3dSprites();
|
||||
|
||||
// Muestra u oculta los sprites pares
|
||||
if (keys & KEY_A) {
|
||||
for (n = 0; n < MAXSPRITES; n +=2) {
|
||||
NF_Show3dSprite(n, true);
|
||||
}
|
||||
}
|
||||
if (keys & KEY_B) {
|
||||
for (n = 0; n < MAXSPRITES; n +=2) {
|
||||
NF_Show3dSprite(n, false);
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
@ -1,244 +1,224 @@
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
//
|
||||
// SPDX-FileContributor: NightFox & Co., 2009-2011
|
||||
//
|
||||
// Example of rotating and scaling 3D sprites.
|
||||
// http://www.nightfoxandco.com
|
||||
|
||||
/*
|
||||
-------------------------------------------------
|
||||
|
||||
NightFox's Lib Template
|
||||
Ejemplo de 3D Sprites
|
||||
Rotacion y escalado
|
||||
|
||||
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)
|
||||
{
|
||||
// Set random seed based on the current time
|
||||
srand(time(NULL));
|
||||
|
||||
/*
|
||||
-------------------------------------------------
|
||||
Main() - Bloque general del programa
|
||||
-------------------------------------------------
|
||||
*/
|
||||
// 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();
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Initialize NitroFS and set it as the root folder of the filesystem
|
||||
nitroFSInit(NULL);
|
||||
NF_SetRootFolder("NITROFS");
|
||||
|
||||
// Inicializa el random
|
||||
srand(time(NULL));
|
||||
// Initialize 3D engine in the top screen in mode 0
|
||||
NF_Set3D(0, 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
|
||||
// Initialize 3D sprite system
|
||||
NF_InitSpriteBuffers(); // Initialize storage buffers
|
||||
NF_Init3dSpriteSys();
|
||||
|
||||
// Inicializa el motor 3D
|
||||
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior
|
||||
// Load background files from NitroFS
|
||||
NF_LoadTiledBg("bg/bg3", "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);
|
||||
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
|
||||
NF_LoadSpritePal("sprite/redcar", 1);
|
||||
|
||||
// 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);
|
||||
NF_Vram3dSpriteGfx(1, 1, true);
|
||||
NF_Vram3dSpritePal(1, 1);
|
||||
|
||||
// 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/bg3", "bg3", 256, 256);
|
||||
// Variables
|
||||
s16 x[MAXSPRITES];
|
||||
s16 y[MAXSPRITES];
|
||||
s16 ix[MAXSPRITES];
|
||||
s16 iy[MAXSPRITES];
|
||||
s16 rx[MAXSPRITES];
|
||||
s16 ry[MAXSPRITES];
|
||||
s16 rz[MAXSPRITES];
|
||||
s16 scale[MAXSPRITES];
|
||||
|
||||
// Carga los graficos de los Sprites
|
||||
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
|
||||
NF_LoadSpritePal("sprite/blueball", 0);
|
||||
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
|
||||
NF_LoadSpritePal("sprite/redcar", 1);
|
||||
// Initialize sprite variables and create the sprites
|
||||
for (int n = 0; n < MAXSPRITES; n++)
|
||||
{
|
||||
int r;
|
||||
|
||||
// Manda los graficos y paletas a la VRAM
|
||||
NF_Vram3dSpriteGfx(0, 0, true);
|
||||
NF_Vram3dSpritePal(0, 0);
|
||||
NF_Vram3dSpriteGfx(1, 1, true);
|
||||
NF_Vram3dSpritePal(1, 1);
|
||||
if ((n % 2) == 0)
|
||||
r = 1;
|
||||
else
|
||||
r = 0;
|
||||
|
||||
x[n] = (rand() % 128) + 1;
|
||||
y[n] = (rand() % 112) + 1;
|
||||
if ((rand() % 100) > 50)
|
||||
ix[n] = 1;
|
||||
else
|
||||
ix[n] = -1;
|
||||
|
||||
// Crea los fondos en ambas pantallas
|
||||
NF_CreateTiledBg(0, 3, "bg3");
|
||||
if ((rand() % 100) > 50)
|
||||
iy[n] = 1;
|
||||
else
|
||||
iy[n] = -1;
|
||||
|
||||
rx[n] = 0;
|
||||
ry[n] = 0;
|
||||
rz[n] = 0;
|
||||
scale[n] = 64;
|
||||
|
||||
// Variables
|
||||
u16 n = 0;
|
||||
u16 r = 0;
|
||||
s16 x[MAXSPRITES];
|
||||
s16 y[MAXSPRITES];
|
||||
s16 ix[MAXSPRITES];
|
||||
s16 iy[MAXSPRITES];
|
||||
s16 rx[MAXSPRITES];
|
||||
s16 ry[MAXSPRITES];
|
||||
s16 rz[MAXSPRITES];
|
||||
s16 scale[MAXSPRITES];
|
||||
NF_Create3dSprite(n, r, r, x[n], y[n]);
|
||||
}
|
||||
|
||||
// Inicializa las variables
|
||||
for (n = 0; n < MAXSPRITES; n ++) {
|
||||
if ((n % 2) == 0) {
|
||||
r = 1;
|
||||
} else {
|
||||
r = 0;
|
||||
}
|
||||
x[n] = (((int)(rand() % 128)) + 1);
|
||||
y[n] = (((int)(rand() % 112)) + 1);
|
||||
if ((rand() % 100) > 50) {
|
||||
ix[n] = 1;
|
||||
} else {
|
||||
ix[n] = -1;
|
||||
}
|
||||
if ((rand() % 100) > 50) {
|
||||
iy[n] = 1;
|
||||
} else {
|
||||
iy[n] = -1;
|
||||
}
|
||||
rx[n] = 0;
|
||||
ry[n] = 0;
|
||||
rz[n] = 0;
|
||||
scale[n] = 64;
|
||||
// Crea los Sprites 3D
|
||||
NF_Create3dSprite(n, r, r, x[n], y[n]);
|
||||
}
|
||||
// Sort their priorites based on their IDs (lower IDs have higher priority)
|
||||
NF_Sort3dSprites();
|
||||
|
||||
// Y ordenalos en la cola segun su ID (El mas bajo tiene prioridad)
|
||||
NF_Sort3dSprites();
|
||||
// Variable that contains the ID of the sprite selected by the user
|
||||
s16 id = 0;
|
||||
|
||||
// Variable para la lectura del teclado
|
||||
u16 press = 0;
|
||||
u16 held = 0;
|
||||
s16 id = 0;
|
||||
while (1)
|
||||
{
|
||||
// Read keys
|
||||
scanKeys();
|
||||
u16 press = keysDown();
|
||||
u16 held = keysHeld();
|
||||
|
||||
// Bucle (repite para siempre)
|
||||
while(1) {
|
||||
// Move sprites
|
||||
for (int n = 0; n < MAXSPRITES; n++)
|
||||
{
|
||||
x[n] += ix[n];
|
||||
if ((x[n] < 1) || (x[n] > (255 - NF_3DSPRITE[n].width)))
|
||||
ix[n] = -ix[n];
|
||||
|
||||
// Lee el teclado
|
||||
scanKeys();
|
||||
press = keysDown();
|
||||
held = keysHeld();
|
||||
y[n] += iy[n];
|
||||
if ((y[n] < 1) || (y[n] > (191 - NF_3DSPRITE[n].height)))
|
||||
iy[n] = -iy[n];
|
||||
|
||||
// Mueve todos los Sprites
|
||||
for (n = 0; n < MAXSPRITES; n ++) {
|
||||
x[n] += ix[n];
|
||||
if ((x[n] < 1) || (x[n] > (255 - NF_3DSPRITE[n].width))) ix[n] = -ix[n];
|
||||
y[n] += iy[n];
|
||||
if ((y[n] < 1) || (y[n] > (191 - NF_3DSPRITE[n].height))) iy[n] = -iy[n];
|
||||
NF_Move3dSprite(n, x[n], y[n]);
|
||||
}
|
||||
NF_Move3dSprite(n, x[n], y[n]);
|
||||
}
|
||||
|
||||
// Selecciona el Sprite con A y B
|
||||
if (press & KEY_A) {
|
||||
id ++;
|
||||
if (id > (MAXSPRITES - 1)) id = 0;
|
||||
}
|
||||
if (press & KEY_B) {
|
||||
id --;
|
||||
if (id < 0) id = (MAXSPRITES - 1);
|
||||
}
|
||||
// Change the selected sprite by pressing A or B
|
||||
if (press & KEY_A)
|
||||
{
|
||||
id++;
|
||||
if (id > (MAXSPRITES - 1))
|
||||
id = 0;
|
||||
}
|
||||
if (press & KEY_B)
|
||||
{
|
||||
id--;
|
||||
if (id < 0)
|
||||
id = MAXSPRITES - 1;
|
||||
}
|
||||
|
||||
// Rota el Z del Sprite ID
|
||||
if (held & KEY_RIGHT) {
|
||||
rz[id] += 2;
|
||||
if (rz[id] > 512) rz[id] -= 512;
|
||||
}
|
||||
if (held & KEY_LEFT) {
|
||||
rz[id] -= 2;
|
||||
if (rz[id] < 0) rz[id] += 512;
|
||||
}
|
||||
// Rotate Z axis of the selcted sprite
|
||||
if (held & KEY_RIGHT)
|
||||
{
|
||||
rz[id] += 2;
|
||||
if (rz[id] > 512)
|
||||
rz[id] -= 512;
|
||||
}
|
||||
if (held & KEY_LEFT)
|
||||
{
|
||||
rz[id] -= 2;
|
||||
if (rz[id] < 0)
|
||||
rz[id] += 512;
|
||||
}
|
||||
|
||||
// Rota el Y del Sprite ID
|
||||
if (held & KEY_DOWN) {
|
||||
ry[id] += 2;
|
||||
if (ry[id] > 512) ry[id] -= 512;
|
||||
}
|
||||
if (held & KEY_UP) {
|
||||
ry[id] -= 2;
|
||||
if (ry[id] < 0) ry[id] += 512;
|
||||
}
|
||||
// Rotate Y axis of the selcted sprite
|
||||
if (held & KEY_DOWN)
|
||||
{
|
||||
ry[id] += 2;
|
||||
if (ry[id] > 512)
|
||||
ry[id] -= 512;
|
||||
}
|
||||
if (held & KEY_UP)
|
||||
{
|
||||
ry[id] -= 2;
|
||||
if (ry[id] < 0)
|
||||
ry[id] += 512;
|
||||
}
|
||||
|
||||
// Rota el X del Sprite ID
|
||||
if (held & KEY_X) {
|
||||
rx[id] += 2;
|
||||
if (rx[id] > 512) rx[id] -= 512;
|
||||
}
|
||||
if (held & KEY_Y) {
|
||||
rx[id] -= 2;
|
||||
if (rx[id] < 0) rx[id] += 512;
|
||||
}
|
||||
// Rotate X axis of the selcted sprite
|
||||
if (held & KEY_X)
|
||||
{
|
||||
rx[id] += 2;
|
||||
if (rx[id] > 512)
|
||||
rx[id] -= 512;
|
||||
}
|
||||
if (held & KEY_Y)
|
||||
{
|
||||
rx[id] -= 2;
|
||||
if (rx[id] < 0)
|
||||
rx[id] += 512;
|
||||
}
|
||||
|
||||
// Escala el sprite
|
||||
if (held & KEY_R) {
|
||||
scale[id] += 2;
|
||||
if (scale[id] > 512) scale[id] = 512;
|
||||
}
|
||||
if (held & KEY_L) {
|
||||
scale[id] -= 2;
|
||||
if (scale[id] < 0) scale[id] = 0;
|
||||
}
|
||||
// Scale sprite
|
||||
if (held & KEY_R)
|
||||
{
|
||||
scale[id] += 2;
|
||||
if (scale[id] > 512)
|
||||
scale[id] = 512;
|
||||
}
|
||||
if (held & KEY_L)
|
||||
{
|
||||
scale[id] -= 2;
|
||||
if (scale[id] < 0)
|
||||
scale[id] = 0;
|
||||
}
|
||||
|
||||
// Aplica la rotacion
|
||||
NF_Rotate3dSprite(id, rx[id], ry[id], rz[id]);
|
||||
// Apply rotation and scale
|
||||
NF_Rotate3dSprite(id, rx[id], ry[id], rz[id]);
|
||||
NF_Scale3dSprite(id, scale[id], scale[id]);
|
||||
|
||||
// Aplica el escalado
|
||||
NF_Scale3dSprite(id, scale[id], scale[id]);
|
||||
// Draw all 3D sprites
|
||||
NF_Draw3dSprites();
|
||||
|
||||
// Dibuja los 3D Sprites
|
||||
NF_Draw3dSprites();
|
||||
// Tell the GPU to draw the scene and wait until it's done
|
||||
glFlush(0);
|
||||
|
||||
// Actualiza la escena 3D, si no lo haces, no se mostrara en pantalla
|
||||
glFlush(0);
|
||||
// Print debug information
|
||||
consoleClear();
|
||||
printf("A / B - Sprite select %d\n", id);
|
||||
printf("Rotate Z (LEFT/RIGHT) %d\n", rz[id]);
|
||||
printf("Rotate Y (UP/DOWN) %d\n", ry[id]);
|
||||
printf("Rotate X (X/Y) %d\n", rx[id]);
|
||||
printf("Scale (R/L) %d\n", scale[id]);
|
||||
|
||||
// Debug
|
||||
consoleClear();
|
||||
printf("A / B - Sprite select %d\n", id);
|
||||
printf("Rotate Z (LEFT/RIGHT) %d\n", rz[id]);
|
||||
printf("Rotate Y (UP/DOWN) %d\n", ry[id]);
|
||||
printf("Rotate X (X/Y) %d\n", rx[id]);
|
||||
printf("Scale (R/L) %d\n", scale[id]);
|
||||
|
||||
// Espera al sincronismo vertical
|
||||
swiWaitForVBlank();
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
// Wait for the screen refresh
|
||||
swiWaitForVBlank();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,194 +1,169 @@
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
//
|
||||
// SPDX-FileContributor: NightFox & Co., 2009-2011
|
||||
//
|
||||
// Priority change example.
|
||||
// http://www.nightfoxandco.com
|
||||
|
||||
/*
|
||||
-------------------------------------------------
|
||||
|
||||
NightFox's Lib Template
|
||||
Ejemplo de 3D Sprites - Cambio de prioridad
|
||||
|
||||
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 16
|
||||
#define TARGET 8
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Set random seed based on the current time
|
||||
srand(time(NULL));
|
||||
|
||||
/*
|
||||
-------------------------------------------------
|
||||
Main() - Bloque general del programa
|
||||
-------------------------------------------------
|
||||
*/
|
||||
// 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();
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Initialize NitroFS and set it as the root folder of the filesystem
|
||||
nitroFSInit(NULL);
|
||||
NF_SetRootFolder("NITROFS");
|
||||
|
||||
// Inicializa el random
|
||||
srand(time(NULL));
|
||||
// Initialize 3D engine in the top screen in mode 0
|
||||
NF_Set3D(0, 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
|
||||
// Initialize 3D sprite system
|
||||
NF_InitSpriteBuffers(); // Initialize storage buffers
|
||||
NF_Init3dSpriteSys();
|
||||
|
||||
// Inicializa el motor 3D
|
||||
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior
|
||||
// Load background files from NitroFS
|
||||
NF_LoadTiledBg("bg/bg3", "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);
|
||||
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
|
||||
NF_LoadSpritePal("sprite/redcar", 1);
|
||||
|
||||
// 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);
|
||||
NF_Vram3dSpriteGfx(1, 1, true);
|
||||
NF_Vram3dSpritePal(1, 1);
|
||||
|
||||
// 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/bg3", "bg3", 256, 256);
|
||||
// Variables
|
||||
s16 x[MAXSPRITES];
|
||||
s16 y[MAXSPRITES];
|
||||
s16 ix[MAXSPRITES];
|
||||
s16 iy[MAXSPRITES];
|
||||
|
||||
// Carga los graficos de los Sprites
|
||||
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
|
||||
NF_LoadSpritePal("sprite/blueball", 0);
|
||||
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
|
||||
NF_LoadSpritePal("sprite/redcar", 1);
|
||||
// Initialize sprite variables and create the sprites
|
||||
for (int n = 0; n < MAXSPRITES; n++)
|
||||
{
|
||||
int r;
|
||||
|
||||
// Manda los graficos y paletas a la VRAM
|
||||
NF_Vram3dSpriteGfx(0, 0, true);
|
||||
NF_Vram3dSpritePal(0, 0);
|
||||
NF_Vram3dSpriteGfx(1, 1, true);
|
||||
NF_Vram3dSpritePal(1, 1);
|
||||
if (n == TARGET)
|
||||
r = 1;
|
||||
else
|
||||
r = 0;
|
||||
|
||||
x[n] = rand() % 128;
|
||||
y[n] = rand() % 112;
|
||||
|
||||
// Crea los fondos en ambas pantallas
|
||||
NF_CreateTiledBg(0, 3, "bg3");
|
||||
if ((rand() % 100) > 50)
|
||||
ix[n] = 1;
|
||||
else
|
||||
ix[n] = -1;
|
||||
|
||||
if ((rand() % 100) > 50)
|
||||
iy[n] = 1;
|
||||
else
|
||||
iy[n] = -1;
|
||||
|
||||
// Variables
|
||||
u16 n = 0;
|
||||
u16 r = 0;
|
||||
s16 x[MAXSPRITES];
|
||||
s16 y[MAXSPRITES];
|
||||
s16 ix[MAXSPRITES];
|
||||
s16 iy[MAXSPRITES];
|
||||
NF_Create3dSprite(n, r, r, x[n], y[n]);
|
||||
}
|
||||
|
||||
// Inicializa las variables
|
||||
for (n = 0; n < MAXSPRITES; n ++) {
|
||||
if (n == TARGET) {
|
||||
r = 1;
|
||||
} else {
|
||||
r = 0;
|
||||
}
|
||||
x[n] = (((int)(rand() % 128)));
|
||||
y[n] = (((int)(rand() % 112)));
|
||||
if ((rand() % 100) > 50) {
|
||||
ix[n] = 1;
|
||||
} else {
|
||||
ix[n] = -1;
|
||||
}
|
||||
if ((rand() % 100) > 50) {
|
||||
iy[n] = 1;
|
||||
} else {
|
||||
iy[n] = -1;
|
||||
}
|
||||
// Crea los Sprites 3D
|
||||
NF_Create3dSprite(n, r, r, x[n], y[n]);
|
||||
}
|
||||
// Sort their priorites based on their IDs (lower IDs have higher priority)
|
||||
NF_Sort3dSprites();
|
||||
|
||||
// Y ordenalos en la cola segun su ID (El mas bajo tiene prioridad)
|
||||
NF_Sort3dSprites();
|
||||
// Variable that holds the current priority of the user-controlled sprite
|
||||
s16 prio = TARGET;
|
||||
|
||||
// Variable para la lectura del teclado
|
||||
u16 keys = 0;
|
||||
s16 prio = TARGET;
|
||||
while (1)
|
||||
{
|
||||
// Read keys
|
||||
scanKeys();
|
||||
u16 keys = keysDown();
|
||||
|
||||
// Bucle (repite para siempre)
|
||||
while(1) {
|
||||
// Move sprites
|
||||
for (int n = 0; n < MAXSPRITES; n++)
|
||||
{
|
||||
x[n] += ix[n];
|
||||
if ((x[n] < 0) || (x[n] > (255 - NF_3DSPRITE[n].width)))
|
||||
ix[n] = -ix[n];
|
||||
|
||||
// Lee el teclado
|
||||
scanKeys();
|
||||
keys = keysDown();
|
||||
y[n] += iy[n];
|
||||
if ((y[n] < 0) || (y[n] > (191 - NF_3DSPRITE[n].height)))
|
||||
iy[n] = -iy[n];
|
||||
|
||||
// Mueve todos los Sprites
|
||||
for (n = 0; n < MAXSPRITES; n ++) {
|
||||
x[n] += ix[n];
|
||||
if ((x[n] < 0) || (x[n] > (255 - NF_3DSPRITE[n].width))) ix[n] = -ix[n];
|
||||
y[n] += iy[n];
|
||||
if ((y[n] < 0) || (y[n] > (191 - NF_3DSPRITE[n].height))) iy[n] = -iy[n];
|
||||
NF_Move3dSprite(n, x[n], y[n]);
|
||||
}
|
||||
NF_Move3dSprite(n, x[n], y[n]);
|
||||
}
|
||||
|
||||
// Cambia la prioridad del Sprite seleccionado
|
||||
if ((keys & KEY_A) && (prio > 0)) {
|
||||
prio --;
|
||||
NF_Set3dSpritePriority(TARGET, prio);
|
||||
}
|
||||
if ((keys & KEY_B) && (prio < (MAXSPRITES - 1))) {
|
||||
prio ++;
|
||||
NF_Set3dSpritePriority(TARGET, prio);
|
||||
}
|
||||
// Restaura la prioridad por defecto
|
||||
if (keys & KEY_X) NF_3dSpriteSetDepth(TARGET, 0);
|
||||
// Fuerza estar al frente
|
||||
if (keys & KEY_R) NF_3dSpriteSetDepth(TARGET, -512);
|
||||
// Fuerza estar al fondo
|
||||
if (keys & KEY_L) NF_3dSpriteSetDepth(TARGET, 512);
|
||||
// Change the priority of the sprite
|
||||
if ((keys & KEY_A) && (prio > 0))
|
||||
{
|
||||
prio --;
|
||||
NF_Set3dSpritePriority(TARGET, prio);
|
||||
}
|
||||
if ((keys & KEY_B) && (prio < (MAXSPRITES - 1)))
|
||||
{
|
||||
prio ++;
|
||||
NF_Set3dSpritePriority(TARGET, prio);
|
||||
}
|
||||
|
||||
// Dibuja los 3D Sprites
|
||||
NF_Draw3dSprites();
|
||||
// Restore default priority
|
||||
if (keys & KEY_X)
|
||||
NF_3dSpriteSetDepth(TARGET, 0);
|
||||
|
||||
// Actualiza la escena 3D, si no lo haces, no se mostrara en pantalla
|
||||
glFlush(0);
|
||||
// Move sprite on top of everything
|
||||
if (keys & KEY_R)
|
||||
NF_3dSpriteSetDepth(TARGET, -512);
|
||||
|
||||
// Debug
|
||||
consoleClear();
|
||||
for (n = 0; n < NF_CREATED_3DSPRITE.total; n ++) {
|
||||
printf("Pri:%02d Spr:%02d Spr:%02d Pri:%02d\n", n, NF_CREATED_3DSPRITE.id[n], n, NF_3DSPRITE[n].prio);
|
||||
}
|
||||
printf("\nSprite Id%02d is on %02d priority\n\n", TARGET, NF_3DSPRITE[TARGET].prio);
|
||||
printf("A - Near B - Far");
|
||||
// Move sprite to the back
|
||||
if (keys & KEY_L)
|
||||
NF_3dSpriteSetDepth(TARGET, 512);
|
||||
|
||||
// Espera al sincronismo vertical
|
||||
swiWaitForVBlank();
|
||||
// Draw all 3D sprites
|
||||
NF_Draw3dSprites();
|
||||
|
||||
}
|
||||
// Tell the GPU to draw the scene and wait until it's done
|
||||
glFlush(0);
|
||||
|
||||
return 0;
|
||||
// Print debug information
|
||||
consoleClear();
|
||||
for (int n = 0; n < NF_CREATED_3DSPRITE.total; n++)
|
||||
{
|
||||
printf("Pri:%02d Spr:%02d Spr:%02d Pri:%02d\n",
|
||||
n, NF_CREATED_3DSPRITE.id[n], n, NF_3DSPRITE[n].prio);
|
||||
}
|
||||
printf("\nSprite Id%02d is on %02d priority\n\n",
|
||||
TARGET, NF_3DSPRITE[TARGET].prio);
|
||||
printf("A - Near B - Far");
|
||||
|
||||
// Wait for the screen refresh
|
||||
swiWaitForVBlank();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,183 +1,144 @@
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
//
|
||||
// SPDX-FileContributor: NightFox & Co., 2009-2011
|
||||
//
|
||||
// Priority swap example.
|
||||
// http://www.nightfoxandco.com
|
||||
|
||||
/*
|
||||
-------------------------------------------------
|
||||
|
||||
NightFox's Lib Template
|
||||
Ejemplo de 3D Sprites
|
||||
Intercambio de prioridades
|
||||
|
||||
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 32
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Set random seed based on the current time
|
||||
srand(time(NULL));
|
||||
|
||||
/*
|
||||
-------------------------------------------------
|
||||
Main() - Bloque general del programa
|
||||
-------------------------------------------------
|
||||
*/
|
||||
// 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();
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Initialize NitroFS and set it as the root folder of the filesystem
|
||||
nitroFSInit(NULL);
|
||||
NF_SetRootFolder("NITROFS");
|
||||
|
||||
// Inicializa el random
|
||||
srand(time(NULL));
|
||||
// Initialize 3D engine in the top screen in mode 0
|
||||
NF_Set3D(0, 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
|
||||
// Initialize 3D sprite system
|
||||
NF_InitSpriteBuffers(); // Initialize storage buffers
|
||||
NF_Init3dSpriteSys();
|
||||
|
||||
// Inicializa el motor 3D
|
||||
NF_Set3D(0, 0); // Modo 3D_0 en la pantalla superior
|
||||
// Load background files from NitroFS
|
||||
NF_LoadTiledBg("bg/bg3", "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);
|
||||
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
|
||||
NF_LoadSpritePal("sprite/redcar", 1);
|
||||
|
||||
// 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);
|
||||
NF_Vram3dSpriteGfx(1, 1, true);
|
||||
NF_Vram3dSpritePal(1, 1);
|
||||
|
||||
// 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/bg3", "bg3", 256, 256);
|
||||
// Variables
|
||||
s16 x[MAXSPRITES];
|
||||
s16 y[MAXSPRITES];
|
||||
s16 ix[MAXSPRITES];
|
||||
s16 iy[MAXSPRITES];
|
||||
|
||||
// Carga los graficos de los Sprites
|
||||
NF_LoadSpriteGfx("sprite/blueball", 0, 64, 64);
|
||||
NF_LoadSpritePal("sprite/blueball", 0);
|
||||
NF_LoadSpriteGfx("sprite/redcar", 1, 128, 64);
|
||||
NF_LoadSpritePal("sprite/redcar", 1);
|
||||
// Initialize sprite variables and create the sprites
|
||||
for (int n = 0; n < MAXSPRITES; n++)
|
||||
{
|
||||
int r;
|
||||
|
||||
// Manda los graficos y paletas a la VRAM
|
||||
NF_Vram3dSpriteGfx(0, 0, true);
|
||||
NF_Vram3dSpritePal(0, 0);
|
||||
NF_Vram3dSpriteGfx(1, 1, true);
|
||||
NF_Vram3dSpritePal(1, 1);
|
||||
if ((n == 0) || (n == (MAXSPRITES - 1)))
|
||||
r = 1;
|
||||
else
|
||||
r = 0;
|
||||
|
||||
x[n] = (rand() % 128) + 1;
|
||||
y[n] = (rand() % 112) + 1;
|
||||
|
||||
// Crea los fondos en ambas pantallas
|
||||
NF_CreateTiledBg(0, 3, "bg3");
|
||||
if ((rand() % 100) > 50)
|
||||
ix[n] = 1;
|
||||
else
|
||||
ix[n] = -1;
|
||||
|
||||
if ((rand() % 100) > 50)
|
||||
iy[n] = 1;
|
||||
else
|
||||
iy[n] = -1;
|
||||
|
||||
// Variables
|
||||
u16 n = 0;
|
||||
u16 r = 0;
|
||||
s16 x[MAXSPRITES];
|
||||
s16 y[MAXSPRITES];
|
||||
s16 ix[MAXSPRITES];
|
||||
s16 iy[MAXSPRITES];
|
||||
NF_Create3dSprite(n, r, r, x[n], y[n]);
|
||||
}
|
||||
|
||||
// Inicializa las variables
|
||||
for (n = 0; n < MAXSPRITES; n ++) {
|
||||
if ((n == 0) || (n == (MAXSPRITES - 1))) {
|
||||
r = 1;
|
||||
} else {
|
||||
r = 0;
|
||||
}
|
||||
x[n] = (((int)(rand() % 128)) + 1);
|
||||
y[n] = (((int)(rand() % 112)) + 1);
|
||||
if ((rand() % 100) > 50) {
|
||||
ix[n] = 1;
|
||||
} else {
|
||||
ix[n] = -1;
|
||||
}
|
||||
if ((rand() % 100) > 50) {
|
||||
iy[n] = 1;
|
||||
} else {
|
||||
iy[n] = -1;
|
||||
}
|
||||
// Crea los Sprites 3D
|
||||
NF_Create3dSprite(n, r, r, x[n], y[n]);
|
||||
}
|
||||
// Sort their priorites based on their IDs (lower IDs have higher priority)
|
||||
NF_Sort3dSprites();
|
||||
|
||||
// Y ordenalos en la cola segun su ID (El mas bajo tiene prioridad)
|
||||
NF_Sort3dSprites();
|
||||
while (1)
|
||||
{
|
||||
// Read keys
|
||||
scanKeys();
|
||||
u16 keys = keysDown();
|
||||
|
||||
// Variable para la lectura del teclado
|
||||
u16 keys = 0;
|
||||
// Move sprites
|
||||
for (int n = 0; n < MAXSPRITES; n++)
|
||||
{
|
||||
x[n] += ix[n];
|
||||
if ((x[n] < 1) || (x[n] > (255 - NF_3DSPRITE[n].width)))
|
||||
ix[n] = -ix[n];
|
||||
|
||||
// Bucle (repite para siempre)
|
||||
while(1) {
|
||||
y[n] += iy[n];
|
||||
if ((y[n] < 1) || (y[n] > (191 - NF_3DSPRITE[n].height)))
|
||||
iy[n] = -iy[n];
|
||||
|
||||
// Lee el teclado
|
||||
scanKeys();
|
||||
keys = keysDown();
|
||||
NF_Move3dSprite(n, x[n], y[n]);
|
||||
}
|
||||
|
||||
// Mueve todos los Sprites
|
||||
for (n = 0; n < MAXSPRITES; n ++) {
|
||||
x[n] += ix[n];
|
||||
if ((x[n] < 1) || (x[n] > (255 - NF_3DSPRITE[n].width))) ix[n] = -ix[n];
|
||||
y[n] += iy[n];
|
||||
if ((y[n] < 1) || (y[n] > (191 - NF_3DSPRITE[n].height))) iy[n] = -iy[n];
|
||||
NF_Move3dSprite(n, x[n], y[n]);
|
||||
}
|
||||
// Show or hide sprites with even ID
|
||||
if (keys & KEY_A)
|
||||
NF_Swap3dSpritePriority(0, MAXSPRITES - 1);
|
||||
|
||||
// Muestra u oculta los sprites pares
|
||||
if (keys & KEY_A) {
|
||||
NF_Swap3dSpritePriority(0, (MAXSPRITES - 1));
|
||||
}
|
||||
if (keys & KEY_B) {
|
||||
NF_Swap3dSpritePriority((MAXSPRITES - 1), 0);
|
||||
}
|
||||
if (keys & KEY_B)
|
||||
NF_Swap3dSpritePriority(MAXSPRITES - 1, 0);
|
||||
|
||||
// Dibuja los 3D Sprites
|
||||
NF_Draw3dSprites();
|
||||
// Draw all 3D sprites
|
||||
NF_Draw3dSprites();
|
||||
|
||||
// Actualiza la escena 3D, si no lo haces, no se mostrara en pantalla
|
||||
glFlush(0);
|
||||
// Tell the GPU to draw the scene and wait until it's done
|
||||
glFlush(0);
|
||||
|
||||
// Debug
|
||||
consoleClear();
|
||||
printf("\nSprite Id%02d is on %02d priority\n", 0, NF_3DSPRITE[0].prio);
|
||||
printf("Sprite Id%02d is on %02d priority\n\n", (MAXSPRITES - 1), NF_3DSPRITE[(MAXSPRITES - 1)].prio);
|
||||
printf("A or B - Swap 0 & %d", (MAXSPRITES - 1));
|
||||
// Print debug information
|
||||
consoleClear();
|
||||
printf("\nSprite Id%02d is on %02d priority\n", 0, NF_3DSPRITE[0].prio);
|
||||
printf("Sprite Id%02d is on %02d priority\n\n",
|
||||
MAXSPRITES - 1, NF_3DSPRITE[MAXSPRITES - 1].prio);
|
||||
printf("A or B - Swap 0 & %d", MAXSPRITES - 1);
|
||||
|
||||
// Espera al sincronismo vertical
|
||||
swiWaitForVBlank();
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
// Wait for the screen refresh
|
||||
swiWaitForVBlank();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user