Minijuego para nds: “disquete volador”
- Samir Ramirez
- 12 may 2009
- 1 Min. de lectura
Probando PALib para la consola de Nintendo nds, he programado este minijuego consistente en tener que pulsar sobre el disquete que se mueve. (Más información sobre programar nds en nuestra sección). El código fuente es el siguiente:
// PAGfx Include #include “gfx/all_gfx.c” #include “gfx/all_gfx.h” #include “moneda.h” #include “zippo.h”
int i;
u32 pierdetiempo=300; s16 puntos=0; s16 vidas=3; s32 bolax = 100; s32 bolay = 100; s16 velx=1; s16 vely=1; s32 disx; s32 disy;
//Fonction principale du code int main(void){
PA_Init(); //Initialision of PAlib PA_InitVBL();
PA_InitText(0,0); PA_InitText(1, 2); //Inicializamos sonido AS_Init(AS_MODE_SURROUND | AS_MODE_16CH ); AS_SetDefaultSettings(AS_PCM_8BIT, 11025, AS_SURROUND);
PA_EasyBgLoad(0, // screen 1, // background number (0-3) ordenador); // Background name, used by PAGfx… PA_EasyBgLoad(1, 3, nds_raultecnologia_256); // Same thing, but on the top screen…
PA_LoadSpritePal(0, // Screen 0, // Palette number (void*)disquete2_Pal); // Palette name
//Create the sprite PA_CreateSprite(0, 0,(void*)disquete2_Sprite, OBJ_SIZE_64X64,1, 0, 0, 0);
void comienzo() { pierdetiempo=300; puntos=0; vidas=3; bolax = PA_RandMinMax(2,100); bolay = PA_RandMinMax(2,60); velx=1; vely=1; PA_OutputSimpleText(1,10,5,” “); PA_OutputSimpleText(1,1,6,” “); PA_OutputText(1, 0, 22, “Puntos: %d “, puntos); PA_OutputText(1, 0, 23, “Vidas: %d “, vidas); }
void fin() { PA_PlaySimpleSound(moneda); while(Pad.Newpress.A==0) { PA_OutputSimpleText(1,10,5,”*** FIN ***”); PA_OutputSimpleText(1,1,6,”Pulsa la tecla A para empezar”); } comienzo(); } comienzo();
while(1){ // Main loop
if (Stylus.Newpress) { disx=(bolax+32)-Stylus.X; disy=(bolay+32)-Stylus.Y; if ((disx*disx)<1024 && (disy*disy)<1024) { puntos = puntos+1; PA_OutputText(1, 0, 22, “Puntos: %d “, puntos); pierdetiempo=pierdetiempo/1.1; PA_PlaySimpleSound(zippo); PA_WaitForVBL(); bolax = PA_RandMinMax(2,100); bolay = PA_RandMinMax(2,60); velx=-velx; vely=-vely; } else { vidas = vidas -1; PA_OutputText(1, 0, 23, “Vidas: %d “, vidas); PA_WaitForVBL(); } }
if (vidas<1) { fin(); }
if(bolax == 1) { velx=-velx; }
if (bolay == 1) { vely=-vely; } if (bolay == 127) { vely=-vely; } if(bolax == 191) { velx=-velx; }
// Update the position according to the keypad… bolax=bolax+velx; bolay=bolay+vely;
// Set the sprite’s position PA_SetSpriteXY(0, // screen 0, // sprite bolax, // x position bolay); // y… for (i=0; i < pierdetiempo ;i++) { PA_OutputText(1, 0, 22, “Puntos: %d “, puntos); //PA_WaitForVBL();
} } return 0; }
Kommentare