xxxxxxxxxx
class Pacman {
constructor(x, y) {
this.x = x;
this.y = y;
this.v = createVector(0,0,0);
}
draw(var_cyclique) {
var u = createVector(mouseX - this.x, mouseY - this.y).div(1000);
line(this.x, this.y, this.x + this.v.x, this.y + this.v.y)
line(this.x + this.v.x, this.y + this.v.y, this.x + this.v.x + u.x, this.y + this.v.y + u.y)
this.v.mult(0.99);
this.v.add(u);
this.x += this.v.x;
this.y += this.v.y;
var vecteur = createVector(mouseX - this.x, mouseY - this.y); //Le vecteur du curseur jusqu'à pacman
var angle = createVector(1,0).angleBetween(vecteur);
fill("#FEFE33");
if(mouseY < this.y) {
arc(this.x, this.y, 20, 20, -angle+QUARTER_PI*var_cyclique, -angle-QUARTER_PI*var_cyclique);
} else {
arc(this.x, this.y, 20, 20, angle+QUARTER_PI*var_cyclique, angle-QUARTER_PI*var_cyclique);
}
}
}
var pacs;
var tempsPacman = 2;
var t = 0;
var chrono = 0;
var var_cyclique;
function setup() {
createCanvas(windowWidth, windowHeight);
noStroke();
frameRate(60);
pacs = [new Pacman(random(0, windowWidth), random(50, windowHeight))];
}
function draw() {
background(100);
t += 1/3;
var var_cyclique = sin(t) /2 + 0.5; //Variation cyclique entre 0 et 1 en 3 rafraichissements
for (i in pacs) {
pacs[i].draw(var_cyclique);
}
}