Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************
- * Copyright (C) 2008 by Geecko *
- * *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
- ***************************************************************************/
- #include <pspkernel.h>
- #include <pspdebug.h>
- #include <stdio.h>
- #include <string.h>
- #include <pspgu.h>
- #include <pspdisplay.h>
- #include <pspctrl.h>
- #include <psprtc.h>
- #include "./librairies/danzeff.h"
- #include "./librairies/intraFont.h"
- #include "./librairies/graphics.h"
- PSP_MODULE_INFO("TestAge4PSP", 0, 1, 1);
- #define printf pspDebugScreenPrintf
- #define BUF_WIDTH (512)
- #define SCR_WIDTH (480)
- #define SCR_HEIGHT (272)
- enum colors { /* Définition des couleurs */
- RED = 0xFF0000FF,
- GREEN = 0xFF00FF00,
- BLUE = 0xFFFF0000,
- LITEBLUE = 0xFFFF9628,
- WHITE = 0xFFFFFFFF,
- LITEGRAY = 0xFFBFBFBF,
- GRAY = 0xFF7F7F7F,
- DARKGRAY = 0xFF3F3F3F,
- BLACK = 0xFF000000
- };
- /* Exit callback */
- int exit_callback(int arg1, int arg2, void *common) {
- sceKernelExitGame();
- return 0;}
- /* Callback thread */
- int CallbackThread(SceSize args, void *argp) {
- int cbid;
- cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
- sceKernelRegisterExitCallback(cbid);
- sceKernelSleepThreadCB();
- return 0;}
- /* Sets up the callback thread and returns its thread id */
- int SetupCallbacks(void) {
- int thid = 0;
- thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
- if(thid >= 0) sceKernelStartThread(thid, 0, 0);
- return thid; }
- /*--------------------------------------------------------------*
- * Main *
- *--------------------------------------------------------------*/
- int main(int argc, char *argv[])
- {
- pspDebugScreenInit();
- printf(" Chargement de l'OSK Danzeff... ");
- danzeff_load();
- printf("Termin\202.\n");
- printf(" Chargement d'intraFont... ");
- intraFontInit();
- intraFont* ifl = intraFontLoad("flash0:/font/ltn8.pgf",INTRAFONT_CACHE_MED);
- if (!ifl) { printf("Font load failed!\n"); }
- else { printf("Termin\202.\n"); }
- printf(" Chargement du fond... ");
- char image[200];
- sprintf(image, "./graphics/fond.png");
- Image* fond = loadImage(image);
- if (!fond) { printf("Erreur de chargement de l'image !\n"); }
- else { printf("Termin\202."); }
- SceCtrlData pad;
- sceCtrlSetSamplingCycle(0); // Pour le
- sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); // joystick.
- SetupCallbacks();
- initGraphics(); // Initialisation du GU.
- char texte[16], reponse1[64], reponse2[64], clignotant_b[1];
- unsigned char t=0 ,clavier=0, time=0, run=1, run2=1, active=0, max=0, titre=0, old_rtime=0;
- unsigned int clignotant=0, age=0;
- int date=0;
- pspTime rtime;
- do // Boucle Principale
- {
- do // Boucle pour la saisie
- {
- clearScreen(LITEBLUE);
- blitImageToScreen(0 ,0 ,480, 272, fond, 0, 0);
- guStart();
- if (titre != 25) titre++;
- intraFontSetStyle(ifl, 1.25f, BLACK, WHITE,INTRAFONT_ALIGN_CENTER);
- intraFontPrint(ifl,240,titre,"Test de votre age");
- intraFontSetStyle(ifl, 0.75f, BLACK, WHITE,INTRAFONT_ALIGN_CENTER);
- intraFontPrint(ifl,240,titre+15,"By Geecko");
- if (clavier == 0) {
- intraFontSetStyle(ifl, 1.0f, BLACK, WHITE,INTRAFONT_ALIGN_CENTER);
- intraFontPrint(ifl,240,135,"Saisissez un chiffre selon votre age.");
- intraFontPrint(ifl,240,160,"Pour commencer, appuyez sur X");
- sceCtrlReadBufferPositive(&pad, 1); // Lecture de la touche pressée
- if(pad.Buttons & PSP_CTRL_CROSS) clavier =1;
- }
- else if (clavier == 1) {
- intraFontSetStyle(ifl, 1.0f, BLACK, WHITE,INTRAFONT_ALIGN_LEFT);
- intraFontPrint(ifl,15,100,"Saisie de l'age :");
- sceCtrlReadBufferPositive(&pad, 1); // Lecture de la touche pressée
- t = danzeff_readInput(pad);
- switch (t)
- {
- case 0:
- break;
- case '\10':
- case DANZEFF_LEFT:
- if (active > 0)
- {
- active--;
- texte[active] = '\0';
- }
- break;
- case DANZEFF_RIGHT:
- if (active < max)
- {
- active++;
- texte[active] = '\0';
- active++;
- texte[active] = '\0';
- }
- break;
- case DANZEFF_SELECT:
- case DANZEFF_START:
- run =0;
- default:
- texte[active] = t;
- active++;
- texte[active] = '\0';
- break;
- }
- danzeff_moveTo(330,122); // Rendu du clavier Danzeff
- danzeff_render();
- sceGuEnable(GU_BLEND);
- clignotant = intraFontPrint(ifl,15,130,texte); /* Récupération de la taille en pixels /
- / de l'affichage du buffer "texte" */
- sprintf(clignotant_b,"|");
- time++; //
- if (time == 15){ // Actualisation
- sceRtcGetCurrentClockLocalTime(&rtime); // des secondes.
- time = 0; } //
- if (old_rtime == 0) old_rtime = rtime.seconds; //
- else if (rtime.seconds == old_rtime+1) { // Affichage
- intraFontSetStyle(ifl, 1.0f, BLACK, 0,INTRAFONT_ALIGN_LEFT); // du "|"
- intraFontPrint(ifl,clignotant,129,clignotant_b); } // en fonction
- else if (rtime.seconds == old_rtime+2) old_rtime = 0; // des secondes.
- else if (old_rtime >= 3) old_rtime = 0; //
- }
- sceGuFinish();
- sceGuSync(0,0);
- sceDisplayWaitVblankStart(); // VSync
- flipScreen(); // Echange des buffers pour avoir le rendu à l'écran
- } while (run); // Fin de la boucle pour la saisie
- old_rtime = 0;
- sceRtcGetCurrentClockLocalTime(&rtime);
- sscanf(texte,"%d", &age);
- date = rtime.year - age;
- run =1;
- do // Boucle pour l'affichage du résultat
- {
- clearScreen(LITEBLUE);
- blitImageToScreen(0 ,0 ,480 , 272, fond, 0, 0);
- guStart();
- intraFontSetStyle(ifl, 1.25f, BLACK, WHITE,INTRAFONT_ALIGN_CENTER);
- intraFontPrint(ifl,240,25,"Test de votre age");
- intraFontSetStyle(ifl, 0.75f, BLACK, WHITE,INTRAFONT_ALIGN_CENTER);
- intraFontPrint(ifl,240,40,"By Geecko");
- intraFontSetStyle(ifl, 1.0f, BLACK, WHITE,INTRAFONT_ALIGN_CENTER);
- if (age >= 1)
- {
- if (age > 120)
- {
- sprintf(reponse1,"Tu serais ne en %d...", date);
- sprintf(reponse2,"Tu mens j'espere ?");
- }
- else if (age < 120)
- {
- sprintf(reponse1,"Tu es ne en %d !", date);
- if (age > 75)
- {
- sprintf(reponse2,"Salut vieux crouton !");
- }
- else if (age > 25)
- {
- sprintf(reponse2,"Salut l'adulte !");
- }
- else if (age > 17)
- {
- sprintf(reponse2,"Salut jeune adulte !");
- }
- else if (age > 11)
- {
- sprintf(reponse2,"Salut ado !");
- }
- else if (age > 3)
- {
- sprintf(reponse2,"Salut sale gosse !");
- }
- else
- {
- sprintf(reponse2,"Salut petit bebe !");
- }
- }
- }
- else
- {
- if (age == 0)
- {
- sprintf(reponse1,"Tu n'as pas encore eu ton premier anniversaire !");
- sprintf(reponse2,"Salut petit bebe !");
- }
- else if (age < 0)
- {
- sprintf(reponse1,"Tu ne serais pas ne ! Arrete de mentir !");
- }
- }
- intraFontPrint(ifl,240,135,reponse1); // Affichage des réponses
- intraFontPrint(ifl,240,160,reponse2);
- intraFontPrint(ifl,240,260,"X pour recommencer, O pour retourner au XMB :)");
- sceGuFinish();
- sceGuSync(0,0);
- sceDisplayWaitVblankStart(); // VSync
- flipScreen(); // Echange des buffers pour avoir le rendu à l'écran
- sceCtrlReadBufferPositive(&pad, 1); // Lecture de la touche pressée
- if(pad.Buttons & PSP_CTRL_CROSS) run =0;
- else if(pad.Buttons & PSP_CTRL_CIRCLE) run =0, run2 =0;
- } while (run); // Fin de la boucle pour l'affichage du résultat
- clavier=1, run=1, active=0, max=0, date=0, age=0, t=0;
- memset (texte, 0, sizeof (texte)); // Réinitialise la chaîne de caractères 1
- memset (reponse1, 0, sizeof (reponse1)); // Réinitialise la chaîne de caractères 2
- memset (reponse2, 0, sizeof (reponse2)); // Réinitialise la chaîne de caractères 3
- } while (run2); // Fin de la boucle principale
- sceGuTerm(); // Extinction du GU.
- sceKernelExitGame();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement