xxxxxxxxxx
Person [] ps;
ArrayList<Home> houses;
//info
int count = 200;
int infected;
int wearMask;
int recovered;
int death;
//frames
// 0 main menu
// 1 tutorial
// 2 game
// 3 end
int frame = 0;
button easyBtn;
button medBtn;
button hardBtn;
button startBtn;
button resetBtn;
//0 easy
//1 meduim
//2 hard
int level;
void setup() {
size(720, 480);
easyBtn = new button(width/2 - 150, height/2, "Easy");
medBtn = new button(width/2, height/2, "Meduim");
hardBtn = new button(width/2 + 150, height/2, "Hard");
startBtn = new button(width/2, height/2 + 200, "start");
resetBtn = new button(width/2, height/2 + 200, "try again");
rectMode(CENTER);
houses = new ArrayList<Home>();
}
void gameSetup(int lvl) {
level = lvl;
if (level == 0) count = 100;
if (level == 1) count = 150;
if (level == 2) count = 200;
ps = new Person[count];
for (int i = 0; i < ps.length; i++) {
ps[i] = new Person(random(width), random(height));
if (level == 0) {
if (random(1) < .25)
ps[i].wearMask = true;
ps[i].maxSpd = .8;
} else if (level == 1) {
if (random(1) < .1)
ps[i].wearMask = true;
ps[i].maxSpd = 1.2;
} else if (level == 2) {
if (random(1) < .01)
ps[i].wearMask = true;
ps[i].maxSpd = 1.8;
}
}
ps[0].infected = true;
ps[1].infected = true;
ps[2].infected = true;
}
void draw() {
if (frame == 0) {
background(255);
easyBtn.display();
medBtn.display();
hardBtn.display();
}
if (frame == 1) {
background(255);
textAlign(LEFT, CENTER);
fill(0, 255, 0);
noStroke();
ellipse(100, 150, 10, 10);
fill(0);
text("healthy particle", 120, 150);
fill(255, 0, 0);
noStroke();
ellipse(100, 180, 10, 10);
fill(0);
text("infected particle", 120, 180);
stroke(0);
fill(0, 255, 0);
ellipse(100, 210, 10, 10);
fill(0);
text("wear a mask", 120, 210);
fill(255, 255, 0);
noStroke();
ellipse(100, 240, 10, 10);
fill(0);
text("recovered particle", 120, 240);
fill(120);
noStroke();
ellipse(100, 270, 10, 10);
fill(0);
text("dead particle", 120, 270);
fill(0);
textAlign(LEFT, CENTER);
text("try to isolate particles to decrease \nthe contact between particles", 370, 150);
stroke(0);
noFill();
rect(400, 210, 50, 50);
fill(255, 0, 0);
noStroke();
ellipse(400, 210, 10, 10);
fill(0, 255, 0);
noStroke();
ellipse(400, 260, 10, 10);
startBtn.display();
}
if (frame == 2) {
background(255);
for (int i = 0; i < ps.length; i++) {
ps[i].display();
ps[i].move();
ps[i].update();
}
for (int i = 0; i < ps.length; i++)
for (int j = 0; j < ps.length; j++) {
if (i != j) {
if (ps[i].infected && !ps[j].infected &&
!ps[j].recovered && !ps[j].wearMask &&
dist(ps[i].pos.x, ps[i].pos.y, ps[j].pos.x, ps[j].pos.y) < 10) {
ps[j].infected = true;
}
}
}
for (Home c : houses) {
c.display();
}
infected = 0;
wearMask = 0;
recovered = 0;
death = 0;
for (int i = 0; i < ps.length; i++) {
if (ps[i].dead) death++;
if (ps[i].wearMask) wearMask++;
if (ps[i].recovered) recovered++;
if (ps[i].infected) infected++;
}
//info bar
noStroke();
fill(0, 200);
rect(width/2, height, width, 100);
String info =
"population: " + count +
" infected: " + infected +
" Wear A Mask: " + wearMask +
" recoverd: " + recovered +
" death: " + death;
fill(255);
textSize(14);
textAlign(CENTER, CENTER);
text(info, width/2, height - 25);
if (infected == 0) frame = 3;
}
if (frame == 3) {
background(255);
fill(0);
textSize(24);
textAlign(CENTER, CENTER);
if (level == 0)
text("wear a mask and make the game easy", width/2, height/2);
if (level == 1)
text("actually not only you who playing this game!", width/2, height/2);
if (level == 2)
text("please don't make game is hard :(", width/2, height/2);
String info =
"population: " + count +
" Wear A Mask: " + 100 * wearMask/count + "%\n" +
"recoverd: " + 100 * recovered/count + "%" +
" death: " + 100 * death/count + "%";
fill(0);
textSize(18);
textAlign(CENTER, CENTER);
text(info, width/2, 100);
resetBtn.display();
}
}
void mousePressed() {
if (frame == 0) {
if (easyBtn.update()) {
level = 0;
frame = 1;
}
if (medBtn.update()) {
level = 1;
frame = 1;
}
if (hardBtn.update()) {
level = 2;
frame = 1;
}
}
if (frame == 1) {
if (startBtn.update()) {
gameSetup(level);
frame = 2;
}
}
if (frame == 2) {
Home c = new Home(mouseX, mouseY, 50);
houses.add(c);
for (Person p : ps) {
p.houses.add(c);
}
}
if (frame == 3) {
if (resetBtn.update()) {
houses.clear();
frame = 0;
}
}
}