top of page

Probando PAlib para programar en la NDS (II)

  • Foto del escritor: Samir Ramirez
    Samir Ramirez
  • 16 feb 2009
  • 2 Min. de lectura

Siguiendo con PAlib para probar a programar en la NDS he hecho este pequeño “juego” con letras… el PAD mueve la letra O en las 4 direcciones, la pantalla táctil se usa para reiniciar el juego y le añadí sonido, un contador de fuel que va disminuyendo y puntuación.

El código del juego es el siguiente:

// Includes #include <PA9.h>       // Include for PA_Lib #include “explosion.h” // incluimos el fichero explosion.raw para el sonido #include “zat.h” #include “alarma.h” #include “dragon.h”

// Function: main() int main(int argc, char ** argv) { PA_Init();    // Initializes PA_Lib PA_InitVBL(); // Initializes a standard VBL PA_InitText(1, 2); // Tell it to put text on screen 1, background number 2 PA_InitText(0, 2); //PA_InitSound();  //Inicializa el sonido

AS_Init(AS_MODE_SURROUND | AS_MODE_16CH ); AS_SetDefaultSettings(AS_PCM_8BIT, 11025, AS_SURROUND);

int i; s16 posx=10; s16 posy=10; s16 fuel=1000; s16 puntos=0; u32 comidax = PA_RandMinMax(1,30); u32 comiday = PA_RandMinMax(3,22); u32 fuelx = PA_RandMinMax(1,30); u32 fuely = PA_RandMinMax(3,22);

void comienzo() { PA_OutputSimpleText(1, comidax, comiday, ” “); PA_OutputSimpleText(1, posx, posy, ” “); PA_OutputSimpleText(1, fuelx, fuely, ” “); posx=10; posy=10; fuel=1000; puntos=0; comidax = PA_RandMinMax(1,30); comiday = PA_RandMinMax(3,22); PA_OutputSimpleText(1, comidax, comiday, “*”); fuelx = PA_RandMinMax(1,30); fuely = PA_RandMinMax(3,22); PA_OutputSimpleText(1, fuelx, fuely, “F”); PA_OutputSimpleText(1, posx, posy, “O”); PA_OutputSimpleText(0,10,12,”                 “); PA_OutputSimpleText(0,1,13,”                              “); PA_OutputText(1, 0, 0, “Puntos: %d  “, puntos); PA_OutputText(1, 15, 0, “Fuel: %d  “, fuel); PA_PlaySimpleSound(dragon); }

void comida() { comidax = PA_RandMinMax(1,30); comiday = PA_RandMinMax(3,22); PA_OutputSimpleText(1, comidax, comiday, “*”); PA_PlaySimpleSound(explosion); }

void quedafuel() { fuelx = PA_RandMinMax(1,30); fuely = PA_RandMinMax(3,22); PA_OutputSimpleText(1, fuelx, fuely, “F”); PA_PlaySimpleSound(zat); }

void fin() { PA_PlaySimpleSound(alarma); while (Stylus.Held == 0) { PA_OutputSimpleText(0,10,12,”*** FIN ***”); PA_OutputSimpleText(0,1,13,”Pulsa la pantalla para empezar”);

}

comienzo();

}

PA_OutputText(1, 0, 0, “Puntos: %d  “, puntos); PA_OutputText(1, 15, 0, “Fuel: %d  “, fuel); PA_OutputSimpleText(1, 0, 2, “+——–RAULTECNOLOGIA——–+”); PA_OutputSimpleText(1, 0, 23, “+——–RAULTECNOLOGIA——–+”);

for (i = 3; i < 23; i++){ PA_OutputSimpleText(1, 0, i, “|”); PA_OutputSimpleText(1, 31, i, “|”); }

PA_OutputSimpleText(1, comidax, comiday, “*”); PA_OutputSimpleText(1, fuelx, fuely, “F”); PA_OutputSimpleText(1, posx, posy, “O”); PA_PlaySimpleSound(dragon); // Infinite loop to keep the program running while (1) { if (posy > 3) { if(Pad.Held.Up)

{ PA_OutputSimpleText(1, posx, posy, ” “); posy-=1; PA_OutputSimpleText(1, posx, posy, “O”); } }

if (posy < 22) { if(Pad.Held.Down)

{ PA_OutputSimpleText(1, posx, posy, ” “); posy+=1; PA_OutputSimpleText(1, posx, posy, “O”); } }

if (posx >1) { if(Pad.Held.Left)

{ PA_OutputSimpleText(1, posx, posy, ” “); posx-=1; PA_OutputSimpleText(1, posx, posy, “O”); } }

if (posx < 30) { if(Pad.Held.Right)

{ PA_OutputSimpleText(1, posx, posy, ” “); posx+=1; PA_OutputSimpleText(1, posx, posy, “O”); } }

if ((posx-comidax)==0) { if((posy-comiday)==0) { comida(); puntos=puntos+1; PA_OutputText(1, 0, 0, “Puntos: %d  “, puntos); PA_OutputSimpleText(0,10,12,”Un punto   “); } }

if ((posx-fuelx)==0) { if((posy-fuely)==0) { quedafuel(); fuel=fuel+100; PA_OutputText(1, 15, 0, “Fuel: %d  “, fuel); PA_OutputSimpleText(0,10,12,”Fuel 100   “); } }

fuel=fuel-1; PA_OutputText(1, 15, 0, “Fuel: %d  “, fuel); if (fuel == 0) fin(); PA_WaitForVBL(); }

return 0; } // End of main()

Entradas recientes

Ver todo
Videojuegos con Tululoo GameMaker

Una explicación algo más detallada está en el blog que tenemos sobre GameMaker, del que Tululoo hereda varios elementos. #tululoo

 
 
 

Comentarios


3025674909|

©2020 por SM-MANUFACTURING. Creada con Wix.com

bottom of page