Zitat:
#include <stdio.h>
#include <oslib/oslib.h>
#include <math.h>
//Necessary to create eboot
PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THRE AD_ATTR_USER | THREAD_ATTR_VFPU);
//declaration of the pointers of our images
OSL_IMAGE *background,*A,*B;
int collided;
int hit;
int Ax=100, Ay = 100, Awidth = 32, Aheight = 32, Bx = 200, By = 100, Bwidth = 32, Bheight = 32;
int collision(int Ax, int Ay, int Awidth, int Aheight, int Bx, int By, int Bwidth, int Bheight){
int hit=0;
if ((Ax >= Bx && Ax <= (Bx+Bwidth)) && (Ay >= By && Ay <= (By+Bheight)))
{
hit = 1;
}
if (((Ax+Awidth) >= Bx && (Ax+Awidth) <= (Bx+Bwidth)) && (Ay >= By && Ay <= (By+Bheight))) {
hit = 1;
}
if ((Ax >= Bx && Ax <= (Bx+Bwidth)) && ((Ay+Aheight) >= By && (Ay+Aheight) <= (By+Bheight))) {
hit = 1;
}
if (((Ax+Awidth) >= Bx && (Ax+Awidth) <= (Bx+Bwidth)) && ((Ay+Aheight) >= By && (Ay+Aheight) <= (By+Bheight))) {
hit = 1;
}
return hit;
}
int main(int argc, char **argv)
{
//Initialization of the Oslib library
oslInit(0);
//Initialization of the graphics mode
oslInitGfx(OSL_PF_8888, 1);
oslInitConsole(); //Text
oslSetTransparentColor(RG B(255,0,255));
//loads our images into memory
A = oslLoadImageFile("A.png", OSL_IN_RAM, OSL_PF_5551);
B = oslLoadImageFile("B.png", OSL_IN_RAM, OSL_PF_5551);
background = oslLoadImageFile("backgro und.png", OSL_IN_RAM, OSL_PF_5551);
//stuff
A->x =Ax;
A->y =Ay;
B->x =Bx;
B->y =By;
//position
A->x =100;
A->y =100;
B->x=200;
B->y=100;
//main while loop
while (!osl_quit)
{
//To be able to draw on the screen
oslStartDrawing();
//Clear the screen
oslCls();
//initiate the PSP's buttons
oslReadKeys();
oslDrawImage(background);
oslDrawImage(A);
oslDrawImage(B);
if(hit==1)oslPrintf_xy(10 ,10,"collision is positive");
if(collision(Ax, Ay, Awidth, Aheight, Bx, By, Bwidth, Bheight)) {
collided = 1;}
if(collided==1) {
oslPrintf_xy(10,30,"colli sion is +");}
if(osl_keys->held.right) A->x+=1;
if(osl_keys->held.left) A->x-=1;
if(osl_keys->held.up) A->y-=1;
if(osl_keys->held.down) A->y+=1;
//Ends drawing mode
oslEndDrawing();
//Synchronizes the screen
oslSyncFrame();
}
//Terminate the program
oslEndGfx();
oslQuit();
return 0;
}