selecting images

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
flyboy2012
Posts: 11
Joined: Tue Oct 07, 2008 8:50 am

selecting images

Post by flyboy2012 »

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: Select all

--Start button
if strtwndw == 0 and pointx>1 and pointx<84 and pointy>248 and pointy<272 and pad&#58;cross&#40;&#41; and oldpad&#58;cross&#40;&#41; ~= pad&#58;cross&#40;&#41; then
System.currentDirectory&#40;&#41;


appsDir = System.currentDirectory&#40;&#41;
System.currentDirectory&#40;"ms0&#58;/PSP/Game/CRWindowsPSP"&#41;
strtwndw = 1
idletm=0
end
how would i wright that?
Noko
Posts: 23
Joined: Sat Sep 06, 2008 8:35 pm

Post by Noko »

> old school lib code

...what?
flyboy2012
Posts: 11
Joined: Tue Oct 07, 2008 8:50 am

Post by flyboy2012 »

the code you use in the main.c
like

Code: Select all

oslDrawImage&#40;background&#41;;
osl stands for old school library
Onii
Posts: 40
Joined: Sun Oct 05, 2008 1:07 pm

Post by Onii »

My guess is you're looking for a c tutorial. Search for one on google.
flyboy2012
Posts: 11
Joined: Tue Oct 07, 2008 8:50 am

Post by flyboy2012 »

tryed that
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
Dariusc123456
Posts: 388
Joined: Tue Aug 12, 2008 12:46 am

Post by Dariusc123456 »

I think he asking for a lua to C convertion to use OSLibs .
flyboy2012
Posts: 11
Joined: Tue Oct 07, 2008 8:50 am

Re: selecting images

Post by flyboy2012 »

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?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Re: selecting images

Post by J.F. »

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.
flyboy2012
Posts: 11
Joined: Tue Oct 07, 2008 8:50 am

Post by flyboy2012 »

a friend sent me this and yes this is what i was asking for

Code: Select all

#include <oslib/oslib.h>

PSP_MODULE_INFO&#40;"Desktop", 0, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;
PSP_HEAP_SIZE_KB&#40;20*1024&#41;;

int initOSLib&#40;&#41;
&#123;
    oslInit&#40;0&#41;;
    oslInitGfx&#40;OSL_PF_8888, 1&#41;;
    oslSetQuitOnLoadFailure&#40;1&#41;;
    oslSetKeyAutorepeatInit&#40;40&#41;;
    oslSetKeyAutorepeatInterval&#40;10&#41;;
    return 0;
&#125;

int endOSLib&#40;&#41;
&#123;
    oslEndGfx&#40;&#41;;
    osl_quit = 1;
	sceKernelExitGame&#40;&#41;;
    return 0;
&#125;

int collision&#40;int x0, int y0, int x1, int y1, int w0, int h0, int w1, int h1&#41;
&#123;
	int hit = 0;
	
	if&#40;x0+w0 > x1 && x0 < x1+w1 && y0+h0 > y1 && y0 < y1+h1&#41;hit = 1;
	
	return hit;
&#125;

