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,214 +1,192 @@
// SPDX-License-Identifier: CC0-1.0
//
// 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 <time.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#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
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");
// Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0);
NF_Set2D(1, 0);
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
int main(int argc, char **argv) {
// Initialize sprite system
NF_InitSpriteBuffers(); // Initialize storage buffers
NF_InitSpriteSys(0); // Top screen
NF_InitSpriteSys(1); // Bottom screen
// 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();
// Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256);
NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256);
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Load sprite files from NitroFS
NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64);
NF_LoadSpritePal("sprite/personaje", 0);
// Inicializa el motor 2D
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
NF_Set2D(1, 0);
NF_LoadSpriteGfx("sprite/bola", 1, 32, 32);
NF_LoadSpritePal("sprite/bola", 1);
// 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); // Iniciliaza los fondos Tileados para la pantalla inferior
// Create top screen background
NF_CreateTiledBg(0, 3, "nfl");
// Inicializa los Sprites
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas
NF_InitSpriteSys(0); // Inicializa los sprites para la pantalla superior
NF_InitSpriteSys(1); // Inicializa los sprites para la pantalla inferior
// Create bottom screen backgrounds
NF_CreateTiledBg(1, 3, "capa_3");
NF_CreateTiledBg(1, 2, "capa_2");
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla superior
NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256); // Carga el fondo para la capa 3, pantalla inferior
NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256); // Carga el fondo para la capa 2, pantalla inferior
// Transfer the required sprites to VRAM
NF_VramSpriteGfx(1, 0, 0, true); // Ball: Keep all frames in VRAM
NF_VramSpritePal(1, 0, 0);
NF_VramSpriteGfx(0, 1, 0, false); // Character: Keep unused frames in RAM
NF_VramSpritePal(0, 1, 0);
// Carga los archivos de sprites desde la FAT / NitroFS a la RAM
NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64); // Personaje
NF_LoadSpritePal("sprite/personaje", 0);
// Enable alpha
//REG_BLDCNT = BLEND_ALPHA // Layer 2 over layer 3 and sprites (top screen)
// | BLEND_SRC_BG2
// | BLEND_DST_BG3 | BLEND_DST_SPRITE;
REG_BLDCNT_SUB = BLEND_ALPHA // Layer 2 over layer 3 (bottom screen)
| BLEND_SRC_BG2
| BLEND_DST_BG3;
NF_LoadSpriteGfx("sprite/bola", 1, 32, 32); // Bola azul
NF_LoadSpritePal("sprite/bola", 1);
// Alpha value
//REG_BLDALPHA = 0x05 | (0x0F << 8); // Top screen (5 / 15)
REG_BLDALPHA_SUB = 0x00 | (0x0F << 8); // Bottom screen (0 / 15)
// Variables
s8 blink = 1;
u8 alpha = 0;
u8 alpha_timer = 0;
s8 alpha_inc = 1;
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "nfl");
// Crea los fondos de la pantalla inferior
NF_CreateTiledBg(1, 3, "capa_3");
NF_CreateTiledBg(1, 2, "capa_2");
// Setup character sprite
s16 pj_x = 0;
s16 pj_y = 127;
u8 pj_frame = 0;
u8 pj_anim = 0;
s8 pj_speed = 1;
NF_CreateSprite(1, 0, 0, 0, pj_x, pj_y);
// Setup ball sprites
s16 bola_x[32];
s16 bola_y[32];
s8 bola_spx[32];
s8 bola_spy[32];
// Transfiere a la VRAM los sprites necesarios
NF_VramSpriteGfx(1, 0, 0, true); // Personaje (mantiene los frames en RAM) Pantalla inferior
NF_VramSpritePal(1, 0, 0);
for (int n = 0; n < 32; n++)
{
bola_x[n] = rand() % 223;
bola_y[n] = rand() % 159;
bola_spx[n] = (rand() % 3) + 1;
bola_spy[n] = (rand() % 3) + 1;
NF_CreateSprite(0, n, 0, 0, bola_x[n], bola_y[n]);
}
NF_VramSpriteGfx(0, 1, 0, false); // Personaje (mantiene los frames en RAM) Pantalla inferior
NF_VramSpritePal(0, 1, 0);
while (1)
{
// Move character
pj_x += pj_speed;
if ((pj_x < 0) || (pj_x > 191))
{
pj_speed *= -1;
if (pj_speed > 0)
NF_HflipSprite(1, 0, false);
else
NF_HflipSprite(1, 0, true);
}
NF_MoveSprite(1, 0, pj_x, pj_y);
// Habilita el canal 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_SUB = BLEND_ALPHA | BLEND_SRC_BG2 | BLEND_DST_BG3; // Alpha del fondo 2 sobre el 3 (Sub Screen)
// Nivel de Alpha
//REG_BLDALPHA = 0x05 | (0x0F << 8); // Nivel de alpha (5 sobre 15) en Main Screen
REG_BLDALPHA_SUB = 0x00 | (0x0F << 8); // Nivel de alpha (0 sobre 15) en Sub Screen
// Animate character
pj_anim++;
if (pj_anim > 5)
{
pj_anim = 0;
pj_frame++;
if (pj_frame > 11)
pj_frame = 0;
NF_SpriteFrame(1, 0, pj_frame);
}
// Move balls
for (int n = 0; n < 32; n ++)
{
bola_x[n] += bola_spx[n];
if ((bola_x[n] < 0) || (bola_x[n] > 223))
bola_spx[n] *= -1;
bola_y[n] += bola_spy[n];
if ((bola_y[n] < 0) || (bola_y[n] > 159))
bola_spy[n] *= -1;
// Variables generales y inicializacion del random
u8 n = 0;
s8 blink = 1;
u8 alpha = 0;
u8 alpha_timer = 0;
s8 alpha_inc = 1;
srand(time(NULL));
NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
// Crea el sprite del personaje en pantalla
s16 pj_x = 0;
s16 pj_y = 127;
u8 pj_frame = 0;
u8 pj_anim = 0;
s8 pj_speed = 1;
NF_CreateSprite(1, 0, 0, 0, pj_x, pj_y);
// Fake alpha effect in the last 15 balls. This is done by showing
// 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);
else
NF_ShowSprite(0, n, false);
}
}
blink ^= 1;
// Crea las bolas en la pantalla superior
s16 bola_x[32];
s16 bola_y[32];
s8 bola_spx[32];
s8 bola_spy[32];
for (n = 0; n < 32; n ++) {
bola_x[n] = (rand() % 223);
bola_y[n] = (rand() % 159);
bola_spx[n] = (rand() % 3) + 1;
bola_spy[n] = (rand() % 3) + 1;
NF_CreateSprite(0, n, 0, 0, bola_x[n], bola_y[n]);
}
// "Dissolve" background effect
alpha_timer ++;
if (alpha_timer > 5)
{
alpha_timer = 0;
alpha += alpha_inc;
if ((alpha == 0) || (alpha == 14))
alpha_inc *= -1;
// Alpha level in bottom screen (the max is 15)
REG_BLDALPHA_SUB = alpha | (0x0F << 8);
}
// Bucle (repite para siempre)
while(1) {
// Update OAM array
NF_SpriteOamSet(0);
NF_SpriteOamSet(1);
// Mueve el personaje
pj_x += pj_speed;
if ((pj_x < 0) || (pj_x > 191)) {
pj_speed *= -1;
if (pj_speed > 0) {
NF_HflipSprite(1, 0, false);
} else {
NF_HflipSprite(1, 0, true);
}
}
NF_MoveSprite(1, 0, pj_x, pj_y);
// Wait for the screen refresh
swiWaitForVBlank();
// Animacion del personaje
pj_anim ++;
if (pj_anim > 5) {
pj_anim = 0;
pj_frame ++;
if (pj_frame > 11) pj_frame = 0;
NF_SpriteFrame(1, 0, pj_frame);
}
// Mueve las bolas
for (n = 0; n < 32; n ++) {
bola_x[n] += bola_spx[n];
if ((bola_x[n] < 0) || (bola_x[n] > 223)) bola_spx[n] *= -1;
bola_y[n] += bola_spy[n];
if ((bola_y[n] < 0) || (bola_y[n] > 159)) bola_spy[n] *= -1;
NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
// Efecto "Fake alpha" en las ultimas 15 bolas
if (n < 15) {
if ((blink > 0)) {
NF_ShowSprite(0, n, true);
} else {
NF_ShowSprite(0, n, false);
}
}
}
blink *= -1;
// Efecto Ghost del fondo (Alpha channel)
alpha_timer ++;
if (alpha_timer > 5) {
alpha_timer = 0;
alpha += alpha_inc;
if ((alpha == 0) || (alpha == 14)) alpha_inc *= -1;
REG_BLDALPHA_SUB = alpha | (0x0F << 8); // Nivel de alpha (sobre 15) en Sub Screen
}
// Actualiza el array de OAM
NF_SpriteOamSet(0);
NF_SpriteOamSet(1);
swiWaitForVBlank(); // Espera al sincronismo vertical
// Actualiza el OAM
oamUpdate(&oamMain);
oamUpdate(&oamSub);
}
return 0;
// Update OAM
oamUpdate(&oamMain);
oamUpdate(&oamSub);
}
return 0;
}

