There's my problem; it doesn't bounces naturally on the right wall. If you don't understand what I mean, just see for yourself. Please only tell me or show me what the solution is. Don't go wild and create the second bat etc. That's something I want to do myself. :)
(the same bug exists for the down-wall, but with a fix for the right-wall I'm able to implent it for the down-wall too).
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <graphics.h>
#include <stdio.h>
#define BAT_WIDTH 100
#define BALL_WIDTH 32
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
PSP_MODULE_INFO("POPong", 0, 1, 1);
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
Color White = RGB(255, 255, 255);
Color Red = RGB(255, 0, 0);
int batPosX = 190;
int ballPosX = 224;
int ballPosY = 116;
int ballVecX = 2;
int ballVecY = 1;
int loop = 1;
int score = 0;
SceCtrlData pad;
int analog;
char buffer1[100];
char buffer2[100];
char buffer3[100];
int main(void)
{
SetupCallbacks();
initGraphics();
Image* batImage = loadImage("bat.png");
Image* ballImage = loadImage("ball.png");
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
while(1)
{
sceCtrlReadBufferPositive(&pad,1);
if (pad.Buttons & PSP_CTRL_LTRIGGER)
{
batPosX-=5;
}
if (pad.Buttons & PSP_CTRL_RTRIGGER)
{
batPosX+=5;
}
analog = pad.Lx>>4;
analog -= 8;
batPosX += analog/2;
if (batPosX > 480 - BAT_WIDTH)
{
batPosX = 480 - BAT_WIDTH;
}
if (batPosX < 0)
{
batPosX = 0;
}
ballPosX += ballVecX;
ballPosY += ballVecY;
if (ballPosX <= 0)
{
ballPosX =- ballPosX;
ballVecX =+ 1;
}
// -> THIS NEEDS A FIX <-
if (ballPosX >= 472)
{
ballPosX = 944 - ballPosX;
ballVecX =- 1;
}
if (ballPosY <= 0)
{
ballPosY =- ballPosY;
ballVecY =+ 1;
}
if (ballPosY >= 272)
{
if ( (ballPosX >= batPosX) && (ballPosX <= batPosX + BAT_WIDTH - BALL_WIDTH) )
{
ballPosY = 544 - ballPosY;
ballVecY =- 1;
score++;
sprintf(buffer3, "%i", score);
}
else
{
fillScreenRect(0xff0000ff,0,0,480,272);
printTextScreen(15, 15, "GAME OVER", White);
flipScreen();
sceKernelDelayThread(5000000);
sceKernelExitGame();
}
}
sprintf(buffer1, "%i", ballPosX);
sprintf(buffer2, "%i", ballPosY);
fillScreenRect(White, 0, 0, 480, 272);
blitAlphaImageToScreen(0, 0, BAT_WIDTH, 10, batImage, batPosX, 262);
blitAlphaImageToScreen(0, 0, BALL_WIDTH, BALL_WIDTH, ballImage, ballPosX, ballPosY);
printTextScreen(15, 15, buffer1, Red);
printTextScreen(15, 30, buffer2, Red);
printTextScreen(15, 45, buffer3, Red);
sceDisplayWaitVblankStart();
flipScreen();
}
sceKernelSleepThread();
}
Thanks in advance.