xxxxxxxxxx
82
let angle = 0;
let spinning = false;
let spinSpeed = 0;
let sections = [10, 20, 30, 40, 50, 100]; // Numbered sections
let colors = ['#FF6347', '#FFD700', '#FF4500', '#7FFF00', '#1E90FF', '#FF69B4'];
let spinSound;
function preload() {
spinSound = loadSound("wheel.mp3"); // Load the wheel sound
}
function setup() {
createCanvas(800, 400);
textAlign(CENTER, CENTER);
textSize(32);
}
function draw() {
background('rgb(194,233,250)');
// Translate to center and rotate the wheel
translate(width / 2, height / 2);
rotate(angle);
let totalSections = sections.length;
let arcAngle = TWO_PI / totalSections;
// Draw the jackpot wheel with centered numbers
for (let i = 0; i < totalSections; i++) {
fill(colors[i]);
arc(0, 0, 300, 300, i * arcAngle, (i + 1) * arcAngle);
fill(0);
let textAngle = i * arcAngle + arcAngle / 2;
push();
rotate(textAngle);
translate(100, 0); // Move the number closer to the center of the wheel
rotate(HALF_PI); // Align the text to face the center
text(sections[i], 0, 0); // Draw the number
pop();
}
// Reset rotation to draw the arrow on top of the wheel
resetMatrix();
// Draw the pointer
fill(255, 0, 0);
triangle(width / 2 - 10, height / 2 - 160, width / 2 + 10, height / 2 - 160, width / 2, height / 2 - 120);
// Draw back to home button
fill(80, 120, 255);
rect(width - 780, height - 60, 100, 50);
fill(255);
text("Home", width - 730, height - 35);
// Spinning logic
if (spinning) {
angle += spinSpeed;
spinSpeed *= 0.99; // Slow down over time
if (spinSpeed < 0.01) {
spinning = false; // Stop when speed is low enough
spinSound.stop(); // Stop the sound when spinning ends
}
}
}
function mousePressed() {
// Check if the "Home" button is clicked
if (mouseX >= 20 && mouseX <= 120 && mouseY >= height - 60 && mouseY <= height - 10) {
// Redirect to the arcade home page
window.location.href = "arcade.html";
} else {
// Start the wheel spin when clicking anywhere else
if (!spinning) {
spinSpeed = random(0.2, 0.4); // Random spin speed
spinning = true;
spinSound.loop(); // Start playing the sound in a loop while the wheel is spinning
}
}
}