Muito obrigado
Então aqui vai: eu tenho que fazer um "jogo", utilizando um "example" do processing chamado "accelaration with vectors" em que já temos uma ellipse controlada pelo mouse.
Agora a minha dúvida, é como é que eu coloco essa ellipse a "apanhar" outro objeto, ou seja, quando passamos com a ellipse por cima de um objecto, ele desaparece e aparece em outro sitio de modo "random" e assim sucessivamente.
Aqui vai o código já contido no "example":
// A Mover object
Mover mover;
void setup() {
size(600,600);
mover = new Mover();
}
void draw() {
background(0);
// Update the location
mover.update();
// Display the Mover
mover.display();
}
Em 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);
}
}
Espero ter-me explicado bem.
Penso que não é uma coisa muito difícil de fazer, mas como ainda não tenho muita prática, estou-me a ver um bocado à rasca...
↧