function mousePressed() {
if (gameState === 'MENU') {
startGame(); // Start the game when the menu screen is tapped
return; // Stop further mousePressed logic
}
// Prevent "🦕" action if browser is zoomed (now just a normal ingredient)
if (isBrowserZoomed) {
let message = createDiv('The browser is zoomed! This might affect the game, please reset zoom.');
message.style('position', 'absolute');
message.style('top', '50%');
message.style('left', '50%');
message.style('transform', 'translate(-50%, -50%)'); message.style('font-size', '24px');
message.style('color', '#CC0000');
message.style('background-color', 'rgba(255, 255, 255, 0.5)');
message.style('padding', '15px');
message.style('border-radius', '0');
message.style('z-index', '1000');
message.style('box-shadow', '0 0 10px rgba(0,0,0,0.4)');
setTimeout(() => message.remove(), 2500);
}
// Check if any falling emoji was tapped
for (let i = fallingEmojis.length - 1; i >= 0; i--) {
let emoji = fallingEmojis[i];
if (emoji.isHit(mouseX, mouseY)) {
if (emoji.char === "🐟" && people.length > 0) {
// FISH collected! Summon a UFO to kill a person
const targetPerson = random(people); // Choose a random active person
ufos.push(new UFO(targetPerson, people)); // Add new UFO to the array
} else if (emoji.char === "🦭" && people.length > 0) { // Seal collected!
// SEAL collected! Summon a Shark to kill a person
const targetPerson = random(people); // Choose a random active person
sharks.push(new Shark(targetPerson, people)); // Add new Shark to the array
isOceanActive = true; // Activate ocean background
} else if (emoji.char === "🦞") { // Lobster collected!
// LOBSTER collected! Increase wanted level and spawn police if person is available
wantedLevel = min(5, wantedLevel + 1); // Increase wanted level up to 5 stars
updateUI(); // Update DOM wantedLevelDisplay immediately
if (people.length > 0) {
let targetPerson = people[0]; // Target the first person on the serving line
let servingLineTopY = height - uiContainer.elt.offsetHeight - SERVING_LINE_Y_OFFSET - SERVING_LINE_HEIGHT_ON_CANVAS;
if (wantedLevel >= 1) policeCars.push(new PoliceCar(targetPerson, people, servingLineTopY));
if (wantedLevel >= 3) swatTeams.push(new SWATTeam(targetPerson, people, servingLineTopY));
if (wantedLevel >= 5) helicopters.push(new PoliceHelicopter(targetPerson, people));
}
} else if (emoji.char === "🦀" && people.length > 0) { // Crab collected!
// CRAB collected! Summon a single Airplane to crash into a person
const targetPerson = random(people); // Choose a random active person
airplanes.push(new Airplane(targetPerson, people)); // Add new Airplane to the array
} else if (emoji.char === "🦧") { // Orangutan collected!
let shooterPerson = people.find(p => p.hasGun && p.state !== 'DYING' && p.state !== 'AWAITING_AMBULANCE');
let availablePeopleForGun = people.filter(p => !p.hasGun && p.state !== 'DYING' && p.state !== 'AWAITING_AMBULANCE');
// Spawn the target person in the middle
let newTargetPerson = new Person(width / 2); // Spawn in the middle
people.push(newTargetPerson);
if (!shooterPerson && availablePeopleForGun.length > 0) {
// If no one is armed yet, arm a random available person (excluding the new target)
let potentialShooters = people.filter(p => p !== newTargetPerson && !p.hasGun && p.state !== 'DYING' && p.state !== 'AWAITING_AMBULANCE');
if (potentialShooters.length > 0) {
shooterPerson = random(potentialShooters);
shooterPerson.hasGun = true;
shooterPerson.shootTimer = 0; // Reset shoot timer
let message = createDiv('Someone just got a gun! New target in the middle!');
message.style('position', 'absolute');
message.style('top', '50%');
message.style('left', '50%');
message.style('transform', 'translate(-50%, -50%)');
message.style('font-size', '32px');
message.style('color', '#990000');
message.style('background-color', 'rgba(255, 255, 255, 0.5)');
message.style('padding', '20px');
message.style('border-radius', '0');
message.style('z-index', '1000');
message.style('box-shadow', '2px 2px 5px rgba(0,0,0,0.3)');
setTimeout(() => message.remove(), 3000);
}
} else if (shooterPerson) {
// If there's already a shooter, they'll automatically target the new person
let message = createDiv('New target in the middle!');
message.style('position', 'absolute');
message.style('top', '50%');
message.style('left', '50%');
message.style('transform', 'translate(-50%, -50%)');
message.style('font-size', '32px');
message.style('color', '#007700');
message.style('background-color', 'rgba(255, 255, 255, 0.5)');
message.style('padding', '20px');
message.style('border-radius', '0');
message.style('z-index', '1000');
message.style('box-shadow', '2px 2px 5px rgba(0,0,0,0.3)');
setTimeout(() => message.remove(), 3000);
}
} else if (emoji.char === "🦕") { // DINOSAUR collected! Now just a normal ingredient.
collectedEmojis.push(emoji.char); // Treat it as a normal ingredient
let message = createDiv(`Collected an ingredient: ${emoji.char}`);
message.style('position', 'absolute');
message.style('top', '50%');
message.style('left', '50%');
message.style('transform', 'translate(-50%, -50%)');
message.style('font-size', '32px');
message.style('color', '#007700');
message.style('background-color', 'rgba(255, 255, 255, 0.5)');
message.style('padding', '20px');
message.style('border-radius', '0');
message.style('z-index', '1000');
message.style('box-shadow', '2px 2px 5px rgba(0,0,0,0.3)');
setTimeout(() => message.remove(), 3000);
} else if (emoji.char === "🦖") { // T-Rex collected! Trigger a fight!
gameState = 'FIGHTING';
fightMessages = []; // Clear previous fight messages
let servingLineY = height - uiContainer.elt.offsetHeight - SERVING_LINE_Y_OFFSET - SERVING_LINE_HEIGHT_ON_CANVAS;
fighter1 = new Fighter(width * 0.25, servingLineY, 'person', random(personWeapons));
fighter2 = new Fighter(width * 0.75, servingLineY, 'dinosaur', random(dinosaurWeapons));
fightMessages.unshift({ text: "A mighty T-Rex approaches! FIGHT!", lifespan: FIGHT_MESSAGE_LIFESPAN * 2 });
fightTimer = FIGHT_TURN_DURATION;
} else {
// NORMAL EMOJI collected - ONLY add to ingredients, DO NOT spawn people!
collectedEmojis.push(emoji.char); // Add emoji character to collected array
let message = createDiv(`Collected an ingredient: ${emoji.char}`);
message.style('position', 'absolute');
message.style('top', '50%');
message.style('left', '50%');
message.style('transform', 'translate(-50%, -50%)');
message.style('font-size', '32px');
message.style('color', '#007700');
message.style('background-color', 'rgba(255, 255, 255, 0.5)');
message.style('padding', '20px');
message.style('border-radius', '0');
message.style('z-index', '1000');
message.style('box-shadow', '2px 2px 5px rgba(0,0,0,0.3)');
setTimeout(() => message.remove(), 2000);
}
fallingEmojis.splice(i, 1); // Remove from falling array
fallingEmojis.push(new Emoji()); // Add a new emoji to keep the rain going
updateUI(); // Update DOM collectedArea and button state with new emojis
return; // Stop checking after the first hit
}
}
}