examples: Cleanup and translate more examples to English

This commit is contained in:
Antonio Niño Díaz 2023-05-20 18:42:39 +01:00
parent c6d6883caf
commit 11b2717515
5 changed files with 463 additions and 625 deletions

View File

@ -1,59 +1,24 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Alpha blending example (real alpha blending and fake blending by blinking).
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de Alpha Blending
Importante: El efecto Fake alpha solo funciona bien
en la consola, no en los emuladores.
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>
int main(int argc, char **argv)
{
// Set random seed based on the current time
srand(time(NULL));
// 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();
@ -61,70 +26,69 @@ 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");
// Inicializa el motor 2D // Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(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
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior NF_InitTiledBgSys(1); // Bottom screen
// Inicializa los Sprites // Initialize sprite system
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas NF_InitSpriteBuffers(); // Initialize storage buffers
NF_InitSpriteSys(0); // Inicializa los sprites para la pantalla superior NF_InitSpriteSys(0); // Top screen
NF_InitSpriteSys(1); // Inicializa los sprites para la pantalla inferior NF_InitSpriteSys(1); // Bottom screen
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM // Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla superior NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256); // Carga el fondo para la capa 3, pantalla inferior NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256);
NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256); // Carga el fondo para la capa 2, pantalla inferior NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256);
// Load sprite files from NitroFS
// Carga los archivos de sprites desde la FAT / NitroFS a la RAM NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64);
NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64); // Personaje
NF_LoadSpritePal("sprite/personaje", 0); NF_LoadSpritePal("sprite/personaje", 0);
NF_LoadSpriteGfx("sprite/bola", 1, 32, 32); // Bola azul NF_LoadSpriteGfx("sprite/bola", 1, 32, 32);
NF_LoadSpritePal("sprite/bola", 1); NF_LoadSpritePal("sprite/bola", 1);
// Create top screen background
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "nfl"); NF_CreateTiledBg(0, 3, "nfl");
// Crea los fondos de la pantalla inferior
// Create bottom screen backgrounds
NF_CreateTiledBg(1, 3, "capa_3"); NF_CreateTiledBg(1, 3, "capa_3");
NF_CreateTiledBg(1, 2, "capa_2"); NF_CreateTiledBg(1, 2, "capa_2");
// Transfer the required sprites to VRAM
// Transfiere a la VRAM los sprites necesarios NF_VramSpriteGfx(1, 0, 0, true); // Ball: Keep all frames in VRAM
NF_VramSpriteGfx(1, 0, 0, true); // Personaje (mantiene los frames en RAM) Pantalla inferior
NF_VramSpritePal(1, 0, 0); NF_VramSpritePal(1, 0, 0);
NF_VramSpriteGfx(0, 1, 0, false); // Personaje (mantiene los frames en RAM) Pantalla inferior NF_VramSpriteGfx(0, 1, 0, false); // Character: Keep unused frames in RAM
NF_VramSpritePal(0, 1, 0); NF_VramSpritePal(0, 1, 0);
// Habilita el canal Alpha // Enable alpha
//REG_BLDCNT = BLEND_ALPHA | BLEND_SRC_BG2 | (BLEND_DST_BG3 + BLEND_DST_SPRITE); // Alpha del fondo 2 sobre el fondo 3 y los sprites (Main Screen) //REG_BLDCNT = BLEND_ALPHA // Layer 2 over layer 3 and sprites (top screen)
REG_BLDCNT_SUB = BLEND_ALPHA | BLEND_SRC_BG2 | BLEND_DST_BG3; // Alpha del fondo 2 sobre el 3 (Sub Screen) // | BLEND_SRC_BG2
// Nivel de Alpha // | BLEND_DST_BG3 | BLEND_DST_SPRITE;
//REG_BLDALPHA = 0x05 | (0x0F << 8); // Nivel de alpha (5 sobre 15) en Main Screen REG_BLDCNT_SUB = BLEND_ALPHA // Layer 2 over layer 3 (bottom screen)
REG_BLDALPHA_SUB = 0x00 | (0x0F << 8); // Nivel de alpha (0 sobre 15) en Sub Screen | BLEND_SRC_BG2
| BLEND_DST_BG3;
// Alpha value
//REG_BLDALPHA = 0x05 | (0x0F << 8); // Top screen (5 / 15)
REG_BLDALPHA_SUB = 0x00 | (0x0F << 8); // Bottom screen (0 / 15)
// Variables
// Variables generales y inicializacion del random
u8 n = 0;
s8 blink = 1; s8 blink = 1;
u8 alpha = 0; u8 alpha = 0;
u8 alpha_timer = 0; u8 alpha_timer = 0;
s8 alpha_inc = 1; s8 alpha_inc = 1;
srand(time(NULL));
// Crea el sprite del personaje en pantalla // Setup character sprite
s16 pj_x = 0; s16 pj_x = 0;
s16 pj_y = 127; s16 pj_y = 127;
u8 pj_frame = 0; u8 pj_frame = 0;
@ -132,83 +96,97 @@ int main(int argc, char **argv) {
s8 pj_speed = 1; s8 pj_speed = 1;
NF_CreateSprite(1, 0, 0, 0, pj_x, pj_y); NF_CreateSprite(1, 0, 0, 0, pj_x, pj_y);
// Crea las bolas en la pantalla superior // Setup ball sprites
s16 bola_x[32]; s16 bola_x[32];
s16 bola_y[32]; s16 bola_y[32];
s8 bola_spx[32]; s8 bola_spx[32];
s8 bola_spy[32]; s8 bola_spy[32];
for (n = 0; n < 32; n ++) {
bola_x[n] = (rand() % 223); for (int n = 0; n < 32; n++)
bola_y[n] = (rand() % 159); {
bola_x[n] = rand() % 223;
bola_y[n] = rand() % 159;
bola_spx[n] = (rand() % 3) + 1; bola_spx[n] = (rand() % 3) + 1;
bola_spy[n] = (rand() % 3) + 1; bola_spy[n] = (rand() % 3) + 1;
NF_CreateSprite(0, n, 0, 0, bola_x[n], bola_y[n]); NF_CreateSprite(0, n, 0, 0, bola_x[n], bola_y[n]);
} }
while (1)
// Bucle (repite para siempre) {
while(1) { // Move character
// Mueve el personaje
pj_x += pj_speed; pj_x += pj_speed;
if ((pj_x < 0) || (pj_x > 191)) { if ((pj_x < 0) || (pj_x > 191))
{
pj_speed *= -1; pj_speed *= -1;
if (pj_speed > 0) { if (pj_speed > 0)
NF_HflipSprite(1, 0, false); NF_HflipSprite(1, 0, false);
} else { else
NF_HflipSprite(1, 0, true); NF_HflipSprite(1, 0, true);
} }
}
NF_MoveSprite(1, 0, pj_x, pj_y); NF_MoveSprite(1, 0, pj_x, pj_y);
// Animacion del personaje // Animate character
pj_anim ++; pj_anim++;
if (pj_anim > 5) { if (pj_anim > 5)
{
pj_anim = 0; pj_anim = 0;
pj_frame ++; pj_frame++;
if (pj_frame > 11) pj_frame = 0; if (pj_frame > 11)
pj_frame = 0;
NF_SpriteFrame(1, 0, pj_frame); NF_SpriteFrame(1, 0, pj_frame);
} }
// Mueve las bolas // Move balls
for (n = 0; n < 32; n ++) { for (int n = 0; n < 32; n ++)
{
bola_x[n] += bola_spx[n]; bola_x[n] += bola_spx[n];
if ((bola_x[n] < 0) || (bola_x[n] > 223)) bola_spx[n] *= -1; if ((bola_x[n] < 0) || (bola_x[n] > 223))
bola_spx[n] *= -1;
bola_y[n] += bola_spy[n]; bola_y[n] += bola_spy[n];
if ((bola_y[n] < 0) || (bola_y[n] > 159)) bola_spy[n] *= -1; if ((bola_y[n] < 0) || (bola_y[n] > 159))
bola_spy[n] *= -1;
NF_MoveSprite(0, n, bola_x[n], bola_y[n]); NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
// Efecto "Fake alpha" en las ultimas 15 bolas
if (n < 15) { // Fake alpha effect in the last 15 balls. This is done by showing
if ((blink > 0)) { // the balls every other frame. This only looks fine in old LCD
// screens with long refresh times. In old DS models it looks better
// than 2DS/3DS and emulators for PC.
if (n < 15)
{
if (blink)
NF_ShowSprite(0, n, true); NF_ShowSprite(0, n, true);
} else { else
NF_ShowSprite(0, n, false); NF_ShowSprite(0, n, false);
} }
} }
} blink ^= 1;
blink *= -1;
// Efecto Ghost del fondo (Alpha channel) // "Dissolve" background effect
alpha_timer ++; alpha_timer ++;
if (alpha_timer > 5) { if (alpha_timer > 5)
{
alpha_timer = 0; alpha_timer = 0;
alpha += alpha_inc; alpha += alpha_inc;
if ((alpha == 0) || (alpha == 14)) alpha_inc *= -1; if ((alpha == 0) || (alpha == 14))
REG_BLDALPHA_SUB = alpha | (0x0F << 8); // Nivel de alpha (sobre 15) en Sub Screen alpha_inc *= -1;
// Alpha level in bottom screen (the max is 15)
REG_BLDALPHA_SUB = alpha | (0x0F << 8);
} }
// Actualiza el array de OAM // Update OAM array
NF_SpriteOamSet(0); NF_SpriteOamSet(0);
NF_SpriteOamSet(1); NF_SpriteOamSet(1);
swiWaitForVBlank(); // Espera al sincronismo vertical // Wait for the screen refresh
swiWaitForVBlank();
// Actualiza el OAM // Update OAM
oamUpdate(&oamMain); oamUpdate(&oamMain);
oamUpdate(&oamSub); oamUpdate(&oamSub);
} }
return 0; return 0;
} }

