 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
flyboy2012
Joined: 07 Oct 2008 Posts: 11
|
Posted: Thu Oct 09, 2008 7:56 am Post subject: selecting images |
|
|
hello i am trying to select an image with an image and i was hopeing someone here new how
i found this .lua script and it has what i need for my app but i dont know how to wright it in old school lib code
here is the .lua script lines that i need to convert
| Code: | --Start button
if strtwndw == 0 and pointx>1 and pointx<84 and pointy>248 and pointy<272 and pad:cross() and oldpad:cross() ~= pad:cross() then
System.currentDirectory()
appsDir = System.currentDirectory()
System.currentDirectory("ms0:/PSP/Game/CRWindowsPSP")
strtwndw = 1
idletm=0
end |
how would i wright that? |
|
| Back to top |
|
 |
Noko
Joined: 06 Sep 2008 Posts: 23
|
Posted: Fri Oct 10, 2008 6:34 pm Post subject: |
|
|
> old school lib code
...what? |
|
| Back to top |
|
 |
flyboy2012
Joined: 07 Oct 2008 Posts: 11
|
Posted: Sun Oct 12, 2008 5:07 am Post subject: |
|
|
the code you use in the main.c
like
| Code: | | oslDrawImage(background); |
osl stands for old school library |
|
| Back to top |
|
 |
Onii
Joined: 05 Oct 2008 Posts: 40
|
Posted: Sun Oct 12, 2008 6:14 am Post subject: |
|
|
| My guess is you're looking for a c tutorial. Search for one on google. |
|
| Back to top |
|
 |
flyboy2012
Joined: 07 Oct 2008 Posts: 11
|
Posted: Sun Oct 12, 2008 7:37 am Post subject: |
|
|
| tryed that |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sun Oct 12, 2008 7:47 am Post subject: |
|
|
| The problem is that you aren't defining the problem accurately or completely. Until you can describe what you are trying to do properly, no one can help. |
|
| Back to top |
|
 |
Dariusc123456
Joined: 12 Aug 2008 Posts: 394
|
Posted: Sun Oct 12, 2008 9:10 am Post subject: |
|
|
| I think he asking for a lua to C convertion to use OSLibs . |
|
| Back to top |
|
 |
flyboy2012
Joined: 07 Oct 2008 Posts: 11
|
Posted: Sun Oct 12, 2008 3:26 pm Post subject: Re: selecting images |
|
|
| flyboy2012 wrote: | | hello i am trying to select an image with an image |
that is what i want to do how can i be more sepefic? |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sun Oct 12, 2008 5:55 pm Post subject: Re: selecting images |
|
|
| flyboy2012 wrote: | | flyboy2012 wrote: | | hello i am trying to select an image with an image |
that is what i want to do how can i be more sepefic? |
Do you mean like a file requester that uses pictures instead of filenames? If so, you have to do that all yourself by hand. If you don't know how to do that, you should probably consult a forum that handles general programming. We don't do that here. |
|
| Back to top |
|
 |