View File

@ -1,267 +1,209 @@
// SPDX-License-Identifier: CC0-1.0
//
// 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 <time.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#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
#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
// Global variables
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++;
}
}
}
}
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// 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();
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Inicializa el motor 2D
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
NF_Set2D(1, 0);
// 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); // Iniciliaza los fondos Tileados para la pantalla inferior
// Carga los archivos de fondo desde la FAT / NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla superior
NF_LoadTilesForBg("bg/water", "water", 512, 512, 0, 175); // Carga el tileset para el agua
// Crea los fondos de la pantalla superior
NF_CreateTiledBg(0, 3, "nfl");
// Crea los fondos de la pantalla inferior
NF_CreateTiledBg(1, 3, "water");
// Inicializa la animacion del fondo
InitAnimatedBg();
// Variables
s16 bg_x = 0;
s16 bg_y = 0;
u16 keys = 0;
// Bucle (repite para siempre)
while(1) {
// Lee el keypad
scanKeys();
keys = keysHeld(); // Teclas presionadas
// Si pulsas izquierda
if (keys & KEY_LEFT) {
bg_x -= SPEED;
if (bg_x < 0) bg_x = 0;
}
// Si pulsas derecha
if (keys & KEY_RIGHT) {
bg_x += SPEED;
if (bg_x > 255) bg_x = 255; // Limite fisico de la capa
}
// Si pulsas arriba
if (keys & KEY_UP) {
bg_y -= SPEED;
if (bg_y < 0) bg_y = 0;
}
// Si pulsas abajo
if (keys & KEY_DOWN) {
bg_y += SPEED;
if (bg_y > 255) bg_y = 255; // Limite fisico de la capa
}
// Anima el fondo
AnimateWater();
swiWaitForVBlank(); // Espera al sincronismo vertical
// Actualiza la posicion de los fondos
NF_ScrollBg(1, 3, bg_x, bg_y);
}
return 0;
// Update map in VRAM
NF_UpdateVramMap(1, 3);
}
// Handle tiled background animation
void AnimateWater(void)
{
// Check if we need to do an animation step
WATER_SPEED++;
if (WATER_SPEED < WATER_DELAY)
return;
WATER_SPEED = 0;
// Funcion para inicializar el fondo animado
void InitAnimatedBg(void) {
// 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;
// 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;
// CAlculate the frame to draw
WATER_FRAME[x][y]++;
// 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));
}
}
if (WATER_FRAME[x][y] > WATER_FRAMES)
WATER_FRAME[x][y] = 0;
// 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 ++;
}
}
}
}
if (WATER_FRAME[x][y] <= 10)
{
// Displacement
int n = 0;
// Actualiza el mapa en VRAM
NF_UpdateVramMap(1, 3);
// 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(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Funcion para animar el fondo mediante tiles
void AnimateWater(void) {
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Calcula el movimiento
WATER_SPEED ++;
// Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0);
NF_Set2D(1, 0);
// Si debes cambiar de frame...
if (WATER_SPEED >= WATER_DELAY) {
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
// Reset del contador de espera
WATER_SPEED = 0;
// Load background files from NitroFS
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
NF_LoadTilesForBg("bg/water", "water", 512, 512, 0, 175);
// 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;
// Create top screen background
NF_CreateTiledBg(0, 3, "nfl");
// Create bottom screen backgrounds
NF_CreateTiledBg(1, 3, "water");
// 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 ++;
}
}
}
}
}
// Initialize background animation
InitAnimatedBg();
// Actualiza el mapa en la VRAM
NF_UpdateVramMap(1, 3);
// Variables
s16 bg_x = 0;
s16 bg_y = 0;
}
while (1)
{
scanKeys(); // Read keypad
u16 keys = keysHeld();
// Scroll background
if (keys & KEY_LEFT)
{
bg_x -= SPEED;
if (bg_x < 0)
bg_x = 0;
}
if (keys & KEY_RIGHT)
{
bg_x += SPEED;
if (bg_x > 255)
bg_x = 255;
}
if (keys & KEY_UP)
{
bg_y -= SPEED;
if (bg_y < 0)
bg_y = 0;
}
if (keys & KEY_DOWN)
{
bg_y += SPEED;
if (bg_y > 255)
bg_y = 255;
}
// Animate background
AnimateWater();
// Wait for the screen refresh
swiWaitForVBlank();
// Scroll background
NF_ScrollBg(1, 3, bg_x, bg_y);
}
return 0;
}