View File

@ -1,76 +1,130 @@
// 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 animating tiled backgrounds.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de fondos animados (Tile animation)
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 SPEED 2 // Scroll speed
#define MAP_X 16 // Map width (animated blocks are 4x4, 64 / 4 = 16)
#define MAP_Y 16 // Map height (animated blocks are 4x4, 64 / 4 = 16)
#define WATER_FRAMES 50 // Number of frames of the animation
#define WATER_DELAY 10 // Animation speed (number of frames to wait to change)
// Algunos defines interesantes // Global variables
#define SPEED 2 // Velocidad del scroll
#define MAP_X 16 // Ancho del mapa (bloques de animacion de 4x4 tiles)
#define MAP_Y 16 // Alto del mapa (bloques de animacion de 4x4 tiles)
#define WATER_FRAMES 50 // Frames totales de la animacion
#define WATER_DELAY 10 // Velocidad de la animacion (espera entre frames)
// Declara funciones
void InitAnimatedBg(void); // Inicializa la animacion
void AnimateWater(void); // Animacion del fondo
// Declara las variables globales
u8 WATER_SPEED; u8 WATER_SPEED;
u8 WATER_FRAME[MAP_X][MAP_Y]; // 512 pixeles, 64 tiles, cada frame son 4x4 tiles u8 WATER_FRAME[MAP_X][MAP_Y]; // 512 pixels, 64 tiles, every frame is 4x4 tiles
// Initialize animated background
void InitAnimatedBg(void)
{
// Initialize water animations
for (int y = 0; y < MAP_Y; y++)
{
for (int x = 0; x < MAP_X; x++)
WATER_FRAME[x][y] = rand() % (WATER_FRAMES + 1);
}
// Generate map of water background
for (int y = 0; y < MAP_Y; y ++)
{
for (int x = 0; x < MAP_X; x ++)
{
// Calculate the map 4x4 region to fill
int start_x = x << 2;
int end_x = start_x + 4;
int start_y = y << 2;
int end_y = start_y + 4;
// Displacement
int n = 0;
// Fill the 4x4 region
for (int tile_y = start_y; tile_y < end_y; tile_y++)
{
for (int tile_x = start_x; tile_x < end_x; tile_x++)
{
// The animation has 11 frames. Any number over the limit
// will display the "rest" frame.
int frame = WATER_FRAME[x][y];
if (frame > 10)
frame = 10;
NF_SetTileOfMap(1, 3, tile_x, tile_y, (frame << 4) + n);
n++;
}
}
}
}
/* // Update map in VRAM
------------------------------------------------- NF_UpdateVramMap(1, 3);
Main() - Bloque general del programa }
-------------------------------------------------
*/
int main(int argc, char **argv) { // Handle tiled background animation
void AnimateWater(void)
{
// Check if we need to do an animation step
WATER_SPEED++;
// Pantalla de espera inicializando NitroFS if (WATER_SPEED < WATER_DELAY)
return;
WATER_SPEED = 0;
// Change the required tiles for the animation
for (int y = 0; y < MAP_Y; y ++)
{
for (int x = 0; x < MAP_X; x ++)
{
// Calculate the map 4x4 region to fill
int start_x = x << 2;
int end_x = start_x + 4;
int start_y = y << 2;
int end_y = start_y + 4;
// CAlculate the frame to draw
WATER_FRAME[x][y]++;
if (WATER_FRAME[x][y] > WATER_FRAMES)
WATER_FRAME[x][y] = 0;
if (WATER_FRAME[x][y] <= 10)
{
// Displacement
int n = 0;
// Fill the 4x4 region
for (int tile_y = start_y; tile_y < end_y; tile_y++)
{
for (int tile_x = start_x; tile_x < end_x; tile_x++)
{
NF_SetTileOfMap(1, 3, tile_x, tile_y, (WATER_FRAME[x][y] << 4) + n);
n++;
}
}
}
}
}
// Update map in VRAM
NF_UpdateVramMap(1, 3);
}
int main(int argc, char **argv)
{
// Set random seed based on the current time
srand(time(NULL));
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
consoleDemoInit(); consoleDemoInit();
@ -78,190 +132,78 @@ 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");
// Inicializa el motor 2D // Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(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
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior NF_InitTiledBgSys(1); // Bottom screen
// Carga los archivos de fondo desde la FAT / NitroFS // Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla superior NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
NF_LoadTilesForBg("bg/water", "water", 512, 512, 0, 175); // Carga el tileset para el agua NF_LoadTilesForBg("bg/water", "water", 512, 512, 0, 175);
// Crea los fondos de la pantalla superior // Create top screen background
NF_CreateTiledBg(0, 3, "nfl"); NF_CreateTiledBg(0, 3, "nfl");
// Crea los fondos de la pantalla inferior // Create bottom screen backgrounds
NF_CreateTiledBg(1, 3, "water"); NF_CreateTiledBg(1, 3, "water");
// Inicializa la animacion del fondo // Initialize background animation
InitAnimatedBg(); InitAnimatedBg();
// Variables // Variables
s16 bg_x = 0; s16 bg_x = 0;
s16 bg_y = 0; s16 bg_y = 0;
u16 keys = 0; while (1)
{
scanKeys(); // Read keypad
u16 keys = keysHeld();
// Scroll background
// Bucle (repite para siempre) if (keys & KEY_LEFT)
while(1) { {
// Lee el keypad
scanKeys();
keys = keysHeld(); // Teclas presionadas
// Si pulsas izquierda
if (keys & KEY_LEFT) {
bg_x -= SPEED; bg_x -= SPEED;
if (bg_x < 0) bg_x = 0; if (bg_x < 0)
bg_x = 0;
} }
// Si pulsas derecha if (keys & KEY_RIGHT)
if (keys & KEY_RIGHT) { {
bg_x += SPEED; bg_x += SPEED;
if (bg_x > 255) bg_x = 255; // Limite fisico de la capa if (bg_x > 255)
bg_x = 255;
} }
// Si pulsas arriba if (keys & KEY_UP)
if (keys & KEY_UP) { {
bg_y -= SPEED; bg_y -= SPEED;
if (bg_y < 0) bg_y = 0; if (bg_y < 0)
bg_y = 0;
} }
// Si pulsas abajo if (keys & KEY_DOWN)
if (keys & KEY_DOWN) { {
bg_y += SPEED; bg_y += SPEED;
if (bg_y > 255) bg_y = 255; // Limite fisico de la capa if (bg_y > 255)
bg_y = 255;
} }
// Anima el fondo // Animate background
AnimateWater(); AnimateWater();
swiWaitForVBlank(); // Espera al sincronismo vertical // Wait for the screen refresh
swiWaitForVBlank();
// Actualiza la posicion de los fondos // Scroll background
NF_ScrollBg(1, 3, bg_x, bg_y); NF_ScrollBg(1, 3, bg_x, bg_y);
} }
return 0; return 0;
}
// Funcion para inicializar el fondo animado
void InitAnimatedBg(void) {
// Variables locales
u8 x = 0;
u8 y = 0;
u8 tile_x = 0;
u8 tile_y = 0;
u8 start_x = 0;
u8 end_x = 0;
u8 start_y = 0;
u8 end_y = 0;
u8 n = 0;
u8 frame = 0;
// Inicializa la animacion del agua
srand(time(NULL));
for (y = 0; y < MAP_Y; y ++) {
for (x = 0; x < MAP_X; x ++) {
WATER_FRAME[x][y] = (rand() % (WATER_FRAMES + 1));
}
}
// Genera el mapa de el fondo marino
for (y = 0; y < MAP_Y; y ++) {
for (x = 0; x < MAP_X; x ++) {
// Calcula el area a rellenar
start_x = (x << 2);
end_x = start_x + 4;
start_y = (y << 2);
end_y = start_y +4;
// Desplazamiento
n = 0;
// Rellena la cuadricula de 4x4 tiles
for (tile_y = start_y; tile_y < end_y; tile_y ++) {
for (tile_x = start_x; tile_x < end_x; tile_x ++) {
frame = WATER_FRAME[x][y];
if (frame > 10) frame = 10; // La animacion tiene 11 frames, por encima de estos, muestra siempre el mismo (sensacion de "reposo")
NF_SetTileOfMap(1, 3, tile_x, tile_y, ((frame << 4) + n));
n ++;
}
}
}
}
// Actualiza el mapa en VRAM
NF_UpdateVramMap(1, 3);
}
// Funcion para animar el fondo mediante tiles
void AnimateWater(void) {
// Calcula el movimiento
WATER_SPEED ++;
// Si debes cambiar de frame...
if (WATER_SPEED >= WATER_DELAY) {
// Reset del contador de espera
WATER_SPEED = 0;
// Variables temporales
u8 x = 0;
u8 y = 0;
u8 tile_x = 0;
u8 tile_y = 0;
u8 start_x = 0;
u8 end_x = 0;
u8 start_y = 0;
u8 end_y = 0;
u8 n = 0;
// Cambia los tiles necesarios para realizar la animacion
for (y = 0; y < MAP_Y; y ++) {
for (x = 0; x < MAP_X; x ++) {
// Calcula el area a rellenar en este ciclo
start_x = (x << 2);
end_x = start_x + 4;
start_y = (y << 2);
end_y = start_y + 4;
// Y el frame a ejecutar
WATER_FRAME[x][y] ++;
if (WATER_FRAME[x][y] > WATER_FRAMES) WATER_FRAME[x][y] = 0;
if (WATER_FRAME[x][y] <= 10) {
// Desplazamiento
n = 0;
// Rellena la cuadricula de 4x4 tiles
for (tile_y = start_y; tile_y < end_y; tile_y ++) {
for (tile_x = start_x; tile_x < end_x; tile_x ++) {
NF_SetTileOfMap(1, 3, tile_x, tile_y, ((WATER_FRAME[x][y] << 4) + n));
n ++;
}
}
}
}
}
// Actualiza el mapa en la VRAM
NF_UpdateVramMap(1, 3);
}
} }

View File

@ -1,115 +1,74 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// 16-bit bitmap backbuffer example.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo basico de BackBuffer en 16bits (modo BITMAP)
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 <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
// Includes propietarios NDS
#include <nds.h> #include <nds.h>
// Includes librerias propias
#include <nf_lib.h> #include <nf_lib.h>
int main(int argc, char **argv)
{
// Initialize 2D engine in both screens and use mode 5
NF_Set2D(0, 5);
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Inicializa el motor 2D en modo BITMAP
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas
NF_Set2D(1, 5); NF_Set2D(1, 5);
// Inicializa los fondos en modo "BITMAP" // Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1); NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1); NF_InitBitmapBgSys(1, 1);
// Inicializa el BackBuffer de 16 bits en ambas pantallas // Initialize backbuffers
// Usalo solo una vez antes de habilitarlo
NF_Init16bitsBackBuffer(0); NF_Init16bitsBackBuffer(0);
NF_Init16bitsBackBuffer(1); NF_Init16bitsBackBuffer(1);
// Habilita el backbuffer de ambas pantallas // Enable backbuffers
NF_Enable16bitsBackBuffer(0); NF_Enable16bitsBackBuffer(0);
NF_Enable16bitsBackBuffer(1); NF_Enable16bitsBackBuffer(1);
u32 r = 0;
u32 g = 0;
u32 b = 0;
// Variables RGB while (1)
u8 r = 0; {
u8 g = 0; // Fill buffer
u8 b = 0; for (int y = 0; y < 256; y ++)
// Calcula el valor RGB {
u16 rgb = 0; for (int x = 0; x < 256; x ++)
// Otras {
s16 x = 0; // Calculate new color
s16 y = 0; r++;
if (r > 31)
while (1) { {
// Rellena el buffer
for (y = 0; y < 256; y ++) {
for (x = 0; x < 256; x ++) {
// Calcula el nuevo color
r ++;
if (r > 31) {
r = 0; r = 0;
g ++; g++;
if (g > 16) { if (g > 16)
g = 0; g = 0;
} }
} b = (y << 5) >> 8;
b = ((y << 5) >> 8);
// Calcula el valor RGB (Alpha + RGB555) // Compose RGB value
rgb = ((r)|((g) << 5)|((b) << 10)|(BIT(15))); u32 rgb = r | (g << 5) | (b << 10) | BIT(15);
// Escribelos en el buffer
NF_16BITS_BACKBUFFER[0][((y << 8) + x)] = rgb; // Write color to the backbuffer
NF_16BITS_BACKBUFFER[1][((x << 8) + y)] = rgb; NF_16BITS_BACKBUFFER[0][(y << 8) + x] = rgb;
NF_16BITS_BACKBUFFER[1][(x << 8) + y] = rgb;
} }
} }
// Copia el contenido del Backbuffer a la VRAM // Send backbuffers to the screen
NF_Flip16bitsBackBuffer(0); NF_Flip16bitsBackBuffer(0);
NF_Flip16bitsBackBuffer(1); NF_Flip16bitsBackBuffer(1);
// Wait for the screen refresh
swiWaitForVBlank(); swiWaitForVBlank();
} }
return 0; return 0;
} }

