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 › object declarations
Page Index Toggle Pages: 1
object declarations (Read 466 times)
object declarations
Dec 23rd, 2009, 9:24am
 
Hello,

I had another post about a video game I started to write for a school project, and i just had one more question that I was unsure of how to implement. I want to make my game somewhat similar to that of and old Super Mario game or something along the lines of that. So basically, I want it to have some platforms floating in the air, more or less; so the character can jump and land onto this platform. But how do I make it so that the character lands on the platform instead of just falling through it, like it's just part of the background?

Thanks for any help!
Re: object declarations
Reply #1 - Dec 23rd, 2009, 9:37am
 
You check to see if the character collides with the platform.  Do a search on collision detection - this kind of question gets asked often enough (e.g. here) and in fact the answer may help with your other question...
Re: object declarations
Reply #2 - Dec 23rd, 2009, 9:57am
 
Ohh, that would make sense about having the character 'collide' with the item that it's picking up or landing on. So I would just have to check that the character in question is 'on' the rectangle if it's a platform, or if it's within the bounds if it's a picture that I loaded in?
The part that I'm really not too sure about is checking to see if the character is within bounds of the object (when it's collecting an item). I tried using:

 void gather(){
   if (collect == false){
     if (dist (x, y, Sx, Sy) < Swidth){   // x and y are the character's coords, while Sx, Sy are
       collect = true;                           // xpos and ypos of the item
       loselife = false;
       incscore = true;
       score += 30;
     }

I thought that would make the character pick up the item and show an increase in score. But the exact problem I'm having is that it -does- pick up the item and increase the score, but only when the item is out of the screen's bound (i.e. the item is too far down on the y-axis).

Do you know what else can be used, or what the error is in my code so far?
Page Index Toggle Pages: 1