Estive a fazer umas pesquisas e ja consegui evoluir um pouco, no entanto, o objeto que é para apanhar, está a dar pontuação quando passo por cima dele com o cursor, e não quando passa o objeto. Agora é só mesmo essa a dúvida, como dar pontuação quando o elemento que segue o rato passar por cima do outro elemento, em vez de ser o cursor em si.
Aqui vai o meu código:
int x, y;
int startTime;
boolean gotIt = false;
float showTime = 3000;
int bgColor = 150;
int score = 0;
Mover mover;
// Set up the screen, and choose
// first random location for the ball
void setup() {
size(600, 600);
startTime = millis();
fill(255, 0, 0);
newRandomLocation();
mover = new Mover();
}
// Draw the ball, or choose a new
// location for the ball
void draw() {
background(#464646);
fill(#FFFFFF);
ellipse(100,100,5,5);
ellipse(200,200,6,6);
ellipse(300,70,3,3);
ellipse(240,90,2,2);
ellipse(450,170,6,6);
ellipse(550,300,1,1);
ellipse(300,70,3,3);
ellipse(150,300,1,1);
ellipse(550,100,1,1);
ellipse(450,400,1,1);
ellipse(400,300,1,1);
ellipse(430,200,1,1);
ellipse(100,220,1,1);
ellipse(30,240,1,1);
ellipse(500,200,3,3);
ellipse(430,100,3,3);
ellipse(350,250,1,1);
ellipse(320,200,1,1);
fill(#AEAFAD);
triangle(50,600,100,400,200,600);
triangle(0,600,50,500,100,600);
triangle(100,600,150,450,250,600);
triangle(150,600,200,500,350,600);
triangle(200,600,250,430,400,600);
fill(#88D853);
rect(0,580,30,30);
if (bgColor == 255)
bgColor = 150;
showScore();
if (!gotIt && millis() - startTime < showTime) {
fill(255, 0, 0);
ellipse(x, y, 30, 30);
}
else {
newRandomLocation();
}
}
// Select a new randomLocation for the ball
void newRandomLocation() {
x = (int)random(0, width);
y = (int)random(0, height);
gotIt = false;
startTime = millis();
}
// If the user clicks inside the ball, give
// them a point
void mouseMoved() {
if (dist(mouseX, mouseY, x, y) < 50) {
score += 10;
gotIt = true;
showTime = 0.9 * showTime;
}
else
bgColor = 255;
}
// Display the score in the bottom-left corner
void showScore() {
fill(0);
text(score, 3, height - 3);
// Update the location
mover.update();
// Display the Mover
mover.display();
}
outra aba:
class Mover {
// The Mover tracks location, velocity, and acceleration
PVector location;
PVector velocity;
PVector acceleration;
// The Mover's maximum speed
float topspeed;
Mover() {
// Start in the center
location = new PVector(width/2,height/2);
velocity = new PVector(0,0);
topspeed = 5;
}
void update() {
// Compute a vector that points from location to mouse
PVector mouse = new PVector(mouseX,mouseY);
PVector acceleration = PVector.sub(mouse,location);
// Set magnitude of acceleration
acceleration.setMag(0.2);
// Velocity changes according to acceleration
velocity.add(acceleration);
// Limit the velocity by topspeed
velocity.limit(topspeed);
// Location changes by velocity
location.add(velocity);
}
void display() {
stroke(255);
strokeWeight(2);
fill(127);
ellipse(location.x,location.y,48,48);
fill(#81C158);
ellipse(location.x,location.y,40,40);
}
}
↧