View File

@ -1,59 +1,22 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
// SPDX-FileContributor: NightFox & Co., 2009-2011 // SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Basic example of using a 16-bit bitmap with a backbuffer and loading images.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo basico de BackBuffer en 16bits (modo BITMAP)
con carga de archivos de imagen
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 <string.h> #include <string.h>
#include <unistd.h> #include <unistd.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>
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();
@ -61,106 +24,102 @@ 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");
// Inicializa el motor 2D en modo BITMAP // Initialize 2D engine in both screens and use mode 5
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas NF_Set2D(0, 5);
NF_Set2D(1, 5); NF_Set2D(1, 5);
// Inicializa los fondos en modo "BITMAP" // Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1); NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1); NF_InitBitmapBgSys(1, 1);
// Inicializa los buffers para guardar fondos en formato BITMAP // Initialize storage buffers
NF_Init16bitsBgBuffers(); NF_Init16bitsBgBuffers();
// Inicializa el BackBuffer de 16 bits // Initialize backbuffer
// Usalo solo una vez antes de habilitarlo
NF_Init16bitsBackBuffer(1); NF_Init16bitsBackBuffer(1);
// Habilita el backbuffer en la pantalla superior // Enable backbuffer
NF_Enable16bitsBackBuffer(1); NF_Enable16bitsBackBuffer(1);
// Carga el archivo BITMAP de imagen en formato RAW a la RAM // Load bitmap background files from NitroFS
NF_Load16bitsBg("bmp/bitmap16", 0); NF_Load16bitsBg("bmp/bitmap16", 0);
// Tranfiere la imagen a la VRAM de la pantalla superior // Tranfer image to VRAM of the top screen
NF_Copy16bitsBuffer(0, 0, 0); NF_Copy16bitsBuffer(0, 0, 0);
// Tranfiere la imagen al BackBuffer de la pantalla inferior // Tranfer image to the backbuffer of the bottom screen
NF_Copy16bitsBuffer(1, 1, 0); NF_Copy16bitsBuffer(1, 1, 0);
// Variables RGB // Window location
u8 r = 0;
u8 g = 0;
u8 b = 0;
// Calcula el valor RGB
u16 rgb = 0;
// Ventana
s16 x = 0;
s16 y = 0;
s16 composite = 0;
s16 square_x = 0; s16 square_x = 0;
s16 square_y = 0; s16 square_y = 0;
// Variables del control del touchpad while (1)
u16 keys = 0; {
touchPosition touchscreen; // Copy original image
while (1) {
// Copia el original
NF_Copy16bitsBuffer(1, 1, 0); NF_Copy16bitsBuffer(1, 1, 0);
// Lectura de posicion del stylus // Read keys and touchscreen
scanKeys(); // Lee el touchpad via Libnds scanKeys();
touchPosition touchscreen;
touchRead(&touchscreen); touchRead(&touchscreen);
keys = keysHeld(); // Verifica el estado del touchscreen u16 keys = keysHeld();
if (keys & KEY_TOUCH) { if (keys & KEY_TOUCH)
square_x = (touchscreen.px - 32); {
square_y = (touchscreen.py - 32); square_x = touchscreen.px - 32;
square_y = touchscreen.py - 32;
} }
// Calcula la ventana // Restrict coordinates of the window
if (square_x < 0) square_x = 0; if (square_x < 0)
if (square_x > 191) square_x = 191; square_x = 0;
if (square_y < 0) square_y = 0; if (square_x > 191)
if (square_y > 127) square_y = 127; square_x = 191;
// Rellena el buffer if (square_y < 0)
for (y = square_y; y < (square_y + 64); y ++) { square_y = 0;
for (x = square_x; x < (square_x + 64); x ++) { if (square_y > 127)
// Obten el color actual square_y = 127;
rgb = NF_16BITS_BACKBUFFER[1][((y << 8) + x)];
r = (rgb & 0x1F); // Fill buffer
g = ((rgb >> 5) & 0x1F); for (int y = square_y; y < (square_y + 64); y ++)
b = ((rgb >> 10) & 0x1F); {
// Genera el equivalente a blanco y negro y sube el brillo 3 puntos for (int x = square_x; x < (square_x + 64); x ++)
composite = ((int)((r + g + b) / 3) + 3); {
if (composite > 31) composite = 31; // Get current color
// Reemplaza los valores RGB u32 rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
u32 r = rgb & 0x1F;
u32 g = (rgb >> 5) & 0x1F;
u32 b = (rgb >> 10) & 0x1F;
// Generate a grayscale value based on the RGB components
u32 composite = ((r + g + b) / 3) + 3;
if (composite > 31)
composite = 31;
// Replace the RGB values by the grayscale value (this shows up
// as a rectangular window on the screen)
r = composite; r = composite;
g = composite; g = composite;
b = composite; b = composite;
// Calcula el valor RGB (Alpha + RGB555)
rgb = ((r)|((g) << 5)|((b) << 10)|(BIT(15))); // Pack the components as a RGB value
// Escribelos en el buffer rgb = r | (g << 5)| (b << 10) | BIT(15);
NF_16BITS_BACKBUFFER[1][((y << 8) + x)] = rgb;
// Write RGB value in the backbuffer
NF_16BITS_BACKBUFFER[1][(y << 8) + x] = rgb;
} }
} }
// Copia el contenido del Backbuffer a la VRAM // Swap backbuffer and visible buffers
NF_Flip16bitsBackBuffer(1); NF_Flip16bitsBackBuffer(1);
// Sincronismo Vertical // Wait for the screen refresh
swiWaitForVBlank(); swiWaitForVBlank();
} }
return 0; return 0;
} }

