jkim1684
YaBB Newbies
Offline
Posts: 8
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); } }