flyboy2012
Joined: 07 Oct 2008 Posts: 11
|
Posted: Thu Oct 16, 2008 11:30 pm Post subject: |
|
|
a friend sent me this and yes this is what i was asking for
| Code: |
#include <oslib/oslib.h>
PSP_MODULE_INFO("Desktop", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
PSP_HEAP_SIZE_KB(20*1024);
int initOSLib()
{
oslInit(0);
oslInitGfx(OSL_PF_8888, 1);
oslSetQuitOnLoadFailure(1);
oslSetKeyAutorepeatInit(40);
oslSetKeyAutorepeatInterval(10);
return 0;
}
int endOSLib()
{
oslEndGfx();
osl_quit = 1;
sceKernelExitGame();
return 0;
}
int collision(int x0, int y0, int x1, int y1, int w0, int h0, int w1, int h1)
{
int hit = 0;
if(x0+w0 > x1 && x0 < x1+w1 && y0+h0 > y1 && y0 < y1+h1)hit = 1;
return hit;
}
int main()
{
initOSLib();//Call the function made before
//Set item starting positions
int item1X = 50;
int item1Y = 50;
int item2X = 50;
int item2Y = 70;
int item3X = 50;
int item3Y = 90;
//Set cursors starting position
int cursorX = 0;
int cursorY = 0;
//Load the background and cursor
OSL_IMAGE* BG = oslLoadImageFilePNG("background.png", OSL_IN_RAM|OSL_SWIZZLED, OSL_PF_8888);
OSL_IMAGE* cursor = oslLoadImageFilePNG("cursor.png", OSL_IN_RAM|OSL_SWIZZLED, OSL_PF_8888);
while(!osl_quit)//Main loop
{
oslStartDrawing();//Start drawing
oslReadKeys();//Read the PSP's keys
oslDrawImage(BG);//Draw the background
oslDrawFillRect(item1X, item1Y, item1X+10, item1Y+10, RGB(255, 0, 0));//Draw item 1
oslDrawFillRect(item2X, item2Y, item2X+10, item2Y+10, RGB(0, 255, 0));//Draw item 2
oslDrawFillRect(item3X, item3Y, item3X+10, item3Y+10, RGB(0, 0, 255));//Draw item 3
oslDrawImageXY(cursor, cursorX, cursorY);//Draw the cursor
if(osl_keys->held.cross)//If cross is pressed
{
if(collision(cursorX, cursorY, item1X, item1Y, 10, 10, 10, 10) && !(collision(cursorX, cursorY, item2X, item2Y, 10, 10, 10, 10)) && !(collision(cursorX, cursorY, item3X, item3Y, 10, 10, 10, 10)))//If the cursor is on the first item and not on the other two
{
//Set the items X & Y to the cursors
item1X = cursorX;
item1Y = cursorY;
}
if(collision(cursorX, cursorY, item2X, item2Y, 10, 10, 10, 10) && !(collision(cursorX, cursorY, item1X, item1Y, 10, 10, 10, 10)) && !(collision(cursorX, cursorY, item3X, item3Y, 10, 10, 10, 10)))//If the cursor is on the second item and not on the other two
{
//Set the items X & Y to the cursors
item2X = cursorX;
item2Y = cursorY;
}
if(collision(cursorX, cursorY, item3X, item3Y, 10, 10, 10, 10) && !(collision(cursorX, cursorY, item1X, item1Y, 10, 10, 10, 10)) && !(collision(cursorX, cursorY, item2X, item2Y, 10, 10, 10, 10)))//If the cursor is on the third item and not on the other two
{
//Set the items X & Y to the cursor's
item3X = cursorX;
item3Y = cursorY;
}
}
//Controls for the cursor
if(osl_keys->held.left)cursorX -= 2;
if(osl_keys->held.right)cursorX += 2;
if(osl_keys->held.up)cursorY -= 2;
if(osl_keys->held.down)cursorY += 2;
//Exit if start is pressed
if(osl_keys->pressed.start)endOSLib();
//End drawing, frame .etc...
oslEndDrawing();
oslEndFrame();
oslSyncFrame();
}//End of main loop
return 1;
}
|
|
|
| Back to top |
|
 |
PosX100
Joined: 15 Aug 2007 Posts: 98
|
Posted: Fri Oct 17, 2008 1:47 am Post subject: |
|
|
Well , you really need to learn C.
You don't have to be an expert to tell if the above code posted above is
really bad ...
Here's how you can make it look prettier/efficient and , faster ...
Init & end functions return...nothing , so why you return data?
| Code: |
void initOSLib()
{
oslInit(0);
oslInitGfx(OSL_PF_8888, 1);
oslSetQuitOnLoadFailure(1);
oslSetKeyAutorepeatInit(40);
oslSetKeyAutorepeatInterval(10);
}
void endOSLib()
{
oslEndGfx();
osl_quit = 1;
sceKernelExitGame();
}
|
Dirty "collision detection" function which makes no sense with the variable names,
you can do this:
| Code: |
static bool collide( const TVector2* v1, const TVector2* v2)
{
return ( ( v1->x + v1->w > v2->x ) && ( v1->x < v2->x +v2->w )
&&( v1->y + v1->h > v2->y ) && ( v1->y < v2->y +v2->h ));
}
|
Main loop is really messy , so ... here's a quick example of the right way doing it:
| Code: |
int main ( ... )
{
initOSLib();
while ( application->isRunning() )
{
clear
begin drawing
switch ( application->getStateStack().top() )
{
case GAMEPLAY:
{
draw something
break;
}
}
end drawing
handle input , timers & "physics"
present
}
endOSLib();
}
|
To sum everything up : learn the basics , then make games ...
(also , feel free to kill your friend :-P ) |
|
| Back to top |
|
 |
flyboy2012
Joined: 07 Oct 2008 Posts: 11
|
Posted: Thu Oct 23, 2008 12:15 pm Post subject: |
|
|
| i posted in the wrong spot please excuse my mistake |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|