You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
193 lines
4.8 KiB
193 lines
4.8 KiB
PImage backgroundImage;
|
|
Equipe[] equipes;
|
|
int nombreEquipes = 50;
|
|
|
|
void setup() {
|
|
|
|
size(displayWidth, displayHeight);
|
|
fullScreen(1);
|
|
randomSeed(3);
|
|
frameRate(30);
|
|
colorMode(HSB, 255);
|
|
rectMode(CENTER);
|
|
noStroke();
|
|
|
|
backgroundImage = loadImage("backgroundImage.jpg");
|
|
image(backgroundImage, 0, 0, displayWidth, displayHeight);
|
|
|
|
equipes = new Equipe[nombreEquipes];
|
|
for (int i = 0 ; i < equipes.length; i++) {
|
|
equipes[i] = new Equipe(i);
|
|
}
|
|
}
|
|
|
|
class Equipe {
|
|
int id, score, pos_x, pos_y, radius;
|
|
String membres;
|
|
color couleur;
|
|
Pion pion;
|
|
|
|
Equipe(int id) {
|
|
this.id = id;
|
|
this.score = 0;
|
|
//float randomHue = random(255);
|
|
//float randomSaturation = random(100,255);
|
|
//float randomBrightness = random(80,255);
|
|
//color inverseText = color(float(255)-randomHue, float(255)-randomSaturation, float(255)-randomBrightness);
|
|
//this.couleur = color(randomHue, randomSaturation, randomBrightness);
|
|
//this.pion = new Pion(this.id, this.couleur, inverseText);
|
|
|
|
// générer un pion pour l'équipe
|
|
this.pion = new Pion(this.id, color(0), color(255));
|
|
|
|
// récupérer les valeurs de positionnement initial du pion
|
|
this.pos_x = this.pion.pos_x;
|
|
this.pos_y = this.pion.pos_y;
|
|
this.radius = this.pion.radius;
|
|
|
|
// afficher l'emplacement de l'équipe avant le pion
|
|
this.update();
|
|
}
|
|
|
|
void update() {
|
|
color bgColor = color(100, 100, 200);
|
|
color textColor = color(200, 100, 200);
|
|
fill(bgColor);
|
|
float radius = this.radius;
|
|
circle(this.pos_x,this.pos_y,radius);
|
|
fill(textColor);
|
|
float textSize = this.radius/4*3;
|
|
textSize(textSize);
|
|
float pos_x = this.id<9? this.pos_x-radius/5: this.pos_x-radius/3;
|
|
text(this.id+1, pos_x, this.pos_y+radius/5);
|
|
|
|
this.pion.update();
|
|
}
|
|
}
|
|
|
|
class Pion {
|
|
int id, pos_x, pos_y, radius;
|
|
color fond, texte;
|
|
boolean hovered, dragged;
|
|
|
|
Pion(int id, color fond, color texte) {
|
|
this.id = id;
|
|
this.fond = fond;
|
|
this.texte = texte;
|
|
this.radius = 30;
|
|
this.pos_x = floor(displayWidth/nombreEquipes)*id+radius;
|
|
this.pos_y = 30;
|
|
this.hovered = false;
|
|
this.dragged = false;
|
|
}
|
|
|
|
void update() {
|
|
color bgColor = this.dragged? color(40, 250, 250): this.hovered? this.texte: this.fond;
|
|
color textColor = this.dragged? color(210, 10, 10): this.hovered? this.fond: this.texte;
|
|
|
|
stroke(bgColor);
|
|
strokeWeight(0.5);
|
|
fill(bgColor);
|
|
float radius = this.radius; //this.dragged? this.radius*1.4: this.hovered? this.radius*1.2: this.radius;
|
|
circle(this.pos_x,this.pos_y,radius);
|
|
|
|
fill(textColor);
|
|
float textSize = this.radius/4*3; //this.dragged? this.radius*0.75: this.hovered? this.radius*0.75: this.radius*0.75;
|
|
textSize(textSize);
|
|
|
|
float pos_x = this.id<9? this.pos_x-radius/5: this.pos_x-radius/3;
|
|
text(this.id+1, pos_x, this.pos_y+radius/5);
|
|
}
|
|
|
|
void dragStart() {
|
|
this.dragged = true;
|
|
}
|
|
|
|
void dragStop() {
|
|
this.dragged = false;
|
|
}
|
|
|
|
void hoverStart() {
|
|
this.hovered = true;
|
|
}
|
|
|
|
void hoverStop() {
|
|
this.hovered = false;
|
|
}
|
|
}
|
|
|
|
void mouseDragged() {
|
|
for (int i = 0 ; i < equipes.length; i++) {
|
|
Pion p = equipes[i].pion;
|
|
if (p.dragged) {
|
|
p.pos_x = mouseX;
|
|
p.pos_y = mouseY;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void mouseMoved() {
|
|
for (int i = 0 ; i < equipes.length; i++) {
|
|
Equipe e = equipes[i];
|
|
Pion p = e.pion;
|
|
|
|
float distPion = dist(p.pos_x, p.pos_y, mouseX, mouseY);
|
|
float distEquipe = dist(e.pos_x, e.pos_y, mouseX, mouseY);
|
|
float threshold = p.radius/2;
|
|
|
|
if (distPion>threshold && distEquipe>threshold && (p.hovered || p.dragged)) {
|
|
p.dragStop();
|
|
p.hoverStop();
|
|
} else if (distPion<=threshold && !p.hovered) {
|
|
println(p.id+1);
|
|
p.hoverStart();
|
|
} else if (distEquipe<=threshold && !p.dragged) {
|
|
println(p.id+1);
|
|
p.dragStart();
|
|
}
|
|
|
|
//if (distPion<p.radius/2 && !p.hovered) {
|
|
// println(p.id+1);
|
|
// p.hoverStart();
|
|
//} else if(distPion>=p.radius/2 && p.hovered) {
|
|
// p.hoverStop();
|
|
//} else if(distEquipe<e.radius/2 && !p.hovered) {
|
|
// println(p.id+1);
|
|
// p.dragStart();
|
|
//} else if(distEquipe>=e.radius/2 && p.hovered) {
|
|
// p.dragStop();
|
|
//}
|
|
}
|
|
}
|
|
|
|
void mousePressed() {
|
|
//println(mouseX, mouseY);
|
|
for (int i = 0 ; i < equipes.length; i++) {
|
|
Pion p = equipes[i].pion;
|
|
float d = dist(p.pos_x, p.pos_y, mouseX, mouseY);
|
|
if (d<p.radius/2) {
|
|
println(p.id+1);
|
|
p.dragStart();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void mouseReleased() {
|
|
for (int i = 0 ; i < equipes.length; i++) {
|
|
Pion p = equipes[i].pion;
|
|
if (p.dragged) {
|
|
p.dragStop();
|
|
}
|
|
}
|
|
}
|
|
|
|
void draw()
|
|
{
|
|
image(backgroundImage, 0, 0, displayWidth, displayHeight);
|
|
for (int i = 0 ; i < equipes.length; i++) {
|
|
equipes[i].update();
|
|
}
|
|
}
|