We are about to switch to a new forum software. Until then we have removed the registration on this forum.
tab 1: ArrayList < Car > cars; PFont f; float x1, y1, lives1; boolean x2;
void setup () { size(700, 700); cars = new ArrayList(); for (int count=0; count < 20; count=count+1) { cars.add(new Car()); } f=createFont("Arial", 24, true); x1= width-690; y1=height-10; x2=true; lives1=10; }
void draw () { background(255); fill(#0EFF03); rect(mouseX, mouseY, 30, 50) ; lives() ; for (int count=0; count < 20; count=count+1) { cars.get(count).display(); cars.get(count).move(); } }
void lives() { textFont(f); fill(245, 200, 0); text("lives:" + lives1, x1, y1); }
tab 2: class Car { float x, y; float speed;
Car() { x = random(10, width-10); y = 0; speed = random(1, 5); }
void display () { fill(255, 0, 0); noStroke(); rect(x, y, 30, 50); }
void move() { y = y + speed; if(y > height) { y = 0; x = random(10, width-10); } }
void losinglives1(){ if (dist(x, y, mouseX, mouseY)<15) { lives1=lives1-1; } } }
Answers
help me pls
How can you tell if two grid-aligned rectangles are touching? (Hint: Where are the corners?)
Then you should write a function that determines if two rectangles are touching. Such a function should take, as parameters, the positions and size of both rectangles, and return either true (if they touch) or false (if they do not).
Can you write a sketch that demonstrates your collision detecting function works?
Now use that function in your original sketch. Remember: You only want to lose a life if there are rectangles colliding NOW, and they weren't colliding BEFORE. You might need an additional variable to record if they were colliding in the previous frame...
can you just write it for me please?
jeffreythompson.org/collision-detection/rect-rect.php
Sure! Shoot me an email (tfguy44 at gmail dot com) and we can discuss it. My rates are very reasonable!