examples: Cleanup and translate more examples to English

This commit is contained in:
Antonio Niño Díaz 2023-05-21 02:25:53 +01:00
parent af329f901a
commit 4d4cb6ab8e
6 changed files with 423 additions and 562 deletions

View File

@ -85,9 +85,9 @@ int main(int argc, char **argv)
square_y = 127;
// Fill buffer
for (int y = square_y; y < (square_y + 64); y ++)
for (int y = square_y; y < square_y + 64; y++)
{
for (int x = square_x; x < (square_x + 64); x ++)
for (int x = square_x; x < square_x + 64; x++)
{
// Get current color
u32 rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
@ -107,7 +107,7 @@ int main(int argc, char **argv)
b = composite;
// Pack the components as a RGB value
rgb = r | (g << 5)| (b << 10) | BIT(15);
rgb = r | (g << 5) | (b << 10) | BIT(15);
// Write RGB value in the backbuffer
NF_16BITS_BACKBUFFER[1][(y << 8) + x] = rgb;

View File

@ -1,60 +1,23 @@
// 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.
// It shows two images with a window effect.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo basico de BackBuffer en 16bits (modo BITMAP)
con carga de archivos de imagen.
Efecto de visualizar dos imagenes con efecto ventana.
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>
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Pantalla de espera inicializando NitroFS
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
@ -62,114 +25,116 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
NF_SetRootFolder("NITROFS");
// Inicializa el motor 2D en modo BITMAP
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas
// Initialize 2D engine in both screens and use mode 5
NF_Set2D(0, 5);
NF_Set2D(1, 5);
// Inicializa los fondos en modo "BITMAP"
// Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1);
// Inicializa los buffers para guardar fondos en formato BITMAP
// Initialize storage buffers
NF_Init16bitsBgBuffers();
// Inicializa el BackBuffer de 16 bits
// Usalo solo una vez antes de habilitarlo
// Initialize backbuffer
NF_Init16bitsBackBuffer(1);
// Habilita el backbuffer en la pantalla superior
// Enable backbuffer
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/img16_a", 1);
NF_Load16bitsBg("bmp/img16_b", 2);
// Tranfiere la imagen a la VRAM de ambas pantallas
// Tranfer image to VRAM of both screens
NF_Copy16bitsBuffer(0, 0, 0);
NF_Copy16bitsBuffer(1, 1, 2);
// Si no es necesario usarla mas, borrala de la RAM
// It's not needed to use it any longer, so remove it from RAM
NF_Unload16bitsBg(0);
// Variables del control del touchpad
u16 keys = 0;
touchPosition touchscreen;
// Variables del control de la ventana
u32 move = 0;
s16 y = 0;
// Variables to control the window
s16 xa = 0;
s16 xb = 0;
s16 ya = 0;
s16 yb = 0;
s16 sqr_xa = 0;
s16 sqr_xb = 0;
s16 sqr_ya = 0;
s16 sqr_yb = 0;
bool in_touch = false;
// Repite para siempre
while (1) {
// Copia al backbuffer la imagen de arriba
while (1)
{
// Copy original image to the backbuffer of the top screen
NF_Copy16bitsBuffer(1, 1, 2);
// Lectura de posicion del stylus
scanKeys(); // Lee el touchpad via Libnds
// Read keys and touchscreen
scanKeys();
touchPosition touchscreen;
touchRead(&touchscreen);
keys = keysHeld(); // Verifica el estado del touchscreen
if (keys & KEY_TOUCH) { // Si se toca el touchpad
if (!in_touch) { // Y es el primer toque
xa = touchscreen.px; // Guarda el punto
ya = touchscreen.py;
in_touch = true; // e indicalo
}
xb = touchscreen.px; // Guarda el segundo punto
yb = touchscreen.py;
} else {
in_touch = false; // Ya no se esta tocando el touchpad
}
u16 keys_held = keysHeld();
u16 keys_down = keysDown();
// Si se ha tocado el touchpad y la ventana es del tamaño suficiente...
if (in_touch && (xa != xb) && (ya != yb)) {
// Calcula los limites de la ventana
if (xa < xb) {
if (keys_down & KEY_TOUCH)
{
// If this is the first time the user presses the screen, save that
// point as one corner of the window.
xa = touchscreen.px;
ya = touchscreen.py;
}
else if (keys_held & KEY_TOUCH)
{
// Save the other corner of the window
xb = touchscreen.px;
yb = touchscreen.py;
// If the two points aren't the same
if ((xa != xb) && (ya != yb))
{
int sqr_xa, sqr_xb, sqr_ya, sqr_yb;
// Calculate window bounds
if (xa < xb)
{
sqr_xa = xa;
sqr_xb = xb;
} else {
}
else
{
sqr_xa = xb;
sqr_xb = xa;
}
if (ya < yb) {
if (ya < yb)
{
sqr_ya = ya;
sqr_yb = yb;
} else {
}
else
{
sqr_ya = yb;
sqr_yb = ya;
}
// Ahora dibuja la ventana linea a linea
for (y = sqr_ya; y < sqr_yb; y ++) {
// Calcula donde se escribira la linea
move = ((y << 8) + sqr_xa);
// Copia la linea de la Imagen A sobre la B
memcpy((NF_16BITS_BACKBUFFER[1] + move), (NF_BG16B[1].buffer + move), ((sqr_xb - sqr_xa) << 1));
// Draw the window
for (int y = sqr_ya; y < sqr_yb; y ++)
{
u32 offset = (y << 8) + sqr_xa;
memcpy(NF_16BITS_BACKBUFFER[1] + offset,
NF_BG16B[1].buffer + offset,
(sqr_xb - sqr_xa) << 1);
}
}
}
// Sincronismo Vertical
// Wait for the screen refresh
swiWaitForVBlank();
// Manda el backbuffer a la pantalla
// Swap backbuffer and visible buffers
NF_Flip16bitsBackBuffer(1);
}
return 0;
}

View File

@ -1,59 +1,22 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Basic example of using a 16-bit bitmap and zooming an image.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo basico de BackBuffer en 16bits (modo BITMAP)
Zoom de imagen X2
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>
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Pantalla de espera inicializando NitroFS
int main(int argc, char **argv)
{
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
@ -61,124 +24,124 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
NF_SetRootFolder("NITROFS");
// Inicializa el motor 2D en modo BITMAP
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas
// Initialize 2D engine in both screens and use mode 5
NF_Set2D(0, 5);
NF_Set2D(1, 5);
// Inicializa los fondos en modo "BITMAP"
// Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1);
// Inicializa los buffers para guardar fondos en formato BITMAP
// Initialize storage buffers
NF_Init16bitsBgBuffers();
// Inicializa el BackBuffer de 16 bits
// Usalo solo una vez antes de habilitarlo
// Initialize backbuffers
NF_Init16bitsBackBuffer(0);
NF_Init16bitsBackBuffer(1);
// Habilita el backbuffer en la pantalla superior
// Enable backbuffers
NF_Enable16bitsBackBuffer(0);
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);
// Tranfiere la imagen al BackBuffer de la pantalla inferior
// Tranfer image to the backbuffer of the bottom screen
NF_Copy16bitsBuffer(1, 1, 0);
// Variables RGB
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;
// Window position
s16 square_x = 0;
s16 square_y = 0;
s16 zoom_x = 0;
s16 zoom_y = 0;
// Variables del control del touchpad
u16 keys = 0;
touchPosition touchscreen;
while (1) {
// Copia el original
while (1)
{
// Copy original image
NF_Copy16bitsBuffer(1, 1, 0);
// Lectura de posicion del stylus
scanKeys(); // Lee el touchpad via Libnds
// Read keys and touchscreen
scanKeys();
touchPosition touchscreen;
touchRead(&touchscreen);
keys = keysHeld(); // Verifica el estado del touchscreen
if (keys & KEY_TOUCH) {
square_x = (touchscreen.px - 64);
square_y = (touchscreen.py - 48);
u16 keys = keysHeld();
if (keys & KEY_TOUCH)
{
square_x = touchscreen.px - 64;
square_y = touchscreen.py - 48;
}
// Calcula la ventana
if (square_x < 0) square_x = 0;
if (square_x > 127) square_x = 127;
if (square_y < 0) square_y = 0;
if (square_y > 95) square_y = 95;
// Restrict coordinates of the window
if (square_x < 0)
square_x = 0;
if (square_x > 127)
square_x = 127;
// Resetea el control de zoom
zoom_x = 0;
zoom_y = 0;
if (square_y < 0)
square_y = 0;
if (square_y > 95)
square_y = 95;
// Rellena el buffer
for (y = square_y; y < (square_y + 96); y ++) {
for (x = square_x; x < (square_x + 128); x ++) {
// Obten el color actual
rgb = NF_16BITS_BACKBUFFER[1][((y << 8) + x)];
// Escribe los pixeles en el Backbuffer de la pantalla superior
// Esto genera el Zoom x2 en la pantalla superior
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + zoom_x)] = rgb;
NF_16BITS_BACKBUFFER[0][((zoom_y << 8) + (zoom_x + 1))] = rgb;
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + zoom_x)] = rgb;
NF_16BITS_BACKBUFFER[0][(((zoom_y + 1) << 8) + (zoom_x + 1))] = rgb;
// Desglosa el RGB
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 >> 2);
b = (composite >> 1);
// 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;
// Incrementa dos puntos la X del zoom
// Reset source buffer read pointers
u32 zoom_x = 0;
u32 zoom_y = 0;
// Fill the destination buffer
for (int y = square_y; y < square_y + 96; y++)
{
for (int x = square_x; x < square_x + 128; x++)
{
// Get current color
u32 rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
// Write value in 2x2 pixels in the bacbuffer of the bottom
// screen for the zoom effect.
NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + zoom_x] = rgb;
NF_16BITS_BACKBUFFER[0][(zoom_y << 8) + (zoom_x + 1)] = rgb;
NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + zoom_x] = rgb;
NF_16BITS_BACKBUFFER[0][((zoom_y + 1) << 8) + (zoom_x + 1)] = rgb;
// Get RGB components
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;
g = composite >> 2;
b = composite >> 1;
// Pack the components as a RGB value
rgb = r | (g << 5) | (b << 10) | BIT(15);
// Write RGB value in the backbuffer
NF_16BITS_BACKBUFFER[1][(y << 8) + x] = rgb;
// Increment X coordinate pointer
zoom_x += 2;
}
zoom_x = 0; // Resetea la X del zoom
zoom_y += 2; // Incrementa dos puntos la Y del zoom
// Set X coordinate from the beginning
zoom_x = 0;
// Increment Y coordinate pointer
zoom_y += 2;
}
// Sincronismo Vertical
// Wait for the screen refresh
swiWaitForVBlank();
// Copia el contenido del Backbuffer a la VRAM
// Swap backbuffers and visible buffers
NF_Flip16bitsBackBuffer(0);
NF_Flip16bitsBackBuffer(1);
}
return 0;
}

View File

@ -1,110 +1,70 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Example of using 16-bit bitmap graphics.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo graficos en modo BITMAP de 16bits
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>
// Includes propietarios NDS
#include <nds.h>
// Includes librerias propias
#include <nf_lib.h>
/*
-------------------------------------------------
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
int main(int argc, char **argv)
{
// Initialize 2D engine in both screens and use mode 5
NF_Set2D(0, 5);
NF_Set2D(1, 5);
// Inicializa los fondos en BITMAP
// Initialize bitmap backgrounds system
NF_InitBitmapBgSys(0, 1);
NF_InitBitmapBgSys(1, 1);
// Variables RGB
u8 r = 0;
u8 g = 0;
u8 b = 0;
// Calcula el valor RGB
u16 rgb = 0;
// Direccion en VRAM
u32 adress = 0;
// Otras
s16 x = 0;
s16 y = 0;
u32 r = 0;
u32 g = 0;
u32 b = 0;
// Rellena la pantalla
for (y = 0; y < 256; y ++) {
for (x = 0; x < 256; x ++) {
// Calcula el nuevo color
r ++;
if (r > 31) {
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 > 31) {
g++;
if (g > 31)
{
g = 0;
b ++;
if (b > 31) b = 0;
}
}
// Calcula el valor RGB (Alpha + RGB555)
rgb = ((r)|((g) << 5)|((b) << 10)|(BIT(15)));
// Calcula la posicion donde se escribira en la VRAM (Banco A, modo bitmap, pantalla superior)
adress = (0x06000000 + (((y << 8) + x) << 1));
// Escribe el valor
*((u16*)adress) = rgb;
// Calcula la posicion donde se escribira en la VRAM (Banco C, modo bitmap, pantalla inferior)
adress = (0x06200000 + (((x << 8) + y) << 1));
// Escribe el valor
*((u16*)adress) = rgb;
b++;
if (b > 31)
b = 0;
}
}
// Pack the components as a RGB value
u32 rgb = r | (g << 5) | (b << 10) | BIT(15);
// Bucle (repite para siempre)
while(1) {
// Calculate destination address for top screen (VRAM_A)
u32 address = 0x06000000 + (((y << 8) + x) << 1);
swiWaitForVBlank(); // Espera al sincronismo vertical
// Write RGB value
*((u16*)address) = rgb;
// Calculate destination address for bottom screen (VRAM_C)
address = 0x06200000 + (((x << 8) + y) << 1);
// Write RGB value
*((u16*)address) = rgb;
}
}
while (1)
{
// Wait for the screen refresh
swiWaitForVBlank();
}
return 0;
}

View File

@ -124,9 +124,11 @@ int main(int argc, char **argv)
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]);
}

View File

@ -1,57 +1,24 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: NightFox & Co., 2009-2011
//
// Example of modifying sprite palettes.
// http://www.nightfoxandco.com
/*
-------------------------------------------------
NightFox's Lib Template
Ejemplo de manipulacion de paletas de 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>
int main(int argc, char **argv)
{
// Set random seed based on the current time
srand(time(NULL));
/*
-------------------------------------------------
Main() - Bloque general del programa
-------------------------------------------------
*/
int main(int argc, char **argv) {
// Pantalla de espera inicializando NitroFS
// Prepare a NitroFS initialization screen
NF_Set2D(0, 0);
NF_Set2D(1, 0);
consoleDemoInit();
@ -59,58 +26,51 @@ int main(int argc, char **argv) {
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
swiWaitForVBlank();
// Define el ROOT e inicializa el sistema de archivos
// Initialize NitroFS and set it as the root folder of the filesystem
nitroFSInit(NULL);
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
NF_SetRootFolder("NITROFS");
// Inicializa el motor 2D
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
// Initialize 2D engine in both screens and use mode 0
NF_Set2D(0, 0);
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
// Initialize tiled backgrounds system
NF_InitTiledBgBuffers(); // Initialize storage buffers
NF_InitTiledBgSys(0); // Top screen
NF_InitTiledBgSys(1); // Bottom screen
// 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
// Initialize sprite system
NF_InitSpriteBuffers(); // Initialize storage buffers
NF_InitSpriteSys(0); // Top screen
NF_InitSpriteSys(1); // Bottom screen
// 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
// 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);
// Carga los archivos de sprites desde la FAT / NitroFS a la RAM
NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64); // Personaje
// Load sprite files from NitroFS
NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64);
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);
// Crea los fondos de la pantalla superior
// Create top screen background
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, 2, "capa_2");
// Transfiere a la VRAM los sprites necesarios
NF_VramSpriteGfx(1, 0, 0, true); // Bola (mantiene los frames en RAM)
// 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, true); // Personaje (mantiene los frames en RAM) Pantalla inferior
NF_VramSpriteGfx(0, 1, 0, true); // Character: Keep all frames in VRAM
NF_VramSpritePal(0, 1, 0);
// Variables generales y inicializacion del random
u16 n = 0;
srand(time(NULL));
// Crea el sprite del personaje en pantalla
// Setup character sprite
s16 pj_x = 0;
s16 pj_y = 127;
u8 pj_frame = 0;
@ -118,118 +78,129 @@ int main(int argc, char **argv) {
s8 pj_speed = 1;
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_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);
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]);
}
// Variables para el ciclo de colores
u8 r, g, b;
s8 red, green, blue;
s8 speed = 0;
// Palette color cycle speed
int speed = 0;
// Bucle (repite para siempre)
while(1) {
// Ciclo de colores
speed ++;
if (speed > 2) {
while (1)
{
// Color cycle handling
speed++;
if (speed > 2)
{
speed = 0;
// Bolas
for (n = 1; n < 256; n ++) {
// Obten el valor actual del color en la paleta
// Balls
for (int n = 1; n < 256; n++)
{
// Get current color from the palette
u8 r, g, b;
NF_SpriteGetPalColor(0, 0, n, &r, &g, &b);
// Pasa los valores del color a las variables de modificacion
red = r;
green = g;
blue = b;
// Modifica los valores
red --;
if (red < 0) red = 31;
green ++;
if (green > 31) green = 0;
blue ++;
if (blue > 31) blue = 0;
// Actualiza el color en la paleta en RAM
NF_SpriteEditPalColor(0, 0, n, red, green, blue);
// Modify color
r--;
if (r > 31)
r = 31;
g++;
if (g > 31)
g = 0;
b++;
if (b > 31)
b = 0;
// Update color in the copy of the palette in RAM
NF_SpriteEditPalColor(0, 0, n, r, g, b);
}
// Actualiza la paleta en VRAM
// Update palette in VRAM
NF_SpriteUpdatePalette(0, 0);
// Personaje
for (n = 1; n < 256; n ++) {
// Obten el valor actual del color en la paleta
// Character
for (int n = 1; n < 256; n++)
{
// Get current color from the palette
u8 r, g, b;
NF_SpriteGetPalColor(1, 0, n, &r, &g, &b);
// Pasa los valores del color a las variables de modificacion
red = r;
green = g;
blue = b;
// Modifica los valores
red --;
if (red < 0) red = 31;
//green ++;
//if (green > 31) green = 0;
//blue ++;
//if (blue > 31) blue = 0;
// Actualiza el color en la paleta en RAM
NF_SpriteEditPalColor(1, 0, n, red, green, blue);
// Modify color
r--;
if (r > 31)
r = 31;
// Update color in the copy of the palette in RAM
NF_SpriteEditPalColor(1, 0, n, r, g, b);
}
// Actualiza la paleta en VRAM
// Update palette in VRAM
NF_SpriteUpdatePalette(1, 0);
}
// Mueve el personaje
// Move character
pj_x += pj_speed;
if ((pj_x < 0) || (pj_x > 191)) {
if ((pj_x < 0) || (pj_x > 191))
{
pj_speed *= -1;
if (pj_speed > 0) {
if (pj_speed > 0)
NF_HflipSprite(1, 0, false);
} else {
else
NF_HflipSprite(1, 0, true);
}
}
NF_MoveSprite(1, 0, pj_x, pj_y);
// Animacion del personaje
pj_anim ++;
if (pj_anim > 5) {
// Animate character
pj_anim++;
if (pj_anim > 5)
{
pj_anim = 0;
pj_frame ++;
if (pj_frame > 11) pj_frame = 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 ++) {
// 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;
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;
if ((bola_y[n] < 0) || (bola_y[n] > 159))
bola_spy[n] *= -1;
NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
}
// Actualiza el array de OAM
// Update OAM array
NF_SpriteOamSet(0);
NF_SpriteOamSet(1);
swiWaitForVBlank(); // Espera al sincronismo vertical
// Wait for the screen refresh
swiWaitForVBlank();
// Actualiza el OAM
// Update OAM
oamUpdate(&oamMain);
oamUpdate(&oamSub);
}
return 0;
}