View File

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

View File

@ -1,166 +1,125 @@
// SPDX-License-Identifier: CC0-1.0
//
// 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 <string.h>
#include <unistd.h>
// Includes propietarios NDS
#include <nds.h>
#include <filesystem.h>
// Includes librerias propias
#include <nf_lib.h>
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
printf("\n NitroFS init. Please wait.\n\n");
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS");
// Initialize 2D engine in both screens and use mode 5
NF_Set2D(0, 5);
NF_Set2D(1, 5);
// Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1);
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
// Initialize storage buffers
NF_Init16bitsBgBuffers();
int main(int argc, char **argv) {
// Initialize backbuffer
NF_Init16bitsBackBuffer(1);
// 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();
// Enable backbuffer
NF_Enable16bitsBackBuffer(1);
// Define el ROOT e inicializa el sistema de archivos
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
// Load bitmap background files from NitroFS
NF_Load16bitsBg("bmp/bitmap16", 0);
// Inicializa el motor 2D en modo BITMAP
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas
NF_Set2D(1, 5);
// Tranfer image to VRAM of the top screen
NF_Copy16bitsBuffer(0, 0, 0);
// Tranfer image to the backbuffer of the bottom screen
NF_Copy16bitsBuffer(1, 1, 0);
// Inicializa los fondos en modo "BITMAP"
NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1);
// Window location
s16 square_x = 0;
s16 square_y = 0;
// Inicializa los buffers para guardar fondos en formato BITMAP
NF_Init16bitsBgBuffers();
while (1)
{
// Copy original image
NF_Copy16bitsBuffer(1, 1, 0);
// Inicializa el BackBuffer de 16 bits
// Usalo solo una vez antes de habilitarlo
NF_Init16bitsBackBuffer(1);
// Read keys and touchscreen
scanKeys();
touchPosition touchscreen;
touchRead(&touchscreen);
u16 keys = keysHeld();
if (keys & KEY_TOUCH)
{
square_x = touchscreen.px - 32;
square_y = touchscreen.py - 32;
}
// Habilita el backbuffer en la pantalla superior
NF_Enable16bitsBackBuffer(1);
// Restrict coordinates of the window
if (square_x < 0)
square_x = 0;
if (square_x > 191)
square_x = 191;
// Carga el archivo BITMAP de imagen en formato RAW a la RAM
NF_Load16bitsBg("bmp/bitmap16", 0);
if (square_y < 0)
square_y = 0;
if (square_y > 127)
square_y = 127;
// Tranfiere la imagen a la VRAM de la pantalla superior
NF_Copy16bitsBuffer(0, 0, 0);
// Tranfiere la imagen al BackBuffer de la pantalla inferior
NF_Copy16bitsBuffer(1, 1, 0);
// Fill buffer
for (int y = square_y; y < (square_y + 64); y ++)
{
for (int x = square_x; x < (square_x + 64); x ++)
{
// Get current color
u32 rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
u32 r = rgb & 0x1F;
u32 g = (rgb >> 5) & 0x1F;
u32 b = (rgb >> 10) & 0x1F;
// Variables RGB
u8 r = 0;
u8 g = 0;
u8 b = 0;
// Generate a grayscale value based on the RGB components
u32 composite = ((r + g + b) / 3) + 3;
if (composite > 31)
composite = 31;
// Calcula el valor RGB
u16 rgb = 0;
// Replace the RGB values by the grayscale value (this shows up
// as a rectangular window on the screen)
r = composite;
g = composite;
b = composite;
// Ventana
s16 x = 0;
s16 y = 0;
s16 composite = 0;
s16 square_x = 0;
s16 square_y = 0;
// Pack the components as a RGB value
rgb = r | (g << 5)| (b << 10) | BIT(15);
// Variables del control del touchpad
u16 keys = 0;
touchPosition touchscreen;
// Write RGB value in the backbuffer
NF_16BITS_BACKBUFFER[1][(y << 8) + x] = rgb;
}
}
while (1) {
// Swap backbuffer and visible buffers
NF_Flip16bitsBackBuffer(1);
// Copia el original
NF_Copy16bitsBuffer(1, 1, 0);
// Lectura de posicion del stylus
scanKeys(); // Lee el touchpad via Libnds
touchRead(&touchscreen);
keys = keysHeld(); // Verifica el estado del touchscreen
if (keys & KEY_TOUCH) {
square_x = (touchscreen.px - 32);
square_y = (touchscreen.py - 32);
}
// Calcula la ventana
if (square_x < 0) square_x = 0;
if (square_x > 191) square_x = 191;
if (square_y < 0) square_y = 0;
if (square_y > 127) square_y = 127;
// Rellena el buffer
for (y = square_y; y < (square_y + 64); y ++) {
for (x = square_x; x < (square_x + 64); x ++) {
// Obten el color actual
rgb = NF_16BITS_BACKBUFFER[1][((y << 8) + x)];
r = (rgb & 0x1F);
g = ((rgb >> 5) & 0x1F);
b = ((rgb >> 10) & 0x1F);
// Genera el equivalente a blanco y negro y sube el brillo 3 puntos
composite = ((int)((r + g + b) / 3) + 3);
if (composite > 31) composite = 31;
// Reemplaza los valores RGB
r = composite;
g = composite;
b = composite;
// Calcula el valor RGB (Alpha + RGB555)
rgb = ((r)|((g) << 5)|((b) << 10)|(BIT(15)));
// Escribelos en el buffer
NF_16BITS_BACKBUFFER[1][((y << 8) + x)] = rgb;
}
}
// Copia el contenido del Backbuffer a la VRAM
NF_Flip16bitsBackBuffer(1);
// Sincronismo Vertical
swiWaitForVBlank();
}
return 0;
// Wait for the screen refresh
swiWaitForVBlank();
}
return 0;
}

View File

@ -15,6 +15,9 @@
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(1, 0);
@ -27,7 +30,7 @@ int main(int argc, char **argv)
nitroFSInit(NULL);
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(1, 0);
@ -61,15 +64,12 @@ int main(int argc, char **argv)
NF_CreateTiledBg(1, 2, "capa_2");
// 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_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);
// Set random seed based on the current time
srand(time(NULL));
// Setup character sprite
s16 pj_x = 0;
s16 pj_y = 127;
@ -108,7 +108,7 @@ int main(int argc, char **argv)
NF_MoveSprite(1, 0, pj_x, pj_y);
// Animate character
pj_anim ++;
pj_anim++;
if (pj_anim > 5)
{
pj_anim = 0;