the movement is based on the stick angle (aStickA), 0° = Right
now, you can add accleration in function of circle ray (aStickR)
Code: Select all
int getSqrRadius(int X, int Y) {
return sqrt((X * X) + (Y * Y));
}
SDL_ShowCursor(0);
SDL_WarpMouse(SCR_WIDTH / 2, SCR_HEIGHT / 2);
SDL_Surface* Mouse = SDL_LoadBMP("ms0:/PSP/GAME150/test/cursor.bmp");
SDL_SetColorKey(Mouse, SDL_SRCCOLORKEY, SDL_MapRGB(Mouse->format,255,255,255));
SDL_Rect coords;
SceCtrlData pad;
int aStickX = 0;
int aStickY = 0;
float aStickR;
float aStickA;
int x,y;
float Precision = 360.0f;
while (1) {
//Deplacement de la souri
SDL_GetMouseState(&x, &y);
sceCtrlReadBufferPositive(&pad, 1);
aStickX = pad.Ly - 128;
aStickY = pad.Lx - 128;
aStickR = getSqrRadius(aStickX, aStickY);
if (aStickR > 100) {
if (getSqrRadius(aStickX, aStickY) > 30) {
aStickA = ((atan2f(aStickX, -aStickY) + M_PI) / (M_PI * 2)) * Precision;
} else {
aStickA = -1;
}
//1° a 89°
if (aStickA >= 1 && aStickA <= (89 * (Precision / 360.0f))) {
x += (10 * (1 - (aStickA / (Precision / 360.0f) / 90)));
y -= (10 * (0 + (aStickA / (Precision / 360.0f) / 90)));
}
else if (aStickA >= (91 * (Precision / 360.0f)) && aStickA <= (179 * (Precision / 360.0f))) {
x -= (10 * (0 + (((aStickA / (Precision / 360.0f)) - 89) / 90)));
y -= (10 * (1 - (((aStickA / (Precision / 360.0f)) - 89) / 90)));
}
else if (aStickA >= (181 * (Precision / 360.0f)) && aStickA <= (269 * (Precision / 360.0f))) {
x -= (10 * (1 - (((aStickA / (Precision / 360.0f)) - 179) / 90)));
y += (10 * (0 + (((aStickA / (Precision / 360.0f)) - 179) / 90)));
}
else if (aStickA >= (271 * (Precision / 360.0f)) && aStickA <= (359 * (Precision / 360.0f))) {
x += (10 * (0 + (((aStickA / (Precision / 360.0f)) - 269) / 90)));
y += (10 * (1 - (((aStickA / (Precision / 360.0f)) - 269) / 90)));
}
else if (aStickA == 0) {
x += 10;
}
else if (aStickA == (90 * (Precision / 360.0f))) {
y -= 10;
}
else if (aStickA == (180 * (Precision / 360.0f))) {
x -= 10;
}
else if (aStickR == (270 * (Precision / 360.0f))) {
y += 10;
}
}
SDL_WarpMouse(x, y);
coords.x = x;
coords.y = y;
SDL_BlitSurface(Mouse, NULL, Screen, &coords);
SDL_Flip(Screen);
sceKernelDelayThread(20000);
}