 |
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 23, 2008 12:18 pm Post subject: Collisions (i think) |
|
|
I am trying to launch a .PBP when i have my image (sprite) over my other image (item1). The program should start when i press cross as long as my sprite is the the boundaries (x50 y50) also the same size of my image (item1)but when i press cross nothing happens so...
How have i set my main.c file up wrong or what do i need to add?
| Code: |
#include <oslib/oslib.h>
#include <psploadexec_kernel.h>
#include <psploadexec_kernel.h>
#include <systemctrl.h>
#include <stdio.h>
#include <stdlib.h>
PSP_MODULE_INFO("PSPWindows", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
void RunPBP(char* file){
struct SceKernelLoadExecVSHParam param;
char argp[256];
int args;
strcpy(argp, file);
args = strlen(file)+1;
memset(¶m, 0, sizeof(param));
param.size = sizeof(param);
param.args = args;
param.argp = argp;
param.key = NULL;
param.vshmain_args_size = 0;
param.vshmain_args = NULL;
sctrlKernelLoadExecVSHMs2(file,¶m);
}
//declaration of the pointers of our images
OSL_IMAGE *background, *sprite, *taskbar, *startmenu, *item1;
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;
}
//Main
int main(){
//Set item starting positions
int item1X = 0;
int item1Y = 0;
int item2X = 50;
int item2Y = 70;
int item3X = 50;
int item3Y = 90;
//Set sprites starting position
int spriteX;
int spriteY;
//Initialization of the Oslib library
oslInit(0);
//Initialization of the graphics mode
oslInitGfx(OSL_PF_8888, 1);
//loads our images into memory
background = oslLoadImageFile("background.png", OSL_IN_RAM, OSL_PF_5551);
taskbar = oslLoadImageFile("taskbar.png", OSL_IN_RAM, OSL_PF_5551);
startmenu = oslLoadImageFile("startmenu.png", OSL_IN_RAM, OSL_PF_5551);
sprite = oslLoadImageFile("sprite.png", OSL_IN_RAM, OSL_PF_5551);
item1 = oslLoadImageFile("internet.png", OSL_IN_RAM, OSL_PF_5551);
//Verification that all files are present
if (!background || !sprite)
oslFatalError("It is impossible to load one or more of the images that are required in this program. Please make sure you have all the files required in the eboot folder");
//Main while loop
while (!osl_quit)
{
//To be able to draw on the screen
oslStartDrawing();
//initiate the PSP's buttons
oslReadKeys();
if (osl_keys->pressed.start)
oslDrawImage(startmenu);
//Sprite movement
if (osl_keys->analogX > 50) sprite->x += 2;
if (osl_keys->analogX < -50) sprite->x -= 2;
if (osl_keys->analogY > 50) sprite->y += 2;
if (osl_keys->analogY < -50) sprite->y -= 2;
//Draw the images to the screen
oslDrawImage(background);
oslDrawImage(taskbar);
oslReadKeys();
if (osl_keys->held.start)
oslDrawImage(startmenu);
oslDrawImage(item1);
oslReadKeys();
if(osl_keys->held.cross)//If cross is pressed
{
if(collision(spriteX, spriteY, item1X, item1Y, 50, 50, 50, 50) && !(collision(spriteX, spriteY, item2X, item2Y, 50, 50, 50, 50)) && !(collision(spriteX, spriteY, item3X, item3Y, 50, 50, 50, 50)))//If the sprite is on the first item and not on the other two
{
RunPBP("ms0:/PSP/GAME/GTH/EBOOT.PBP");
}
if(collision(spriteX, spriteY, item2X, item2Y, 50, 50, 50, 50) && !(collision(spriteX, spriteY, item1X, item1Y, 50, 50, 50, 50)) && !(collision(spriteX, spriteY, item3X, item3Y, 50, 50, 50, 50)))//If the sprite is on the second item and not on the other two
{
//Set the items X & Y to the sprites
item2X = spriteX;
item2Y = spriteY;
}
if(collision(spriteX, spriteY, item3X, item3Y, 50, 50, 50, 50) && !(collision(spriteX, spriteY, item1X, item1Y, 50, 50, 50, 50)) && !(collision(spriteX, spriteY, item2X, item2Y, 50, 50, 50, 50)))//If the sprite is on the third item and not on the other two
{
//Set the items X & Y to the sprite's
item3X = spriteX;
item3Y = spriteY;
}
}
oslDrawImage(sprite);
//Ends drawing mode
oslEndDrawing();
//Synchronizes the screen
oslSyncFrame();
}
//Terminate the program
oslEndGfx();
oslQuit();
return 0;
}
|
|
|
| Back to top |
|
 |
