We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › calculating collisions
Page Index Toggle Pages: 1
calculating collisions (Read 669 times)
calculating collisions
Dec 24th, 2009, 11:17am
 
So I think I've worked out most of the bugs from my video game but I had one mroe seemingly easy question. I calculate whether or not my character collides with the object using:

if ((p1.x + p1.w) > o1.x && p1.x < (o1.x + o1.w) && (p1.y + p1.h) > o1.y && p1.y < (o1.y + o1.h)){ //collect onigri
     incscore = true;
     score += 10;
}

where p1 is the panda character and o1 is my item to be collected, x and y are coords, and w and h are width and height respectively.

So I was wondering if I use this code from above, will the program take the width and height of the object as it appears on the screen, or will it take the width and height of the picture's size that I imported. I made my item's size 600x400, so does my code use that as width and height?

Thanks for any help guys!
Re: calculating collisions
Reply #1 - Dec 25th, 2009, 2:31am
 
Since o seems to be an object, w and h are what you put in them...

If img is a PImage, img.width and img.height are the size of the loaded image, whatever the size you use for drawing.

BTW, what is onigri? I know Japanese onigiri, but not onigri. Something pandas like?
Re: calculating collisions
Reply #2 - Dec 25th, 2009, 10:06am
 
Thanks, I got it to work using different parameters for the object's size.. my issue ended up being that the score increased while it was in range of the image..which was just too big, so i just scaled down the image size. And the onigri as I put it was just a typo, it is supposed to be onigiri. And it's what you're thinking, like a riceball, not something pandas like =P
Page Index Toggle Pages: 1