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 › Mapping regarding a moving image
Page Index Toggle Pages: 1
Mapping regarding a moving image (Read 148 times)
Mapping regarding a moving image
Mar 8th, 2009, 9:46am
 
Hi I am making a game and I made it rain through arrays, and at the bottom there is a bucket that will catch each raindrop. the bucket is constantly in motion because it is a one button game. The bucket constantly moves right, but when the spacebar is pressed it moves left. I have been mapping to try to catch a raindrop into the bucket, but when mapping it, it reacts before the rain even drops. If someone can help it will be greatly appreciated.

///////////////////////////////////////////////////////
Girl girlie;

Drop[] drops = new Drop[5];


void setup(){
 size (600,400);
 smooth();
 background(255);


 girlie = new Girl(0,200);
 
 for (int i=0; i<drops.length; i++) {
   drops[i] = new Drop();
}}

void draw(){

 girlie.move();
 
  for (int i=0; i<drops.length; i++) {
   drops[i].display();    
 }

}

class Girl{
 float x = 0;
 float y = 200;
 int speed;
 PImage bucket;
 PImage bucket2;
 int direction;
 float x1;
 float y1;

     
 Girl (float x2, float y2){
   x = x2;
   y = y2;
   

   

 }
 void move(){

     if((keyPressed == true) && (key == ' ')) {
     noFill();
         background(255);
         rect(x1+1,y1+208,27,72);
     x1 -= 3;
   }
   else {
     noFill();
     background(255);
     rect( x1+87,y1+208,27,72);
     x1 += 3;
   }
   float distance = 0;
   x = constrain(x, distance-30, width-distance-70);
 }
}

class Drop {
 float xx;
 float yy;
 float ss;
 float x1;
 float y1;
 float sise;
 float dis;

  Drop() {
   xx = random(0, width);
   ss = random(1, 3);
   yy = random(-100, -10);
   
 }
 
 void display() {
  line(xx,yy+20,xx,yy+50);
   yy+= ss;
   
   if (yy > height) {
     xx = random(0, width);
     ss = random(1, 3);
     yy = random(-100, -10);
   }
   
       if((keyPressed == true) && (key == ' ')) {
     noFill();
         rect(x1+1,y1+208,27,72);
     x1 -= 3;
   }
   else {
     noFill();
     rect( x1+87,y1+208,27,72);
     x1 += 3;
   }
   dis = dist(xx,yy,x1,y1);
   sise = map(dis,xx,xx,yy,yy); // (0,400 is where you want it to come in effect, and 5 is the size, and 200 is the max size.

   println ("catch");
 
   float distance = 0;
   x1 = constrain(x1, distance-30, width-distance-70);
 }
   
 }
Re: Mapping regarding a moving image
Reply #1 - Mar 8th, 2009, 10:21am
 
No time to test or analyze, but from your description, perhaps you miss a rain drop height test?
Re: Mapping regarding a moving image
Reply #2 - Mar 8th, 2009, 11:22am
 
I set the raindrop variable to xx so I tried to map it according to the bucket and when the drop hits around that area it should println but it prints right when they begin to fall it automatically responds. it is not responding to the bucket.
Page Index Toggle Pages: 1