147 lines
5.5 KiB
PHP
147 lines
5.5 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// Check if user is logged in
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header("Location: register.php");
|
|
exit();
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Level 3 - The Spin Wheel</title>
|
|
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
<style>
|
|
.wheel-container {
|
|
position: relative;
|
|
width: 400px;
|
|
height: 400px;
|
|
margin: 50px auto;
|
|
}
|
|
|
|
#canvas {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.spin-btn {
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
width: 80px;
|
|
height: 80px;
|
|
border-radius: 50%;
|
|
background-color: #ffc107;
|
|
border: 4px solid #fff;
|
|
color: #212529;
|
|
font-weight: bold;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
text-align: center;
|
|
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="text-center">
|
|
|
|
<main class="container">
|
|
<div class="logo">Studio RIT</div>
|
|
<h2>Level 3: The Spin Wheel</h2>
|
|
<p>Spin the wheel and land on the 'Logo' segment to win!</p>
|
|
|
|
<div class="wheel-container">
|
|
<canvas id="canvas" width="400" height="400"></canvas>
|
|
<div class="spin-btn" id="spin_button">SPIN</div>
|
|
</div>
|
|
|
|
</main>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/winwheeljs@2.8.0/dist/Winwheel.min.js"></script>
|
|
|
|
<script>
|
|
// Create new wheel object specifying the parameters at creation time.
|
|
let theWheel = new Winwheel({
|
|
'numSegments' : 8, // Specify number of segments.
|
|
'outerRadius' : 200, // Set outer radius so wheel fits inside the background.
|
|
'textFontSize' : 28, // Set font size as desired.
|
|
'segments' : // Define segments including colour and text.
|
|
[
|
|
{'fillStyle' : '#eae56f', 'text' : 'Prize 1'},
|
|
{'fillStyle' : '#89f26e', 'text' : 'Prize 2'},
|
|
{'fillStyle' : '#7de6ef', 'text' : 'Logo'},
|
|
{'fillStyle' : '#e7706f', 'text' : 'Prize 4'},
|
|
{'fillStyle' : '#eae56f', 'text' : 'Prize 5'},
|
|
{'fillStyle' : '#89f26e', 'text' : 'Prize 6'},
|
|
{'fillStyle' : '#7de6ef', 'text' : 'Prize 7'},
|
|
{'fillStyle' : '#e7706f', 'text' : 'Prize 8'}
|
|
],
|
|
'animation' : // Specify the animation to use.
|
|
{
|
|
'type' : 'spinToStop',
|
|
'duration' : 5, // Duration in seconds.
|
|
'spins' : 8, // Number of complete spins.
|
|
'callbackFinished' : alertPrize,
|
|
}
|
|
});
|
|
|
|
// Vars used by the code in this page to do power controls.
|
|
let wheelSpinning = false;
|
|
|
|
// -------------------------------------------------------
|
|
// Function to handle the onClick on the power buttons.
|
|
// -------------------------------------------------------
|
|
function startSpin()
|
|
{
|
|
// Ensure that spinning can't be clicked again while already running.
|
|
if (wheelSpinning == false) {
|
|
// Begin the spin animation by calling startAnimation on the wheel object.
|
|
theWheel.startAnimation();
|
|
|
|
// Set to true so that power can't be changed and spin button re-enabled during
|
|
// the animation. The user will have to reset before spinning again.
|
|
wheelSpinning = true;
|
|
}
|
|
}
|
|
|
|
// -------------------------------------------------------
|
|
// Function for reset button.
|
|
// -------------------------------------------------------
|
|
function resetWheel()
|
|
{
|
|
theWheel.stopAnimation(false); // Stop the animation, false as parameter so does not call callback function.
|
|
theWheel.rotationAngle = 0; // Re-set the wheel angle to 0 degrees.
|
|
theWheel.draw(); // Call draw to render changes to the wheel.
|
|
wheelSpinning = false; // Reset to false to power buttons and spin can be clicked again.
|
|
}
|
|
|
|
// -------------------------------------------------------
|
|
// Called when the spin animation has finished by the callback feature of the wheel because I specified callback in the parameters
|
|
// note the indicated segment is passed in as a parmeter as 99% of the time you will want to know this.
|
|
// -------------------------------------------------------
|
|
function alertPrize(indicatedSegment)
|
|
{
|
|
// Do basic alert of the prize Descriptions.
|
|
if (indicatedSegment.text == 'Logo') {
|
|
alert("You won! Proceeding to the next level.");
|
|
window.location.href = 'update_level3.php';
|
|
} else {
|
|
alert("You didn't land on the Logo. Try again!");
|
|
resetWheel();
|
|
}
|
|
}
|
|
|
|
document.getElementById('spin_button').addEventListener('click', startSpin);
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|