QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

Needs help for a game : BUG

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 ...

Reply
 
LinkBack Thread Tools
Old 09-27-2006, 01:08 PM   #1
 
PSP-Maniac's Avatar
 
Join Date: May 2006
Posts: 457
Trader Feedback: 0
Default Needs help for a game : BUG

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;
                               }
                               }
                               }
}
so please help me .
-= 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
PSP-Maniac is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-27-2006, 01:13 PM   #2

Save The World
 

 
Join Date: Oct 2005
Location: Bedford, England
Posts: 1,389
Trader Feedback: 0
Default

I don't know much C but isnt it supposed to be printf instead of sprintf?
--Vaza
__________________
Vaza is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-27-2006, 04:13 PM   #3

Your Fate is Grim...
 
Grimfate126's Avatar
 
Join Date: Oct 2005
Posts: 2,269
Trader Feedback: 0
Default

Quote:
Originally Posted by PSP-Maniac
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;
                               }
                               }
                               }
}
so please help me .
-= 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.

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.
__________________
--------------------------------------------------------------------------------------
Grimfate126 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-27-2006, 04:31 PM   #4

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

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);
}
That will display the blood image if your colision mech works and you place placeX and placeY with actual numbers.

Youll most likely have to re-work things as I see a few calculation errors... :\
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-27-2006, 10:58 PM   #5
 
gamer.naveen's Avatar
 
Join Date: Sep 2006
Posts: 14
Trader Feedback: 0
Default >>

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.
gamer.naveen is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-27-2006, 11:15 PM   #6

...in a dream...
 
SG57's Avatar
 
Join Date: Jul 2005
Posts: 4,957
Trader Feedback: 0
Default

He said he has gotten the fly and background to display, signifying he knows about the double-buffering used by the graphics library........
__________________
SG57 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-28-2006, 07:13 AM   #7
 
PSP-Maniac's Avatar
 
Join Date: May 2006
Posts: 457
Trader Feedback: 0
Default

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
PSP-Maniac is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-28-2006, 07:35 AM   #8

AKA Homer
 
Moonchild's Avatar
 
Join Date: Jan 2006
Location: Sweden
Posts: 1,779
Trader Feedback: 0
Default

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;
}
You call it like this

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
}
__________________


Click Here if you want a Winamp Currently Playing Userbar like the one above.
Moonchild is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-28-2006, 08:08 AM   #9
 
PSP-Maniac's Avatar
 
Join Date: May 2006
Posts: 457
Trader Feedback: 0
Default

big thanks homer im gonna make the game and release it now
-= Double Post =-
whow that code makes my bug move in super slow motion

Last edited by PSP-Maniac; 09-28-2006 at 08:08 AM.. Reason: Automerged Doublepost
PSP-Maniac is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-28-2006, 08:44 AM   #10
 
canalaiz's Avatar
 
Join Date: Jun 2005
Posts: 71
Trader Feedback: 0
Default

Sorry to argue, but wouldn't it be better to use the pythagora's theorem to find the distance between 2 objects and then if it's lower than a value return collision?
canalaiz is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-28-2006, 08:51 AM   #11
 
PSP-Maniac's Avatar
 
Join Date: May 2006
Posts: 457
Trader Feedback: 0
Default

Quote:
Originally Posted by canalaiz
Sorry to argue, but wouldn't it be better to use the pythagora's theorem to find the distance between 2 objects and then if it's lower than a value return collision?
wtf !?

to homer : never mind ive worked it out hehe
me = stupid
PSP-Maniac is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-28-2006, 09:01 AM   #12

AKA Homer
 
Moonchild's Avatar
 
Join Date: Jan 2006
Location: Sweden
Posts: 1,779
Trader Feedback: 0
Default

Quote:
Originally Posted by canalaiz
Sorry to argue, but wouldn't it be better to use the pythagora's theorem to find the distance between 2 objects and then if it's lower than a value return collision?
There are probably lots of ways faster than my function.. But I haven't bothered to make another one, atleast it works pretty good
__________________


Click Here if you want a Winamp Currently Playing Userbar like the one above.
Moonchild is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-28-2006, 09:07 AM   #13
 
PSP-Maniac's Avatar
 
Join Date: May 2006
Posts: 457
Trader Feedback: 0
Default

you bet it does. look my release thread.
PSP-Maniac is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-28-2006, 02:15 PM   #14
 
Twin891's Avatar
 
Join Date: Jul 2006
Location: Canada
Posts: 70
Trader Feedback: 0
Default

Quote:
Originally Posted by canalaiz
Sorry to argue, but wouldn't it be better to use the pythagora's theorem to find the distance between 2 objects and then if it's lower than a value return collision?
This only works with circles. If you have a square, you can probably use it to do more efficient calculations tho.
Twin891 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
bug , game

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 09:29 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us