View File

@ -15,6 +15,9 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
// Set random seed based on the current time
srand(time(NULL));
// Prepare a NitroFS initialization screen // Prepare a NitroFS initialization screen
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
@ -27,7 +30,7 @@ int main(int argc, char **argv)
nitroFSInit(NULL); nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); NF_SetRootFolder("NITROFS");
// Inicialize 2D engine in both screens and use mode 0 // Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0); NF_Set2D(0, 0);
NF_Set2D(1, 0); NF_Set2D(1, 0);
@ -61,15 +64,12 @@ int main(int argc, char **argv)
NF_CreateTiledBg(1, 2, "capa_2"); NF_CreateTiledBg(1, 2, "capa_2");
// Transfer the required sprites to VRAM // Transfer the required sprites to VRAM
NF_VramSpriteGfx(1, 0, 0, true); // Ball: Keep unused frames in RAM NF_VramSpriteGfx(1, 0, 0, true); // Ball: Keep all frames in VRAM
NF_VramSpritePal(1, 0, 0); NF_VramSpritePal(1, 0, 0);
NF_VramSpriteGfx(0, 1, 0, false); // Character: Keep unused frames in VRAM NF_VramSpriteGfx(0, 1, 0, false); // Character: Keep unused frames in RAM
NF_VramSpritePal(0, 1, 0); NF_VramSpritePal(0, 1, 0);
// Set random seed based on the current time
srand(time(NULL));
// Setup character sprite // Setup character sprite
s16 pj_x = 0; s16 pj_x = 0;
s16 pj_y = 127; s16 pj_y = 127;
@ -108,7 +108,7 @@ int main(int argc, char **argv)
NF_MoveSprite(1, 0, pj_x, pj_y); NF_MoveSprite(1, 0, pj_x, pj_y);
// Animate character // Animate character
pj_anim ++; pj_anim++;
if (pj_anim > 5) if (pj_anim > 5)
{ {
pj_anim = 0; pj_anim = 0;