Collision/ keyPressed
in
Programming Questions
•
1 year ago
Hey all,
I've embarked on a new task today and im having some difficulty trying to implement the code for it.. Im trying to do 2 things.
#1 - when a key is pressed (lets say 'g') i want an just one ellipse to be drawn randomly in the window (with a fixed diameter).
#2 - I have already created the code when the mouse is pressed an ellipse will roll across the screen.. now if the rolling ellipse comes in contact with the first ellipse i want only the rolling ellipse to disappear.. and when the mouse is pressed again the rolling ellipse to reappear at its starting location and begin rolling again.
Heres what i have so far:
int x, y, z;
boolean motion = false;
boolean collideCircle = false;
void setup() {
background(255);
size(600, 600);
smooth();
}
void draw() {
if (motion==true) {
background(255);
noStroke();
fill(255, 0, 0);
ellipse (x, height/2, 50, 50);
x++;
}
if (collideCircle==true) {
fill(0);
ellipse (z, y, 50, 50);
}
}
void mousePressed() {
motion = true;
x = 0;
}
void keyPressed()
{
collideCircle = true;
y = (int)random(0, height);
z = (int)random(0, width);
}
Thank you for your time :) [Edit - Updated code]
1