rendered paste body#include <pspdisplay.h>
#include <pspctrl.h> // Allows us to read input from the PSP's keys
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <png.h> // <Manipulate the PNG Image files
#include <stdio.h> // Has some C functions (sprintf() to parse strings)
#include <graphics.h>
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
#define printf pspDebugScreenPrintf
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) // Returns X if greater than Y, or returns Y if less
PSP_MODULE_INFO("Image Displayer", 0, 1, 1);
/* 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;
}
struct object {
int x;
int y;
int jumpspeed;
int state; // 0 = ground, 1 = jumping, 2 = falling
int gravity;
};
int main() {
SceCtrlData pad;
struct object box;
box.x = 50;
box.y = 230;
box.state=0;
box.jumpspeed=10;
box.gravity=230;
char jumpsped[100];
char gravity_ch[100];
//char buffer[200]; // Block of memory of 200 variables for a string (maximum length it can be)
Image* ourImage;
SetupCallbacks();
pspDebugScreenInit();
initGraphics();
//sprintf(buffer, "ourImage.png");
ourImage = loadImage("ourImage.png");
if(ourImage)
{
while(1)
{
sceCtrlPeekBufferPositive(&pad, 1); // Find out what the state of the control pad is
// Change the position of the box
if(pad.Buttons & PSP_CTRL_LEFT)
{
if(box.x>0)
{box.x=box.x-3;}
}
else if(pad.Buttons & PSP_CTRL_RIGHT)
{
if(box.x<480-32)
{box.x=box.x+3;}
}
if((pad.Buttons & PSP_CTRL_CROSS) && (box.state==0))
{box.state=1; box.jumpspeed=0;}
if(box.state==1 && box.jumpspeed<3.5)
{ box.y=box.y-0.8;
box.jumpspeed+=0.3;}
if (box.state==1 && box.jumpspeed>3.5)
{box.y=box.y-0.3;
//new line here to keep the jumpspeed increasing
box.jumpspeed+=0.3;}
if (box.state==1 && box.jumpspeed>=5);
{
box.state=2;
}
if (box.state==2)
{
box.jumpspeed=5;
box.y+=0.8;}
if (box.state==2 & box.y==230)
{box.y=230; box.state=0;
box.jumpspeed=0;}
// Wait for the end of the cycle
sceDisplayWaitVblankStart();
fillScreenRect(RGB(70, 130, 150), 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
blitAlphaImageToScreen(0 ,0 ,32 , 32, ourImage, box.x, box.y);
printTextScreen(70,70,"Hello",255);
sprintf(jumpsped, "Jumpspeed: %d ",box.jumpspeed);
sprintf(gravity_ch, "Gravity: %d ",box.gravity);
printTextScreen(0,0,jumpsped ,255);
printTextScreen(0,0, gravity_ch ,255);
flipScreen(); // Just updates the screen
}
}
sceKernelSleepThread(); // Wait for home
return 0;
}