Advertisement
GeeckoDev

TestAge4PSP

Apr 14th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.46 KB | None | 0 0
  1. /***************************************************************************
  2.  *   Copyright (C) 2008 by Geecko                                          *
  3.  *                                                                         *
  4.  *                                                                         *
  5.  *   This program is free software; you can redistribute it and/or modify  *
  6.  *   it under the terms of the GNU General Public License as published by  *
  7.  *   the Free Software Foundation; either version 2 of the License, or     *
  8.  *   (at your option) any later version.                                   *
  9.  *                                                                         *
  10.  *   This program is distributed in the hope that it will be useful,       *
  11.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  12.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  13.  *   GNU General Public License for more details.                          *
  14.  *                                                                         *
  15.  *   You should have received a copy of the GNU General Public License     *
  16.  *   along with this program; if not, write to the                         *
  17.  *   Free Software Foundation, Inc.,                                       *
  18.  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  19.  ***************************************************************************/
  20.  
  21. #include <pspkernel.h>
  22. #include <pspdebug.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <pspgu.h>
  26. #include <pspdisplay.h>
  27. #include <pspctrl.h>
  28. #include <psprtc.h>
  29. #include "./librairies/danzeff.h"
  30. #include "./librairies/intraFont.h"
  31. #include "./librairies/graphics.h"
  32.  
  33. PSP_MODULE_INFO("TestAge4PSP", 0, 1, 1);
  34.  
  35. #define printf pspDebugScreenPrintf
  36. #define BUF_WIDTH (512)
  37. #define SCR_WIDTH (480)
  38. #define SCR_HEIGHT (272)
  39.  
  40. enum colors {   /* Définition des couleurs */
  41.         RED = 0xFF0000FF,
  42.         GREEN = 0xFF00FF00,
  43.         BLUE =  0xFFFF0000,
  44.         LITEBLUE =  0xFFFF9628,
  45.         WHITE = 0xFFFFFFFF,
  46.         LITEGRAY = 0xFFBFBFBF,
  47.         GRAY =  0xFF7F7F7F,
  48.         DARKGRAY = 0xFF3F3F3F, 
  49.         BLACK = 0xFF000000
  50.         };
  51.  
  52. /* Exit callback */
  53. int exit_callback(int arg1, int arg2, void *common) {
  54.           sceKernelExitGame();
  55.           return 0;}
  56.  
  57. /* Callback thread */
  58. int CallbackThread(SceSize args, void *argp) {
  59.           int cbid;
  60.           cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
  61.           sceKernelRegisterExitCallback(cbid);
  62.           sceKernelSleepThreadCB();
  63.           return 0;}
  64.  
  65. /* Sets up the callback thread and returns its thread id */
  66. int SetupCallbacks(void) {
  67.           int thid = 0;
  68.           thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
  69.           if(thid >= 0) sceKernelStartThread(thid, 0, 0);
  70.           return thid; }
  71.  
  72.  
  73. /*--------------------------------------------------------------*
  74.  *                             Main                             *              
  75.  *--------------------------------------------------------------*/
  76.  
  77. int main(int argc, char *argv[])
  78. {
  79.     pspDebugScreenInit();
  80.     printf(" Chargement de l'OSK Danzeff...  ");
  81.       danzeff_load();
  82.     printf("Termin\202.\n");
  83.     printf(" Chargement d'intraFont...  ");
  84.       intraFontInit();
  85.       intraFont* ifl = intraFontLoad("flash0:/font/ltn8.pgf",INTRAFONT_CACHE_MED);
  86.       if (!ifl) { printf("Font load failed!\n"); }
  87.     else { printf("Termin\202.\n"); }
  88.     printf(" Chargement du fond...  ");
  89.       char image[200];
  90.       sprintf(image, "./graphics/fond.png");
  91.       Image* fond = loadImage(image);
  92.       if (!fond) { printf("Erreur de chargement de l'image !\n"); }
  93.     else { printf("Termin\202."); }
  94.     SceCtrlData pad;
  95.     sceCtrlSetSamplingCycle(0);                    // Pour le
  96.     sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);  // joystick.
  97.     SetupCallbacks();
  98.     initGraphics();                                // Initialisation du GU.
  99.  
  100.     char texte[16], reponse1[64], reponse2[64], clignotant_b[1];
  101.     unsigned char t=0 ,clavier=0, time=0, run=1, run2=1, active=0, max=0, titre=0, old_rtime=0;
  102.     unsigned int clignotant=0, age=0;
  103.     int date=0;
  104.     pspTime rtime;
  105.  
  106.     do // Boucle Principale
  107.     {
  108.         do // Boucle pour la saisie
  109.         {
  110.         clearScreen(LITEBLUE);
  111.         blitImageToScreen(0 ,0 ,480, 272, fond, 0, 0);
  112.         guStart();
  113.  
  114.           if (titre != 25) titre++;
  115.         intraFontSetStyle(ifl, 1.25f, BLACK, WHITE,INTRAFONT_ALIGN_CENTER);
  116.         intraFontPrint(ifl,240,titre,"Test de votre age");
  117.         intraFontSetStyle(ifl, 0.75f, BLACK, WHITE,INTRAFONT_ALIGN_CENTER);
  118.         intraFontPrint(ifl,240,titre+15,"By Geecko");
  119.  
  120.           if (clavier == 0) {
  121.           intraFontSetStyle(ifl, 1.0f, BLACK, WHITE,INTRAFONT_ALIGN_CENTER);
  122.           intraFontPrint(ifl,240,135,"Saisissez un chiffre selon votre age.");
  123.           intraFontPrint(ifl,240,160,"Pour commencer, appuyez sur X");
  124.           sceCtrlReadBufferPositive(&pad, 1);  // Lecture de la touche pressée
  125.           if(pad.Buttons & PSP_CTRL_CROSS) clavier =1;
  126.           }
  127.  
  128.           else if (clavier == 1) {
  129.           intraFontSetStyle(ifl, 1.0f, BLACK, WHITE,INTRAFONT_ALIGN_LEFT);
  130.           intraFontPrint(ifl,15,100,"Saisie de l'age :");
  131.           sceCtrlReadBufferPositive(&pad, 1);  // Lecture de la touche pressée
  132.           t = danzeff_readInput(pad);
  133.           switch (t)
  134.           {
  135.               case 0:
  136.               break;
  137.               case '\10':
  138.               case DANZEFF_LEFT:
  139.               if (active > 0)
  140.               {
  141.             active--;
  142.             texte[active] = '\0';
  143.               }
  144.               break;
  145.               case DANZEFF_RIGHT:
  146.               if (active < max)
  147.               {
  148.             active++;
  149.             texte[active] = '\0';
  150.             active++;
  151.             texte[active] = '\0';
  152.               }
  153.               break;
  154.               case DANZEFF_SELECT:
  155.               case DANZEFF_START:
  156.               run =0;
  157.               default:
  158.             texte[active] = t;
  159.             active++;
  160.             texte[active] = '\0';
  161.               break;
  162.           }
  163.  
  164.           danzeff_moveTo(330,122);         // Rendu du clavier Danzeff
  165.           danzeff_render();  
  166.           sceGuEnable(GU_BLEND);
  167.  
  168.           clignotant = intraFontPrint(ifl,15,130,texte);        /* Récupération de la taille en pixels /
  169.                                         /  de l'affichage du buffer "texte"   */
  170.           sprintf(clignotant_b,"|");
  171.  
  172.           time++;                           //
  173.           if (time == 15){                      // Actualisation
  174.           sceRtcGetCurrentClockLocalTime(&rtime);           // des secondes.
  175.           time = 0; }                           //
  176.           if (old_rtime == 0) old_rtime = rtime.seconds;        //
  177.           else if (rtime.seconds == old_rtime+1) {          // Affichage
  178.           intraFontSetStyle(ifl, 1.0f, BLACK, 0,INTRAFONT_ALIGN_LEFT);  // du "|"
  179.           intraFontPrint(ifl,clignotant,129,clignotant_b); }        // en fonction
  180.           else if (rtime.seconds == old_rtime+2) old_rtime = 0;     // des secondes.
  181.           else if (old_rtime >= 3) old_rtime = 0;           //
  182.           }
  183.  
  184.         sceGuFinish();
  185.         sceGuSync(0,0);    
  186.         sceDisplayWaitVblankStart();   // VSync
  187.         flipScreen();                  // Echange des buffers pour avoir le rendu à l'écran
  188.         } while (run); // Fin de la boucle pour la saisie
  189.  
  190.         old_rtime = 0;
  191.         sceRtcGetCurrentClockLocalTime(&rtime);
  192.         sscanf(texte,"%d", &age);
  193.         date = rtime.year - age;
  194.         run =1;
  195.  
  196.         do // Boucle pour l'affichage du résultat
  197.         {
  198.         clearScreen(LITEBLUE);
  199.         blitImageToScreen(0 ,0 ,480 , 272, fond, 0, 0);
  200.         guStart();
  201.         intraFontSetStyle(ifl, 1.25f, BLACK, WHITE,INTRAFONT_ALIGN_CENTER);
  202.         intraFontPrint(ifl,240,25,"Test de votre age");
  203.         intraFontSetStyle(ifl, 0.75f, BLACK, WHITE,INTRAFONT_ALIGN_CENTER);
  204.         intraFontPrint(ifl,240,40,"By Geecko");
  205.         intraFontSetStyle(ifl, 1.0f, BLACK, WHITE,INTRAFONT_ALIGN_CENTER);
  206.  
  207.         if (age >= 1)
  208.         {
  209.             if (age > 120)
  210.             {
  211.             sprintf(reponse1,"Tu serais ne en %d...", date);
  212.             sprintf(reponse2,"Tu mens j'espere ?");
  213.             }
  214.             else if (age < 120)
  215.             {
  216.             sprintf(reponse1,"Tu es ne en %d !", date);
  217.             if (age > 75)
  218.             {
  219.             sprintf(reponse2,"Salut vieux crouton !");
  220.             }
  221.             else if (age > 25)
  222.             {
  223.             sprintf(reponse2,"Salut l'adulte !");
  224.             }
  225.             else if (age > 17)
  226.             {
  227.             sprintf(reponse2,"Salut jeune adulte !");
  228.             }
  229.             else if (age > 11)
  230.             {
  231.             sprintf(reponse2,"Salut ado !");
  232.             }
  233.             else if (age > 3)
  234.             {
  235.             sprintf(reponse2,"Salut sale gosse !");
  236.             }
  237.             else
  238.             {
  239.             sprintf(reponse2,"Salut petit bebe !");
  240.             }
  241.             }
  242.         }
  243.         else
  244.         {
  245.             if (age == 0)
  246.             {
  247.             sprintf(reponse1,"Tu n'as pas encore eu ton premier anniversaire !");
  248.             sprintf(reponse2,"Salut petit bebe !");
  249.             }
  250.             else if (age < 0)
  251.             {
  252.             sprintf(reponse1,"Tu ne serais pas ne ! Arrete de mentir !");
  253.             }
  254.         }
  255.         intraFontPrint(ifl,240,135,reponse1);    // Affichage des réponses
  256.         intraFontPrint(ifl,240,160,reponse2);
  257.  
  258.         intraFontPrint(ifl,240,260,"X pour recommencer, O pour retourner au XMB :)");
  259.         sceGuFinish();
  260.         sceGuSync(0,0);    
  261.         sceDisplayWaitVblankStart();         // VSync
  262.         flipScreen();                // Echange des buffers pour avoir le rendu à l'écran
  263.         sceCtrlReadBufferPositive(&pad, 1);  // Lecture de la touche pressée
  264.         if(pad.Buttons & PSP_CTRL_CROSS) run =0;
  265.         else if(pad.Buttons & PSP_CTRL_CIRCLE) run =0, run2 =0;
  266.         } while (run);  // Fin de la boucle pour l'affichage du résultat
  267.  
  268.     clavier=1, run=1, active=0, max=0, date=0, age=0, t=0;
  269.     memset (texte, 0, sizeof (texte));   // Réinitialise la chaîne de caractères 1
  270.     memset (reponse1, 0, sizeof (reponse1)); // Réinitialise la chaîne de caractères 2
  271.     memset (reponse2, 0, sizeof (reponse2)); // Réinitialise la chaîne de caractères 3
  272.  
  273.     } while (run2); // Fin de la boucle principale
  274.  
  275.     sceGuTerm();        // Extinction du GU.
  276.     sceKernelExitGame();
  277.     return 0;
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement