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
af329f901a
commit
4d4cb6ab8e
@ -85,9 +85,9 @@ int main(int argc, char **argv)
|
|||||||
square_y = 127;
|
square_y = 127;
|
||||||
|
|
||||||
// Fill buffer
|
// 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
|
// Get current color
|
||||||
u32 rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
|
u32 rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
|
||||||
@ -107,7 +107,7 @@ int main(int argc, char **argv)
|
|||||||
b = composite;
|
b = composite;
|
||||||
|
|
||||||
// Pack the components as a RGB value
|
// 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
|
// Write RGB value in the backbuffer
|
||||||
NF_16BITS_BACKBUFFER[1][(y << 8) + x] = rgb;
|
NF_16BITS_BACKBUFFER[1][(y << 8) + x] = rgb;
|
||||||
|
@ -1,175 +1,140 @@
|
|||||||
// 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.
|
||||||
|
// 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 <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
|
||||||
|
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);
|
||||||
|
|
||||||
/*
|
// Initialize storage buffers
|
||||||
-------------------------------------------------
|
NF_Init16bitsBgBuffers();
|
||||||
Main() - Bloque general del programa
|
|
||||||
-------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
// Initialize backbuffer
|
||||||
|
NF_Init16bitsBackBuffer(1);
|
||||||
|
|
||||||
// Pantalla de espera inicializando NitroFS
|
// Enable backbuffer
|
||||||
NF_Set2D(0, 0);
|
NF_Enable16bitsBackBuffer(1);
|
||||||
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
|
// Load bitmap background files from NitroFS
|
||||||
nitroFSInit(NULL);
|
NF_Load16bitsBg("bmp/bitmap16", 0);
|
||||||
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
|
NF_Load16bitsBg("bmp/img16_a", 1);
|
||||||
|
NF_Load16bitsBg("bmp/img16_b", 2);
|
||||||
|
|
||||||
// Inicializa el motor 2D en modo BITMAP
|
// Tranfer image to VRAM of both screens
|
||||||
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas
|
NF_Copy16bitsBuffer(0, 0, 0);
|
||||||
NF_Set2D(1, 5);
|
NF_Copy16bitsBuffer(1, 1, 2);
|
||||||
|
|
||||||
// Inicializa los fondos en modo "BITMAP"
|
// It's not needed to use it any longer, so remove it from RAM
|
||||||
NF_InitBitmapBgSys(0, 1);
|
NF_Unload16bitsBg(0);
|
||||||
NF_InitBitmapBgSys(1, 1);
|
|
||||||
|
|
||||||
// Inicializa los buffers para guardar fondos en formato BITMAP
|
// Variables to control the window
|
||||||
NF_Init16bitsBgBuffers();
|
s16 xa = 0;
|
||||||
|
s16 xb = 0;
|
||||||
|
s16 ya = 0;
|
||||||
|
s16 yb = 0;
|
||||||
|
|
||||||
// Inicializa el BackBuffer de 16 bits
|
while (1)
|
||||||
// Usalo solo una vez antes de habilitarlo
|
{
|
||||||
NF_Init16bitsBackBuffer(1);
|
// Copy original image to the backbuffer of the top screen
|
||||||
|
NF_Copy16bitsBuffer(1, 1, 2);
|
||||||
|
|
||||||
// Habilita el backbuffer en la pantalla superior
|
// Read keys and touchscreen
|
||||||
NF_Enable16bitsBackBuffer(1);
|
scanKeys();
|
||||||
|
touchPosition touchscreen;
|
||||||
|
touchRead(&touchscreen);
|
||||||
|
u16 keys_held = keysHeld();
|
||||||
|
u16 keys_down = keysDown();
|
||||||
|
|
||||||
// Carga el archivo BITMAP de imagen en formato RAW a la RAM
|
if (keys_down & KEY_TOUCH)
|
||||||
NF_Load16bitsBg("bmp/bitmap16", 0);
|
{
|
||||||
NF_Load16bitsBg("bmp/img16_a", 1);
|
// If this is the first time the user presses the screen, save that
|
||||||
NF_Load16bitsBg("bmp/img16_b", 2);
|
// 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;
|
||||||
|
|
||||||
// Tranfiere la imagen a la VRAM de ambas pantallas
|
// If the two points aren't the same
|
||||||
NF_Copy16bitsBuffer(0, 0, 0);
|
if ((xa != xb) && (ya != yb))
|
||||||
NF_Copy16bitsBuffer(1, 1, 2);
|
{
|
||||||
|
int sqr_xa, sqr_xb, sqr_ya, sqr_yb;
|
||||||
|
|
||||||
// Si no es necesario usarla mas, borrala de la RAM
|
// Calculate window bounds
|
||||||
NF_Unload16bitsBg(0);
|
if (xa < xb)
|
||||||
|
{
|
||||||
|
sqr_xa = xa;
|
||||||
|
sqr_xb = xb;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sqr_xa = xb;
|
||||||
|
sqr_xb = xa;
|
||||||
|
}
|
||||||
|
|
||||||
// Variables del control del touchpad
|
if (ya < yb)
|
||||||
u16 keys = 0;
|
{
|
||||||
touchPosition touchscreen;
|
sqr_ya = ya;
|
||||||
|
sqr_yb = yb;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sqr_ya = yb;
|
||||||
|
sqr_yb = ya;
|
||||||
|
}
|
||||||
|
|
||||||
// Variables del control de la ventana
|
// Draw the window
|
||||||
u32 move = 0;
|
for (int y = sqr_ya; y < sqr_yb; y ++)
|
||||||
s16 y = 0;
|
{
|
||||||
s16 xa = 0;
|
u32 offset = (y << 8) + sqr_xa;
|
||||||
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
|
memcpy(NF_16BITS_BACKBUFFER[1] + offset,
|
||||||
while (1) {
|
NF_BG16B[1].buffer + offset,
|
||||||
|
(sqr_xb - sqr_xa) << 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Copia al backbuffer la imagen de arriba
|
// Wait for the screen refresh
|
||||||
NF_Copy16bitsBuffer(1, 1, 2);
|
swiWaitForVBlank();
|
||||||
|
|
||||||
// Lectura de posicion del stylus
|
// Swap backbuffer and visible buffers
|
||||||
scanKeys(); // Lee el touchpad via Libnds
|
NF_Flip16bitsBackBuffer(1);
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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) {
|
|
||||||
sqr_xa = xa;
|
|
||||||
sqr_xb = xb;
|
|
||||||
} else {
|
|
||||||
sqr_xa = xb;
|
|
||||||
sqr_xb = xa;
|
|
||||||
}
|
|
||||||
if (ya < yb) {
|
|
||||||
sqr_ya = ya;
|
|
||||||
sqr_yb = yb;
|
|
||||||
} 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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sincronismo Vertical
|
|
||||||
swiWaitForVBlank();
|
|
||||||
|
|
||||||
// Manda el backbuffer a la pantalla
|
|
||||||
NF_Flip16bitsBackBuffer(1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,184 +1,147 @@
|
|||||||
// 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 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 <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
|
||||||
|
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);
|
||||||
|
|
||||||
/*
|
// Initialize storage buffers
|
||||||
-------------------------------------------------
|
NF_Init16bitsBgBuffers();
|
||||||
Main() - Bloque general del programa
|
|
||||||
-------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
// Initialize backbuffers
|
||||||
|
NF_Init16bitsBackBuffer(0);
|
||||||
|
NF_Init16bitsBackBuffer(1);
|
||||||
|
|
||||||
// Pantalla de espera inicializando NitroFS
|
// Enable backbuffers
|
||||||
NF_Set2D(0, 0);
|
NF_Enable16bitsBackBuffer(0);
|
||||||
NF_Set2D(1, 0);
|
NF_Enable16bitsBackBuffer(1);
|
||||||
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
|
// Load bitmap background files from NitroFS
|
||||||
nitroFSInit(NULL);
|
NF_Load16bitsBg("bmp/bitmap16", 0);
|
||||||
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
|
|
||||||
|
|
||||||
// Inicializa el motor 2D en modo BITMAP
|
// Tranfer image to the backbuffer of the bottom screen
|
||||||
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas
|
NF_Copy16bitsBuffer(1, 1, 0);
|
||||||
NF_Set2D(1, 5);
|
|
||||||
|
|
||||||
// Inicializa los fondos en modo "BITMAP"
|
// Window position
|
||||||
NF_InitBitmapBgSys(0, 1);
|
s16 square_x = 0;
|
||||||
NF_InitBitmapBgSys(1, 1);
|
s16 square_y = 0;
|
||||||
|
|
||||||
// Inicializa los buffers para guardar fondos en formato BITMAP
|
while (1)
|
||||||
NF_Init16bitsBgBuffers();
|
{
|
||||||
|
// Copy original image
|
||||||
|
NF_Copy16bitsBuffer(1, 1, 0);
|
||||||
|
|
||||||
// Inicializa el BackBuffer de 16 bits
|
// Read keys and touchscreen
|
||||||
// Usalo solo una vez antes de habilitarlo
|
scanKeys();
|
||||||
NF_Init16bitsBackBuffer(0);
|
touchPosition touchscreen;
|
||||||
NF_Init16bitsBackBuffer(1);
|
touchRead(&touchscreen);
|
||||||
|
u16 keys = keysHeld();
|
||||||
|
if (keys & KEY_TOUCH)
|
||||||
|
{
|
||||||
|
square_x = touchscreen.px - 64;
|
||||||
|
square_y = touchscreen.py - 48;
|
||||||
|
}
|
||||||
|
|
||||||
// Habilita el backbuffer en la pantalla superior
|
// Restrict coordinates of the window
|
||||||
NF_Enable16bitsBackBuffer(0);
|
if (square_x < 0)
|
||||||
NF_Enable16bitsBackBuffer(1);
|
square_x = 0;
|
||||||
|
if (square_x > 127)
|
||||||
|
square_x = 127;
|
||||||
|
|
||||||
// Carga el archivo BITMAP de imagen en formato RAW a la RAM
|
if (square_y < 0)
|
||||||
NF_Load16bitsBg("bmp/bitmap16", 0);
|
square_y = 0;
|
||||||
|
if (square_y > 95)
|
||||||
|
square_y = 95;
|
||||||
|
|
||||||
// Tranfiere la imagen al BackBuffer de la pantalla inferior
|
// Reset source buffer read pointers
|
||||||
NF_Copy16bitsBuffer(1, 1, 0);
|
u32 zoom_x = 0;
|
||||||
|
u32 zoom_y = 0;
|
||||||
|
|
||||||
// Variables RGB
|
// Fill the destination buffer
|
||||||
u8 r = 0;
|
for (int y = square_y; y < square_y + 96; y++)
|
||||||
u8 g = 0;
|
{
|
||||||
u8 b = 0;
|
for (int x = square_x; x < square_x + 128; x++)
|
||||||
|
{
|
||||||
|
// Get current color
|
||||||
|
u32 rgb = NF_16BITS_BACKBUFFER[1][(y << 8) + x];
|
||||||
|
|
||||||
// Calcula el valor RGB
|
// Write value in 2x2 pixels in the bacbuffer of the bottom
|
||||||
u16 rgb = 0;
|
// 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;
|
||||||
|
|
||||||
// Ventana
|
// Get RGB components
|
||||||
s16 x = 0;
|
u32 r = rgb & 0x1F;
|
||||||
s16 y = 0;
|
u32 g = (rgb >> 5) & 0x1F;
|
||||||
s16 composite = 0;
|
u32 b = (rgb >> 10) & 0x1F;
|
||||||
s16 square_x = 0;
|
|
||||||
s16 square_y = 0;
|
|
||||||
s16 zoom_x = 0;
|
|
||||||
s16 zoom_y = 0;
|
|
||||||
|
|
||||||
// Variables del control del touchpad
|
// Generate a grayscale value based on the RGB components
|
||||||
u16 keys = 0;
|
u32 composite = ((r + g + b) / 3) + 3;
|
||||||
touchPosition touchscreen;
|
if (composite > 31)
|
||||||
|
composite = 31;
|
||||||
|
|
||||||
while (1) {
|
// 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;
|
||||||
|
|
||||||
// Copia el original
|
// Pack the components as a RGB value
|
||||||
NF_Copy16bitsBuffer(1, 1, 0);
|
rgb = r | (g << 5) | (b << 10) | BIT(15);
|
||||||
|
|
||||||
// Lectura de posicion del stylus
|
// Write RGB value in the backbuffer
|
||||||
scanKeys(); // Lee el touchpad via Libnds
|
NF_16BITS_BACKBUFFER[1][(y << 8) + x] = rgb;
|
||||||
touchRead(&touchscreen);
|
|
||||||
keys = keysHeld(); // Verifica el estado del touchscreen
|
|
||||||
if (keys & KEY_TOUCH) {
|
|
||||||
square_x = (touchscreen.px - 64);
|
|
||||||
square_y = (touchscreen.py - 48);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcula la ventana
|
// Increment X coordinate pointer
|
||||||
if (square_x < 0) square_x = 0;
|
zoom_x += 2;
|
||||||
if (square_x > 127) square_x = 127;
|
}
|
||||||
if (square_y < 0) square_y = 0;
|
|
||||||
if (square_y > 95) square_y = 95;
|
|
||||||
|
|
||||||
// Resetea el control de zoom
|
// Set X coordinate from the beginning
|
||||||
zoom_x = 0;
|
zoom_x = 0;
|
||||||
zoom_y = 0;
|
// Increment Y coordinate pointer
|
||||||
|
zoom_y += 2;
|
||||||
|
}
|
||||||
|
|
||||||
// Rellena el buffer
|
// Wait for the screen refresh
|
||||||
for (y = square_y; y < (square_y + 96); y ++) {
|
swiWaitForVBlank();
|
||||||
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
|
|
||||||
zoom_x += 2;
|
|
||||||
}
|
|
||||||
zoom_x = 0; // Resetea la X del zoom
|
|
||||||
zoom_y += 2; // Incrementa dos puntos la Y del zoom
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sincronismo Vertical
|
// Swap backbuffers and visible buffers
|
||||||
swiWaitForVBlank();
|
NF_Flip16bitsBackBuffer(0);
|
||||||
|
NF_Flip16bitsBackBuffer(1);
|
||||||
// Copia el contenido del Backbuffer a la VRAM
|
}
|
||||||
NF_Flip16bitsBackBuffer(0);
|
|
||||||
NF_Flip16bitsBackBuffer(1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,110 +1,70 @@
|
|||||||
// SPDX-License-Identifier: CC0-1.0
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
//
|
//
|
||||||
// SPDX-FileContributor: NightFox & Co., 2009-2011
|
// SPDX-FileContributor: NightFox & Co., 2009-2011
|
||||||
|
//
|
||||||
|
// Example of using 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>
|
#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);
|
||||||
|
NF_Set2D(1, 5);
|
||||||
|
|
||||||
|
// Initialize bitmap backgrounds system
|
||||||
|
NF_InitBitmapBgSys(0, 1);
|
||||||
|
NF_InitBitmapBgSys(1, 1);
|
||||||
|
|
||||||
|
u32 r = 0;
|
||||||
|
u32 g = 0;
|
||||||
|
u32 b = 0;
|
||||||
|
|
||||||
|
// Rellena la pantalla
|
||||||
|
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 = 0;
|
||||||
|
b++;
|
||||||
|
if (b > 31)
|
||||||
|
b = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
// Pack the components as a RGB value
|
||||||
-------------------------------------------------
|
u32 rgb = r | (g << 5) | (b << 10) | BIT(15);
|
||||||
Main() - Bloque general del programa
|
|
||||||
-------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
// Calculate destination address for top screen (VRAM_A)
|
||||||
|
u32 address = 0x06000000 + (((y << 8) + x) << 1);
|
||||||
|
|
||||||
// Inicializa el motor 2D en modo BITMAP
|
// Write RGB value
|
||||||
NF_Set2D(0, 5); // Modo 2D_5 en ambas pantallas
|
*((u16*)address) = rgb;
|
||||||
NF_Set2D(1, 5);
|
|
||||||
|
|
||||||
// Inicializa los fondos en BITMAP
|
// Calculate destination address for bottom screen (VRAM_C)
|
||||||
NF_InitBitmapBgSys(0, 1);
|
address = 0x06200000 + (((x << 8) + y) << 1);
|
||||||
NF_InitBitmapBgSys(1, 1);
|
|
||||||
|
|
||||||
|
// Write RGB value
|
||||||
|
*((u16*)address) = rgb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Variables RGB
|
while (1)
|
||||||
u8 r = 0;
|
{
|
||||||
u8 g = 0;
|
// Wait for the screen refresh
|
||||||
u8 b = 0;
|
swiWaitForVBlank();
|
||||||
// Calcula el valor RGB
|
}
|
||||||
u16 rgb = 0;
|
|
||||||
// Direccion en VRAM
|
|
||||||
u32 adress = 0;
|
|
||||||
// Otras
|
|
||||||
s16 x = 0;
|
|
||||||
s16 y = 0;
|
|
||||||
|
|
||||||
// Rellena la pantalla
|
|
||||||
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 > 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Bucle (repite para siempre)
|
|
||||||
while(1) {
|
|
||||||
|
|
||||||
swiWaitForVBlank(); // Espera al sincronismo vertical
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -124,9 +124,11 @@ int main(int argc, char **argv)
|
|||||||
bola_x[n] += bola_spx[n];
|
bola_x[n] += bola_spx[n];
|
||||||
if ((bola_x[n] < 0) || (bola_x[n] > 223))
|
if ((bola_x[n] < 0) || (bola_x[n] > 223))
|
||||||
bola_spx[n] *= -1;
|
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))
|
if ((bola_y[n] < 0) || (bola_y[n] > 159))
|
||||||
bola_spy[n] *= -1;
|
bola_spy[n] *= -1;
|
||||||
|
|
||||||
NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
|
NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,235 +1,206 @@
|
|||||||
// 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 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 <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
|
||||||
|
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);
|
||||||
|
|
||||||
/*
|
// Initialize tiled backgrounds system
|
||||||
-------------------------------------------------
|
NF_InitTiledBgBuffers(); // Initialize storage buffers
|
||||||
Main() - Bloque general del programa
|
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
|
// Load background files from NitroFS
|
||||||
NF_Set2D(0, 0);
|
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256);
|
||||||
NF_Set2D(1, 0);
|
NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256);
|
||||||
consoleDemoInit();
|
NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256);
|
||||||
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
|
// Load sprite files from NitroFS
|
||||||
nitroFSInit(NULL);
|
NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64);
|
||||||
NF_SetRootFolder("NITROFS"); // Define la carpeta ROOT para usar NITROFS
|
NF_LoadSpritePal("sprite/personaje", 0);
|
||||||
|
|
||||||
// Inicializa el motor 2D
|
NF_LoadSpriteGfx("sprite/bola", 1, 32, 32);
|
||||||
NF_Set2D(0, 0); // Modo 2D_0 en ambas pantallas
|
NF_LoadSpritePal("sprite/bola", 1);
|
||||||
NF_Set2D(1, 0);
|
|
||||||
|
|
||||||
// Inicializa los fondos tileados
|
// Create top screen background
|
||||||
NF_InitTiledBgBuffers(); // Inicializa los buffers para almacenar fondos
|
NF_CreateTiledBg(0, 3, "nfl");
|
||||||
NF_InitTiledBgSys(0); // Inicializa los fondos Tileados para la pantalla superior
|
|
||||||
NF_InitTiledBgSys(1); // Iniciliaza los fondos Tileados para la pantalla inferior
|
|
||||||
|
|
||||||
// Inicializa los Sprites
|
// Create bottom screen backgrounds
|
||||||
NF_InitSpriteBuffers(); // Inicializa los buffers para almacenar sprites y paletas
|
NF_CreateTiledBg(1, 3, "capa_3");
|
||||||
NF_InitSpriteSys(0); // Inicializa los sprites para la pantalla superior
|
NF_CreateTiledBg(1, 2, "capa_2");
|
||||||
NF_InitSpriteSys(1); // Inicializa los sprites para la pantalla inferior
|
|
||||||
|
|
||||||
// Carga los archivos de fondo desde la FAT / NitroFS a la RAM
|
// Transfer the required sprites to VRAM
|
||||||
NF_LoadTiledBg("bg/nfl", "nfl", 256, 256); // Carga el fondo para la pantalla superior
|
NF_VramSpriteGfx(1, 0, 0, true); // Ball: Keep all frames in VRAM
|
||||||
NF_LoadTiledBg("bg/bg3", "capa_3", 256, 256); // Carga el fondo para la capa 3, pantalla inferior
|
NF_VramSpritePal(1, 0, 0);
|
||||||
NF_LoadTiledBg("bg/bg2", "capa_2", 1024, 256); // Carga el fondo para la capa 2, pantalla inferior
|
|
||||||
|
|
||||||
|
NF_VramSpriteGfx(0, 1, 0, true); // Character: Keep all frames in VRAM
|
||||||
|
NF_VramSpritePal(0, 1, 0);
|
||||||
|
|
||||||
// Carga los archivos de sprites desde la FAT / NitroFS a la RAM
|
// Setup character sprite
|
||||||
NF_LoadSpriteGfx("sprite/personaje", 0, 64, 64); // Personaje
|
s16 pj_x = 0;
|
||||||
NF_LoadSpritePal("sprite/personaje", 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);
|
||||||
|
|
||||||
NF_LoadSpriteGfx("sprite/bola", 1, 32, 32); // Bola azul
|
// Setup ball sprites
|
||||||
NF_LoadSpritePal("sprite/bola", 1);
|
s16 bola_x[32];
|
||||||
|
s16 bola_y[32];
|
||||||
|
s8 bola_spx[32];
|
||||||
|
s8 bola_spy[32];
|
||||||
|
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
// Crea los fondos de la pantalla superior
|
// Palette color cycle speed
|
||||||
NF_CreateTiledBg(0, 3, "nfl");
|
int speed = 0;
|
||||||
// Crea los fondos de la pantalla inferior
|
|
||||||
NF_CreateTiledBg(1, 3, "capa_3");
|
|
||||||
NF_CreateTiledBg(1, 2, "capa_2");
|
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
// Color cycle handling
|
||||||
|
speed++;
|
||||||
|
if (speed > 2)
|
||||||
|
{
|
||||||
|
speed = 0;
|
||||||
|
|
||||||
// Transfiere a la VRAM los sprites necesarios
|
// Balls
|
||||||
NF_VramSpriteGfx(1, 0, 0, true); // Bola (mantiene los frames en RAM)
|
for (int n = 1; n < 256; n++)
|
||||||
NF_VramSpritePal(1, 0, 0);
|
{
|
||||||
|
// Get current color from the palette
|
||||||
|
u8 r, g, b;
|
||||||
|
NF_SpriteGetPalColor(0, 0, n, &r, &g, &b);
|
||||||
|
|
||||||
NF_VramSpriteGfx(0, 1, 0, true); // Personaje (mantiene los frames en RAM) Pantalla inferior
|
// Modify color
|
||||||
NF_VramSpritePal(0, 1, 0);
|
r--;
|
||||||
|
if (r > 31)
|
||||||
|
r = 31;
|
||||||
|
|
||||||
|
g++;
|
||||||
|
if (g > 31)
|
||||||
|
g = 0;
|
||||||
|
|
||||||
// Variables generales y inicializacion del random
|
b++;
|
||||||
u16 n = 0;
|
if (b > 31)
|
||||||
srand(time(NULL));
|
b = 0;
|
||||||
|
|
||||||
// Crea el sprite del personaje en pantalla
|
// Update color in the copy of the palette in RAM
|
||||||
s16 pj_x = 0;
|
NF_SpriteEditPalColor(0, 0, n, r, g, b);
|
||||||
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);
|
|
||||||
|
|
||||||
// Crea las bolas en la pantalla superior
|
// Update palette in VRAM
|
||||||
s16 bola_x[32];
|
NF_SpriteUpdatePalette(0, 0);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Variables para el ciclo de colores
|
// Character
|
||||||
u8 r, g, b;
|
for (int n = 1; n < 256; n++)
|
||||||
s8 red, green, blue;
|
{
|
||||||
s8 speed = 0;
|
// Get current color from the palette
|
||||||
|
u8 r, g, b;
|
||||||
|
NF_SpriteGetPalColor(1, 0, n, &r, &g, &b);
|
||||||
|
|
||||||
// Bucle (repite para siempre)
|
// Modify color
|
||||||
while(1) {
|
r--;
|
||||||
|
if (r > 31)
|
||||||
|
r = 31;
|
||||||
|
|
||||||
// Ciclo de colores
|
// Update color in the copy of the palette in RAM
|
||||||
speed ++;
|
NF_SpriteEditPalColor(1, 0, n, r, g, b);
|
||||||
if (speed > 2) {
|
}
|
||||||
speed = 0;
|
|
||||||
|
|
||||||
// Bolas
|
// Update palette in VRAM
|
||||||
for (n = 1; n < 256; n ++) {
|
NF_SpriteUpdatePalette(1, 0);
|
||||||
// Obten el valor actual del color en la paleta
|
}
|
||||||
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);
|
|
||||||
}
|
|
||||||
// Actualiza la paleta en VRAM
|
|
||||||
NF_SpriteUpdatePalette(0, 0);
|
|
||||||
|
|
||||||
// Personaje
|
// Move character
|
||||||
for (n = 1; n < 256; n ++) {
|
pj_x += pj_speed;
|
||||||
// Obten el valor actual del color en la paleta
|
if ((pj_x < 0) || (pj_x > 191))
|
||||||
NF_SpriteGetPalColor(1, 0, n, &r, &g, &b);
|
{
|
||||||
// Pasa los valores del color a las variables de modificacion
|
pj_speed *= -1;
|
||||||
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);
|
|
||||||
}
|
|
||||||
// Actualiza la paleta en VRAM
|
|
||||||
NF_SpriteUpdatePalette(1, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (pj_speed > 0)
|
||||||
|
NF_HflipSprite(1, 0, false);
|
||||||
|
else
|
||||||
|
NF_HflipSprite(1, 0, true);
|
||||||
|
}
|
||||||
|
NF_MoveSprite(1, 0, pj_x, pj_y);
|
||||||
|
|
||||||
// Mueve el personaje
|
// Animate character
|
||||||
pj_x += pj_speed;
|
pj_anim++;
|
||||||
if ((pj_x < 0) || (pj_x > 191)) {
|
if (pj_anim > 5)
|
||||||
pj_speed *= -1;
|
{
|
||||||
if (pj_speed > 0) {
|
pj_anim = 0;
|
||||||
NF_HflipSprite(1, 0, false);
|
pj_frame++;
|
||||||
} else {
|
if (pj_frame > 11)
|
||||||
NF_HflipSprite(1, 0, true);
|
pj_frame = 0;
|
||||||
}
|
|
||||||
}
|
|
||||||
NF_MoveSprite(1, 0, pj_x, pj_y);
|
|
||||||
|
|
||||||
// Animacion del personaje
|
NF_SpriteFrame(1, 0, pj_frame);
|
||||||
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
|
// Move balls
|
||||||
for (n = 0; n < 32; n ++) {
|
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_x[n] += bola_spx[n];
|
||||||
bola_y[n] += bola_spy[n];
|
if ((bola_x[n] < 0) || (bola_x[n] > 223))
|
||||||
if ((bola_y[n] < 0) || (bola_y[n] > 159)) bola_spy[n] *= -1;
|
bola_spx[n] *= -1;
|
||||||
NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el array de OAM
|
bola_y[n] += bola_spy[n];
|
||||||
NF_SpriteOamSet(0);
|
if ((bola_y[n] < 0) || (bola_y[n] > 159))
|
||||||
NF_SpriteOamSet(1);
|
bola_spy[n] *= -1;
|
||||||
|
|
||||||
swiWaitForVBlank(); // Espera al sincronismo vertical
|
NF_MoveSprite(0, n, bola_x[n], bola_y[n]);
|
||||||
|
}
|
||||||
|
|
||||||
// Actualiza el OAM
|
// Update OAM array
|
||||||
oamUpdate(&oamMain);
|
NF_SpriteOamSet(0);
|
||||||
oamUpdate(&oamSub);
|
NF_SpriteOamSet(1);
|
||||||
|
|
||||||
}
|
// Wait for the screen refresh
|
||||||
|
swiWaitForVBlank();
|
||||||
|
|
||||||
return 0;
|
// Update OAM
|
||||||
|
oamUpdate(&oamMain);
|
||||||
|
oamUpdate(&oamSub);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user