Code: Select all
//Oslib header file
#include <oslib/oslib.h>
//This is needed for eboot
PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
//this creates pointers for our images.
OSL_IMAGE *sprite, *sprite2, *sprite3;
//definations
#define DOWN 0
#define UP 35
#define RIGHT 70
#define LEFT 105
//variables
int sprite_position;
int sprite_march;
//declare the function like buttons and spriteAnimation
void Buttons();
void SpriteAnimate();
int collision(OSL_IMAGE *img1,float img1posX, float img1posY, OSL_IMAGE *img2, float img2posX, float img2posY,OSL_IMAGE *img3, float img3posX, float img3posY );
int main()
{
//start the Oslib library
oslInit(0);
//start the graphixs mode
oslInitGfx(OSL_PF_8888, 1);
//sets the transparency color
oslSetTransparentColor(RGB(255,0,255));
//loads the images into memory
sprite = oslLoadImageFile("sprite.png", OSL_IN_RAM, OSL_PF_5551);
sprite2 = oslLoadImageFile("sprite2.png", OSL_IN_RAM, OSL_PF_5551);
sprite3 = oslLoadImageFile("sprite3.png", OSL_IN_RAM, OSL_PF_5551);
//Disables the transparent color so it cannot be used again
oslDisableTransparentColor();
//sees if all files are avaiable
if (!sprite || !sprite2||!sprite3)
oslDebug("! one or more of the files were missing, the program cannot run");
//Sets the sprites original position, lets see if i can get 2 sprites on da bloody screen
sprite->x = 155;
sprite->y = 95;
sprite_position = DOWN;
//sets second sprite position
sprite2->x = 230;
sprite2->y = 130;
//sets thrid sprite pos
sprite3->x = 270;
sprite3->y = 130;
//main while loop
while (!osl_quit)
{
//to be able ot draw on the screen
oslStartDrawing();
//Buttons
Buttons();
//draws a green background
oslDrawGradientRect(0,0,480,272,RGB(0,128,0),RGB(0,128,0), RGB(128,255,128), RGB(128,255,128));
//this draws the images to the screen
oslDrawImage(sprite);
oslDrawImage(sprite2);
oslDrawImage(sprite3);
//stops the drawing mode
oslEndDrawing();
//sync the screen
oslSyncFrame();
}
//terminate the program
oslEndGfx();
oslQuit();
return 0;
}
void Buttons()
{
//starts up the psp buttons
oslReadKeys();
if (osl_keys->held.down)
{
if(!collision(sprite, sprite->x, sprite->y + 2, sprite2, sprite2->x, sprite2->y, sprite3, sprite3->x, sprite3->y ))
{
//sprite movement
sprite->y +=2;
//sets sprite position on sprite sheet
sprite_position = DOWN;
//calls sprie animate
SpriteAnimate();
}
}
if (osl_keys->held.up)
{
if(!collision(sprite, sprite->x, sprite->y - 2, sprite2, sprite2->x, sprite2->y,sprite3, sprite3->x, sprite3->y ))
{
sprite->y-= 2;
sprite_position = UP;
SpriteAnimate();
}
}
if (osl_keys->held.right)
{
if(!collision(sprite, sprite->x + 2, sprite->y, sprite2, sprite2->x, sprite2->y,sprite3, sprite3->x, sprite3->y ))
{
sprite->x += 2;
sprite_position = RIGHT;
SpriteAnimate();
}
}
if (osl_keys->held.left)
{
if(!collision(sprite, sprite->x - 2, sprite->y, sprite2, sprite2->x, sprite2->y,sprite3, sprite3->x, sprite3->y ))
{
sprite->x -= 2;
sprite_position = LEFT;
SpriteAnimate();
}
}
//If a button is not pressed
if (!osl_keys->held.value)
{
//Start the variable over for when a button is pressed again
sprite_march = 0;
//Sets the sprite's direction
oslSetImageTileSize(sprite,0,sprite_position,22,35);
}
}
void SpriteAnimate()
{
//Moves the sprite in the row that it is in
sprite_march++;
//Moves the sprite constantly
oslSetImageTileSize(sprite,(sprite_march * 22),sprite_position,22,35);
//resets the sprite movement in that row
if (sprite_march == 6) sprite_march = 0;
}
int collision(OSL_IMAGE *img1,float img1posX, float img1posY, OSL_IMAGE *img2, float img2posX, float img2posY, OSL_IMAGE *img3, float img3posX, float img3posY )
{
int collision;
collision = 0;
float img1width = img1->stretchX;
float img1height = img1->stretchY;
float img2width = img2->stretchX;
float img2height = img2->stretchY;
float img3width = img3->stretchX;
float img3height = img3->stretchY;
if ((img1posX + img1width > img2posX) &&
(img1posX < img2posX + img2width) &&
(img1posX + img1width > img3posX) &&
(img1posX < img2posX + img3width) &&
(img1posY + img1height > img2posY) &&
(img1posY < img2posY + img2height) )
{
collision = 1;
}
return collision;
}
Code: Select all
if ((img1posX + img1width > img2posX) &&
(img1posX < img2posX + img2width) &&
[B] (img1posX + img1width > img3posX) &&
(img1posX < img2posX + img3width) &&[/B]
(img1posY + img1height > img2posY) &&
(img1posY < img2posY + img2height) )
{
if i put that in, none of the sprites have collision but if i take out the Bolded parts the first sprite has collision but the second one dose not.(second sprite as in the second object, not the character that is moving). How do i modify this correctly for every new object on the screen? help will be greatly appreciated.