int main&#40;&#41;
&#123;
	initOSLib&#40;&#41;;//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&#40;"background.png", OSL_IN_RAM|OSL_SWIZZLED, OSL_PF_8888&#41;;
	OSL_IMAGE* cursor = oslLoadImageFilePNG&#40;"cursor.png", OSL_IN_RAM|OSL_SWIZZLED, OSL_PF_8888&#41;;
	
	while&#40;!osl_quit&#41;//Main loop
	&#123;
		oslStartDrawing&#40;&#41;;//Start drawing
		oslReadKeys&#40;&#41;;//Read the PSP's keys
		
		oslDrawImage&#40;BG&#41;;//Draw the background
		
		oslDrawFillRect&#40;item1X, item1Y, item1X+10, item1Y+10, RGB&#40;255, 0, 0&#41;&#41;;//Draw item 1
		oslDrawFillRect&#40;item2X, item2Y, item2X+10, item2Y+10, RGB&#40;0, 255, 0&#41;&#41;;//Draw item 2
		oslDrawFillRect&#40;item3X, item3Y, item3X+10, item3Y+10, RGB&#40;0, 0, 255&#41;&#41;;//Draw item 3
		
		oslDrawImageXY&#40;cursor, cursorX, cursorY&#41;;//Draw the cursor
		
		if&#40;osl_keys->held.cross&#41;//If cross is pressed
		&#123;
			if&#40;collision&#40;cursorX, cursorY, item1X, item1Y, 10, 10, 10, 10&#41; && !&#40;collision&#40;cursorX, cursorY, item2X, item2Y, 10, 10, 10, 10&#41;&#41; && !&#40;collision&#40;cursorX, cursorY, item3X, item3Y, 10, 10, 10, 10&#41;&#41;&#41;//If the cursor is on the first item and not on the other two
			&#123;
				//Set the items X & Y to the cursors
				item1X = cursorX;
				item1Y = cursorY;
			&#125;
			if&#40;collision&#40;cursorX, cursorY, item2X, item2Y, 10, 10, 10, 10&#41; && !&#40;collision&#40;cursorX, cursorY, item1X, item1Y, 10, 10, 10, 10&#41;&#41; && !&#40;collision&#40;cursorX, cursorY, item3X, item3Y, 10, 10, 10, 10&#41;&#41;&#41;//If the cursor is on the second item and not on the other two
			&#123;
				//Set the items X & Y to the cursors
				item2X = cursorX;
				item2Y = cursorY;
			&#125;
			if&#40;collision&#40;cursorX, cursorY, item3X, item3Y, 10, 10, 10, 10&#41; && !&#40;collision&#40;cursorX, cursorY, item1X, item1Y, 10, 10, 10, 10&#41;&#41; && !&#40;collision&#40;cursorX, cursorY, item2X, item2Y, 10, 10, 10, 10&#41;&#41;&#41;//If the cursor is on the third item and not on the other two
			&#123;
				//Set the items X & Y to the cursor's
				item3X = cursorX;
				item3Y = cursorY;
			&#125;
		&#125;
		
		//Controls for the cursor
		if&#40;osl_keys->held.left&#41;cursorX -= 2;
		if&#40;osl_keys->held.right&#41;cursorX += 2;
		if&#40;osl_keys->held.up&#41;cursorY -= 2;
		if&#40;osl_keys->held.down&#41;cursorY += 2;
		
		//Exit if start is pressed
		if&#40;osl_keys->pressed.start&#41;endOSLib&#40;&#41;;
		
		//End drawing, frame .etc...
		oslEndDrawing&#40;&#41;;
		oslEndFrame&#40;&#41;;
    	oslSyncFrame&#40;&#41;;
	&#125;//End of main loop
	return 1;
&#125;

PosX100
Posts: 98
Joined: Wed Aug 15, 2007 1:02 am

Post by PosX100 »

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: Select all

void initOSLib&#40;&#41;
&#123;
    oslInit&#40;0&#41;;
    oslInitGfx&#40;OSL_PF_8888, 1&#41;;
    oslSetQuitOnLoadFailure&#40;1&#41;;
    oslSetKeyAutorepeatInit&#40;40&#41;;
    oslSetKeyAutorepeatInterval&#40;10&#41;;
&#125;

void endOSLib&#40;&#41;
&#123;
    oslEndGfx&#40;&#41;;
    osl_quit = 1;
    sceKernelExitGame&#40;&#41;;
&#125; 
Dirty "collision detection" function which makes no sense with the variable names,
you can do this:

Code: Select all

static bool collide&#40; const TVector2* v1, const TVector2* v2&#41;
&#123;
	return &#40; &#40; v1->x + v1->w > v2->x &#41; && &#40; v1->x <  v2->x +v2->w &#41; 
	       &&&#40; v1->y + v1->h > v2->y &#41; && &#40; v1->y <  v2->y +v2->h &#41;&#41;;
&#125;
Main loop is really messy , so ... here's a quick example of the right way doing it:

Code: Select all

int main &#40; ... &#41;
&#123;
	initOSLib&#40;&#41;;
	
	while &#40; application->isRunning&#40;&#41; &#41;
	&#123;
		clear
		    begin drawing
			switch &#40; application->getStateStack&#40;&#41;.top&#40;&#41; &#41;
			&#123;
				case GAMEPLAY&#58;
				&#123;
					
					draw something
					break;
				&#125;
			&#125;
			end drawing
			handle input ,  timers & "physics"
		present
	&#125;
	
	endOSLib&#40;&#41;;
&#125;

To sum everything up : learn the basics , then make games ...
(also , feel free to kill your friend :-P )
flyboy2012
Posts: 11
Joined: Tue Oct 07, 2008 8:50 am

Post by flyboy2012 »

i posted in the wrong spot please excuse my mistake
Post Reply