Onii
Joined: 05 Oct 2008 Posts: 40
|
Posted: Thu Oct 23, 2008 1:28 pm Post subject: |
|
|
I mean no offense, but after reviewing this code, I think programming the PSP my be a bit out of your league.
That aside:
If you want to find out what your program is doing, you're going to either have to load it in a debugger (read: PSPLink + GDB) or throw some printf()s in there. I don't know the first thing about OSL but I'm pretty sure I saw a post on these forums showing its printf (or the equivalent) call.
If you can't figure out either of those methods I'd suggest starting out on an easier project, or come back to the PSP after you have a game or two on another platform. |
|
| Back to top |
|
 |
PosX100
Joined: 15 Aug 2007 Posts: 98
|
Posted: Thu Oct 23, 2008 9:01 pm Post subject: |
|
|
This is an apple .
This is an orange .
This is Sparta(aaaaaaaaaa).
no , No , NO^2 , ........... this is a (yet another) (poorly written) f. shell.
PS:I'm the only shell-hater ? |
|
| Back to top |
|
 |
hibbyware
Joined: 28 Mar 2007 Posts: 78
|
Posted: Thu Oct 23, 2008 9:23 pm Post subject: |
|
|
| PosX100 wrote: |
PS:I'm the only shell-hater ?
|
I have a love hate relationship with shells,
I hate how all these incomplete shells keep getting released when they should wait for it to mature a bit first,
I love to use my own shell as I don't like the XMB much but it will still stay as a private shell as there are already loads of other shells available,
So what I'm saying is that it seems ok to make your own shell for learning and enjoyment but releasing that shell is another matter, |
|
| Back to top |
|
 |
flyboy2012
Joined: 07 Oct 2008 Posts: 11
|
Posted: Fri Oct 24, 2008 7:57 am Post subject: |
|
|
| i did not plan to release this shell. it is intended for personal use. i am learning to code and this is my first project so it shouldn't surprise you that it is poorly written but i still need help |
|
| Back to top |
|
 |
Onii
Joined: 05 Oct 2008 Posts: 40
|
Posted: Fri Oct 24, 2008 10:57 am Post subject: |
|
|
Then throw in printf()s everywhere you think something interesting may happen. For example:
put a printf("1"); inside the read keys check ,
then printf("2"); inside of the first collision check,
then printf("3"); inside your RunPBP
Then run your program and see what numbers show up. Then at least you'll know where your problem is, and therefore what to read up on, or ask specific questions about. |
|
| Back to top |
|
 |
PosX100
Joined: 15 Aug 2007 Posts: 98
|
Posted: Fri Oct 24, 2008 3:37 pm Post subject: |
|
|
I don't think debugging each function will really help in this case.
Its just insanely bad code design combined with extremely bad code.
First of all , you're calling "readKeys" function 3 times each frame...wtf.
Second, "*->held" method means that "$" button should be...held down,which isn't what you really want.
Third,why on earth you're combining collision detection for each object that you don't actually have
to check?.
Fourth,better re-write collision detection function(see my previous post...in your first(?) thread) , it just looks so bad with all these parameters.
Fifth, | Code: | if (osl_keys->held.start)
oslDrawImage(startmenu); | LOL.
Sixth, | Code: | //Set the items X & Y to the sprite's
item3X = spriteX;
item3Y = spriteY; | LOL^2.
Seventh,
Listen , ..."flyboy2012"...
Download an IDE , and start making a few console (text) games on windows/linux/whatever and
small utilities ,and ......you should be able to "fly" in the year 2012....JUST forget psp for now. |
|
| 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
|