🔬 Notice the food emoji is drawn at (this.y - personSize * 0.75). What happens if you change 0.75 to 1.5 or 0.3? Does the food appear higher, lower, or in a completely different place?
} else if (this.isEating) {
// Display the food emoji above the person while eating
textSize(bulletSize);
text(this.eatingFoodEmoji, this.x, this.y - personSize * 0.75); // Slightly higher for food
// Draw the "satisfied" person figure
fill(this.skinColor);
noStroke();
circle(this.x, this.y - personSize * 0.25, personSize * 0.5); // Head
fill(this.clothesColor);
rectMode(CENTER); // Draw rectangle from its center
rect(this.x, this.y + personSize * 0.25, personSize * 0.5, personSize * 0.5); // Body
🔬 This block counts down and transitions from eating to paying. What if you changed the condition from `<= 0` to `< -30`? When would the person start paying—immediately or after a delay?
this.eatingTimer--;
if (this.eatingTimer <= 0) {
this.isEating = false;
this.hasEaten = true; // Eating phase complete
this.isPaying = true; // Transition to paying
this.payingTimer = payingTimerDuration;
}
function Person(chairX, chairY, chairIndex) { // Now takes chair position and index
// The person's position will be based on the chair they occupy
this.x = chairX;
this.y = chairY - chairSize / 2; // Position slightly above the chair emoji for head
this.chairIndex = chairIndex; // Keep track of the chair they occupy
// Properties for eating animation
this.isEating = false;
this.eatingFoodEmoji = "";
this.eatingTimer = 0;
this.hasEaten = false; // Flag that eating phase is complete
// New properties for paying animation
this.isPaying = false;
this.payingTimer = 0;
// New properties for leaving animation
this.isLeaving = false;
this.leavingSpeed = 0;
this.leavingDirection = 0; // -1 for left, 1 for right
// New properties for fallen state
this.isFallen = false;
this.fallenTimer = 0; // Keep for reference, but no self-get-up.
this.needsAmbulance = false; // Flag to show phone emoji and call ambulance
// Random colors for the person
this.skinColor = color(random(180, 255), random(120, 180), random(80, 120)); // Skin tones
this.clothesColor = color(random(50, 200), random(50, 200), random(50, 200)); // Varied clothes colors
// Method to display the person based on their state
this.display = function() {
if (this.isFallen) {
// Draw fallen person
fill(this.skinColor);
noStroke();
// Draw head slightly rotated or flattened
circle(this.x, this.y - personSize * 0.1, personSize * 0.5); // Adjusted Y for fallen head
fill(this.clothesColor);
rectMode(CENTER);
rect(this.x, this.y + personSize * 0.3, personSize * 0.5, personSize * 0.4); // Adjusted Y for fallen body
rectMode(CORNER);
// Display fallen emoji above them
textSize(bulletSize);
fill(0);
text(fallenEmoji, this.x, this.y - personSize * 0.75); // Slightly higher for emoji
// New: Display phone emoji if ambulance is needed
if (this.needsAmbulance) {
textSize(bulletSize * 0.8);
text(phoneEmoji, this.x + personSize * 0.6, this.y - personSize * 0.75); // Phone emoji next to fallen
}
} else if (this.isEating) {
// Display the food emoji above the person while eating
textSize(bulletSize);
text(this.eatingFoodEmoji, this.x, this.y - personSize * 0.75); // Slightly higher for food
// Draw the "satisfied" person figure
fill(this.skinColor);
noStroke();
circle(this.x, this.y - personSize * 0.25, personSize * 0.5); // Head
fill(this.clothesColor);
rectMode(CENTER); // Draw rectangle from its center
rect(this.x, this.y + personSize * 0.25, personSize * 0.5, personSize * 0.5); // Body
rectMode(CORNER); // Reset rectMode to default
// Add a happy mouth and eyes
fill(0);
stroke(0);
strokeWeight(2);
line(this.x - personSize * 0.1, this.y - personSize * 0.1, this.x + personSize * 0.1, this.y - personSize * 0.1); // Simple line mouth
circle(this.x - personSize * 0.1, this.y - personSize * 0.35, personSize * 0.05); // Left eye
circle(this.x + personSize * 0.1, this.y - personSize * 0.35, personSize * 0.05); // Right eye
noStroke(); // Remove stroke for subsequent shapes
this.eatingTimer--;
if (this.eatingTimer <= 0) {
this.isEating = false;
this.hasEaten = true; // Eating phase complete
this.isPaying = true; // Transition to paying
this.payingTimer = payingTimerDuration;
}
} else if (this.isPaying) {
// Display the money emoji above the person while paying
textSize(bulletSize);
text(moneyEmoji, this.x, this.y - personSize * 0.75); // Slightly higher for money
// Draw the normal person figure
fill(this.skinColor);
noStroke();
circle(this.x, this.y - personSize * 0.25, personSize * 0.5); // Head
fill(this.clothesColor);
rectMode(CENTER); // Draw rectangle from its center
rect(this.x, this.y + personSize * 0.25, personSize * 0.5, personSize * 0.5); // Body
rectMode(CORNER); // Reset rectMode to default
// Add simple eyes
fill(0);
noStroke();
circle(this.x - personSize * 0.1, this.y - personSize * 0.35, personSize * 0.05); // Left eye
circle(this.x + personSize * 0.1, this.y - personSize * 0.35, personSize * 0.05); // Right eye
this.payingTimer--;
if (this.payingTimer <= 0) {
this.isPaying = false;
this.isLeaving = true; // Transition to leaving
this.leavingSpeed = random(leavingSpeedMin, leavingSpeedMax); // Random leaving speed
this.leavingDirection = random([-1, 1]); // Randomly leave left or right
}
} else if (this.isLeaving) {
// Display the waving emoji above the person while leaving
textSize(bulletSize);
text(leavingEmoji, this.x, this.y - personSize * 0.75); // Slightly higher for wave
// Draw the normal person figure
fill(this.skinColor);
noStroke();
circle(this.x, this.y - personSize * 0.25, personSize * 0.5); // Head
fill(this.clothesColor);
rectMode(CENTER); // Draw rectangle from its center
rect(this.x, this.y + personSize * 0.25, personSize * 0.5, personSize * 0.5); // Body
rectMode(CORNER); // Reset rectMode to default
// Add simple eyes
fill(0);
noStroke();
circle(this.x - personSize * 0.1, this.y - personSize * 0.35, personSize * 0.05); // Left eye
circle(this.x + personSize * 0.1, this.y - personSize * 0.35, personSize * 0.05); // Right eye
} else {
// Draw the normal seated person figure
fill(this.skinColor);
noStroke();
circle(this.x, this.y - personSize * 0.25, personSize * 0.5); // Head
fill(this.clothesColor);
rectMode(CENTER); // Draw rectangle from its center
rect(this.x, this.y + personSize * 0.25, personSize * 0.5, personSize * 0.5); // Body
rectMode(CORNER); // Reset rectMode to default
// Add simple eyes
fill(0);
noStroke();
circle(this.x - personSize * 0.1, this.y - personSize * 0.35, personSize * 0.05); // Left eye
circle(this.x + personSize * 0.1, this.y - personSize * 0.35, personSize * 0.05); // Right eye
}
};
// New method for leaving movement
this.moveLeaving = function() {
if (this.isLeaving) {
this.x += this.leavingSpeed * this.leavingDirection;
this.y -= this.leavingSpeed * 0.5; // Move slightly upwards to simulate walking away from table
}
};
// New method to make the person fall
this.fall = function() {
// Only fall if not already in another active state (eating, paying, leaving, or fallen)
if (!this.isEating && !this.isPaying && !this.isLeaving && !this.isFallen) {
this.isFallen = true;
this.fallenTimer = fallenTimerDuration; // Still set for reference, but not used for self-get-up
this.needsAmbulance = true; // Mark that an ambulance is needed
// Stop any potential eating/paying process
this.isEating = false;
this.isPaying = false;
}
};
}