![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
This is a discussion on Needs help for a game : BUG within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; hi again i am trying to learn how to code with functions and i mad a game called bug ive ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
![]() |
hi again i am trying to learn how to code with functions and i mad a game called bug ive added a bug in the bottom that moves and a hand that can hit the bug but i have problems using my collision detction code and i dont now why it doesnt work here is the code i does compile but dont work :Code:
int Collision() {
int y1 = yhand + 116;
int y2 = ybug;
int x1 = xhand;
int x2 = xbug;
int x22 = xbug + 101;
if (y1 == y2) {
if (x1 > x2) {
if (x1 < x22) {
sprintf(buffer, "blood.png");
bug = loadImage(buffer);
sprintf(buffer, "blood.png");
bug2 = loadImage(buffer);
poked = 1;
}
}
}
}
.-= Double Post =- come on please someone heeelp me ![]() -= Double Post =- i need to go to bed now see ya hope someone will answer my post. Last edited by PSP-Maniac; 09-27-2006 at 01:08 PM.. Reason: Automerged Doublepost |
|
|
|
|
|
#3 | |
![]() ![]() Your Fate is Grim...
|
Quote:
are you trying to blit blood?? then you cant use that. and dont put sprintf in a loop, itll hog your memory. check out yeldarbs tutorails.
__________________
-------------------------------------------------------------------------------------- ![]() |
|
|
|
|
|
|
#4 |
![]() ![]() ...in a dream...
|
Grimfate, with proper freeing of memory he can to use sprintf. Its pointless in this case, but still...
Vaza - sprintf is fine. His problem is he isnt blitting anything. Sure, he's loading the image, but not blitting it. Code:
... globally do this so the collision function will be able to use it ....
Image *blood = loadImage("blood.png");
void Collision() {
int y1 = yhand + 116;
int y2 = ybug;
int x1 = xhand;
int x2 = xbug;
int x22 = xbug + 101;
if (y1 == y2) {
if (x1 > x2) {
if (x1 < x22) {
poked = 1;
} else { poked = 0; }
}
}
}
... in main loop ...
if ( poked ) {
blitAlphaImageToScreen(0,0, Image->sizeX, Image->sizeY, blood, placeX, placeY);
}
Youll most likely have to re-work things as I see a few calculation errors... :\
__________________
...you'll never know what it's like... spending your whole life in a dream...
Launch a Kitten out of a Cannon and win real cash! Checkout my newly updated site for all my projects (Kitten Cannon, BOXHEAD, Light Cycle 3D) |
|
|
|
|
|
#5 |
|
After a collision...
You'll also have to use flipScreen(); at the end else it'll not work even if the image has been blit. Blit screen returns a int pointer that the flipScreen searches for. Any flip pointer found , flipScreen flips that pointer. So add flipScreen(); See the header file for reference. |
|
|
|
|
|
|
#6 |
![]() ![]() ...in a dream...
|
He said he has gotten the fly and background to display, signifying he knows about the double-buffering used by the graphics library........
__________________
...you'll never know what it's like... spending your whole life in a dream...
Launch a Kitten out of a Cannon and win real cash! Checkout my newly updated site for all my projects (Kitten Cannon, BOXHEAD, Light Cycle 3D) |
|
|
|
|
|
#7 |
![]() |
it isnt the image code that is wrong !!
my god ive readden alot of c tuts so i now what im doing the blitting of the image is in another part of the program and i use sprintf the print into an buffer. i only need help whith the collision detection so SG57 tell me the calculation errors please!? -= Double Post =- btw ive also made a poke the pengiun game see the sig for download. Last edited by PSP-Maniac; 09-28-2006 at 07:13 AM.. Reason: Automerged Doublepost |
|
|
|
|
|
#8 |
![]() ![]() AKA Homer
|
Here's a collision function I made, in case you want it
![]() Code:
int Collide(int fx, int fy, int fw, int fh, int sx, int sy, int sw, int sh)
{
int w, h, w2, h2;
for(w = 0;w<fw;w++)
{
for(h = 0;h<fh;h++)
{
for(w2 = 0;w2<sw;w2++)
{
for(h2 = 0;h2<sh;h2++)
{
if(((fx+w == sx+w2) && (fy+h == sy+h2)))
{
return 1;
}
}
}
}
}
return 0;
}
Code:
if(Collide(x value of first object, y value of first object, width of first object, height of first object, x value of second object, y value of second object, width of second object, height of second object))
{
Do something if there's collision
}
|
|
|
|
|
|
#11 | |
![]() |
Quote:
to homer : never mind ive worked it out hehe me = stupid |
|
|
|
|
|
|
#12 | |
![]() ![]() AKA Homer
|
Quote:
|
|
|
|
|
|
|
#14 | |
![]() |
Quote:
|
|
|
|
|
![]() |
| Tags |
| bug , game |
| Thread Tools | |
|
|