The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

## Code Snippets

This is a discussion on Code Snippets within the Developer's Dungeon forums, part of the PSP Development Forum category; I thought I would Start this section out with a little code snippet section so we could just copy psp ...

 Tweet
1. ## Code Snippets

I thought I would Start this section out with a little code snippet section so we could just copy psp functions into our projects. Please do not post here if youdont have any code to give. Heres some code i found useful for making the backround or text coloful :

Code:
#define RGB(r, g, b) ((b << 16) | (g << 8) | r)
#define BLUE RGB(0, 0, 255)
#define RED RGB(255, 0, 0)
#define GREEN RGB(0, 255, 0)
#define BLACK RGB(0, 0, 0)
#define WHITE RGB(255, 255, 255)
#define printf pspDebugScreenPrintf

pspDebugScreenInit();

pspDebugScreenSetBackColor(BLACK);
pspDebugScreenSetTextColor(BLUE);
pspDebugScreenClear();

printf("Type whatever you want here!\n");

2. Well, I'll add in a little snippet of my own here, it's for making the analog controls 'ramped', ie, the values it returns are better tuned to a small analog nub, so give finer control when moved a little, yet still return the maximum when pushed to the edge.

Code:
//analog stick tripped
int multiplyer;
//we need to process the analog value to give a value between -127 and 127
//now we need to make the amount ramp up, to give finer control :)
if(LxF < 0){multiplyer = -1;}else{multiplyer = 1;}
//do stuff

}
This code goes into your handle keys section, where pad is the read buffer. LxF ends up being a float which ranges from -127 to 127, with 0 when the stick is at rest.

I think that any game using the analog stick should include this code (or something like it), because it makes using the analog stick a much more viable alternative to the D-Pad.

3. Well, i might as well post a code snippet that cyberbill helped me with, it generates a pseudo-random number using the current time.

Code:
/* Function with thanks to cyberbill to find a random number between two numbers */
int Random(int min, int max)
{
/* Seed rand() with the clock time to give the appearance of randomness */
srand(sceKernelLibcTime(NULL));
/*NOTE!! Do not use srand() like this if you are going to call the fuction more than once, it will mess it up! Instead call srand() once in the main where it wont be called multiple times, but if you're calling this function just once, dont worry :) */
int Diff = max - min;
return (rand() % Diff)+min;
}

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 11:09 AM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY