#include <oslib/oslib.h>
#include <ctype.h>
#include <oslib/drawing.h>
PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
OSL_IMAGE *fond, *mickey;
int i;
void Keys();
void Text();
int main(int argc, char* argv[])
{
//Initialization
oslInit(0); //The lib
oslInitGfx(OSL_PF_8888, 1); //Gfx
oslInitConsole(); //Text
oslShowNeoflashLogo();
//Load the files
fond = oslLoadImageFile("fond.png", OSL_IN_RAM, OSL_PF_5551);
mickey = oslLoadImageFile("mickey.png", OSL_IN_RAM, OSL_PF_5551);
if (!fond || !mickey)
oslFatalError("At least one file is missing. Please copy all the file in the game directory.");
oslCorrectImageHalfBorder(mickey); //debug for the bilinear
//Configure the joypad
oslSetKeyAutorepeatInit(40);
oslSetKeyAutorepeatInterval(10);
//Initialize variables
mickey->centerX = mickey->sizeX / 2; //Rotation center of the mickey's sprite
mickey->centerY = mickey->sizeY / 2;
mickey->x = 240; //Place mickey at the center of the screen
mickey->y = 136;
while (!osl_quit)
{
oslStartDrawing();
Keys();
oslDrawImage(fond); //First draw the background...
Text(); //Then the text...
oslDrawImage(mickey); //And mickey at the end
oslEndDrawing();
oslSyncFrame();
}
oslEndGfx();
oslQuit();
return 0;
}
void Keys()
{
oslReadKeys();
//joypad (move mickey on the screen)
if (osl_keys->held.down) mickey->y += 2;
if (osl_keys->held.up) mickey->y -= 2;
if (osl_keys->held.left) mickey->x -= 2;
if (osl_keys->held.right) mickey->x += 2;
//joystick (deform mickey)
for (i=24;i<=120;i+=16)
{
if (osl_keys->analogX > i) mickey->stretchX++;
if (osl_keys->analogY > i) mickey->stretchY++;
if (osl_keys->analogX < -i) mickey->stretchX--;
if (osl_keys->analogY < -i) mickey->stretchY--;
}
//buttons
if (osl_keys->held.square) { mickey->stretchX++; mickey->stretchY++; } //zoom mickey
if (osl_keys->held.circle) { mickey->stretchX--; mickey->stretchY--; }
if (osl_keys->pressed.cross) oslSetBilinearFilter(1); //smooth or not
if (osl_keys->pressed.triangle) oslSetBilinearFilter(0);
if (osl_keys->held.L) mickey->angle -= 2; //make a rotation to mickey
if (osl_keys->held.R) mickey->angle += 2;
if (osl_keys->pressed.start) oslQuit(); //exit the sample
}
void Text()
{
//set the color of the text
oslSetTextColor(RGBA(0,0,0,255));
oslSetBkColor(RGBA(0,0,0,0));
oslPrintf_xy(1,5,"OSLib Sprite sample");
oslPrintf_xy(1,25,"Joypad to move mickey");
oslPrintf_xy(1,35,"Joystick to deform mickey");
oslPrintf_xy(1,45,"[] & () to zoom mickey");
oslPrintf_xy(1,55,"L & R to make a rotation");
oslPrintf_xy(1,65,"X & ^ to smoothing");
oslPrintf_xy(1,75,"Start to Quit");
}