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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Plinko Game</title>
|
| 7 |
+
<style>
|
| 8 |
+
body {
|
| 9 |
+
margin: 0;
|
| 10 |
+
overflow: hidden;
|
| 11 |
+
font-family: Arial, sans-serif;
|
| 12 |
+
}
|
| 13 |
+
#info {
|
| 14 |
+
position: absolute;
|
| 15 |
+
top: 10px;
|
| 16 |
+
width: 100%;
|
| 17 |
+
text-align: center;
|
| 18 |
+
color: white;
|
| 19 |
+
font-size: 24px;
|
| 20 |
+
pointer-events: none;
|
| 21 |
+
}
|
| 22 |
+
#container {
|
| 23 |
+
width: 100%;
|
| 24 |
+
height: 100vh;
|
| 25 |
+
}
|
| 26 |
+
a {
|
| 27 |
+
color: #4CAF50;
|
| 28 |
+
text-decoration: none;
|
| 29 |
+
}
|
| 30 |
+
a:hover {
|
| 31 |
+
text-decoration: underline;
|
| 32 |
+
}
|
| 33 |
+
</style>
|
| 34 |
+
</head>
|
| 35 |
+
<body>
|
| 36 |
+
<div id="info">
|
| 37 |
+
Plinko Game - <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a>
|
| 38 |
+
<br>
|
| 39 |
+
Click to drop the ball
|
| 40 |
+
</div>
|
| 41 |
+
<div id="container"></div>
|
| 42 |
+
|
| 43 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.132.2/build/three.min.js"></script>
|
| 44 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/controls/OrbitControls.js"></script>
|
| 45 |
+
<script>
|
| 46 |
+
// Scene setup
|
| 47 |
+
const scene = new THREE.Scene();
|
| 48 |
+
scene.background = new THREE.Color(0x111111);
|
| 49 |
+
|
| 50 |
+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 51 |
+
camera.position.set(0, 5, 10);
|
| 52 |
+
|
| 53 |
+
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
| 54 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 55 |
+
renderer.shadowMap.enabled = true;
|
| 56 |
+
document.getElementById('container').appendChild(renderer.domElement);
|
| 57 |
+
|
| 58 |
+
// Controls
|
| 59 |
+
const controls = new THREE.OrbitControls(camera, renderer.domElement);
|
| 60 |
+
controls.enableDamping = true;
|
| 61 |
+
controls.dampingFactor = 0.05;
|
| 62 |
+
|
| 63 |
+
// Lighting
|
| 64 |
+
const ambientLight = new THREE.AmbientLight(0x404040);
|
| 65 |
+
scene.add(ambientLight);
|
| 66 |
+
|
| 67 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
|
| 68 |
+
directionalLight.position.set(5, 10, 7);
|
| 69 |
+
directionalLight.castShadow = true;
|
| 70 |
+
scene.add(directionalLight);
|
| 71 |
+
|
| 72 |
+
// Create Plinko board
|
| 73 |
+
const boardWidth = 10;
|
| 74 |
+
const boardHeight = 10;
|
| 75 |
+
const boardGeometry = new THREE.BoxGeometry(boardWidth, boardHeight, 0.2);
|
| 76 |
+
const boardMaterial = new THREE.MeshPhongMaterial({ color: 0x333333 });
|
| 77 |
+
const board = new THREE.Mesh(boardGeometry, boardMaterial);
|
| 78 |
+
board.position.y = -boardHeight / 2;
|
| 79 |
+
board.receiveShadow = true;
|
| 80 |
+
scene.add(board);
|
| 81 |
+
|
| 82 |
+
// Create pegs
|
| 83 |
+
const pegRadius = 0.2;
|
| 84 |
+
const pegHeight = 0.5;
|
| 85 |
+
const pegGeometry = new THREE.CylinderGeometry(pegRadius, pegRadius, pegHeight, 32);
|
| 86 |
+
const pegMaterial = new THREE.MeshPhongMaterial({ color: 0x00aaff });
|
| 87 |
+
|
| 88 |
+
const pegs = [];
|
| 89 |
+
const rows = 10;
|
| 90 |
+
const pegsPerRow = 11;
|
| 91 |
+
const spacing = 0.8;
|
| 92 |
+
|
| 93 |
+
for (let row = 0; row < rows; row++) {
|
| 94 |
+
const offset = (row % 2) * spacing / 2;
|
| 95 |
+
for (let col = 0; col < pegsPerRow; col++) {
|
| 96 |
+
const peg = new THREE.Mesh(pegGeometry, pegMaterial);
|
| 97 |
+
peg.position.x = (col - (pegsPerRow - 1) / 2) * spacing + offset;
|
| 98 |
+
peg.position.y = -row * spacing;
|
| 99 |
+
peg.position.z = 0.1;
|
| 100 |
+
peg.castShadow = true;
|
| 101 |
+
peg.receiveShadow = true;
|
| 102 |
+
scene.add(peg);
|
| 103 |
+
pegs.push(peg);
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
// Create ball
|
| 108 |
+
const ballRadius = 0.3;
|
| 109 |
+
const ballGeometry = new THREE.SphereGeometry(ballRadius, 32, 32);
|
| 110 |
+
const ballMaterial = new THREE.MeshPhongMaterial({ color: 0xff0000 });
|
| 111 |
+
const ball = new THREE.Mesh(ballGeometry, ballMaterial);
|
| 112 |
+
ball.position.set(0, 4, 0);
|
| 113 |
+
ball.castShadow = true;
|
| 114 |
+
scene.add(ball);
|
| 115 |
+
|
| 116 |
+
// Physics variables
|
| 117 |
+
let ballVelocity = new THREE.Vector3(0, 0, 0);
|
| 118 |
+
const gravity = -0.01;
|
| 119 |
+
const friction = 0.99;
|
| 120 |
+
const pegCollisionDistance = pegRadius + ballRadius;
|
| 121 |
+
|
| 122 |
+
// Game state
|
| 123 |
+
let gameActive = false;
|
| 124 |
+
|
| 125 |
+
// Handle window resize
|
| 126 |
+
window.addEventListener('resize', () => {
|
| 127 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 128 |
+
camera.updateProjectionMatrix();
|
| 129 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 130 |
+
});
|
| 131 |
+
|
| 132 |
+
// Handle mouse click
|
| 133 |
+
window.addEventListener('click', () => {
|
| 134 |
+
if (!gameActive) {
|
| 135 |
+
gameActive = true;
|
| 136 |
+
ball.position.set(0, 4, 0);
|
| 137 |
+
ballVelocity.set(0, 0, 0);
|
| 138 |
+
}
|
| 139 |
+
});
|
| 140 |
+
|
| 141 |
+
// Animation loop
|
| 142 |
+
function animate() {
|
| 143 |
+
requestAnimationFrame(animate);
|
| 144 |
+
|
| 145 |
+
if (gameActive) {
|
| 146 |
+
// Apply gravity
|
| 147 |
+
ballVelocity.y += gravity;
|
| 148 |
+
|
| 149 |
+
// Apply friction
|
| 150 |
+
ballVelocity.x *= friction;
|
| 151 |
+
ballVelocity.z *= friction;
|
| 152 |
+
|
| 153 |
+
// Update ball position
|
| 154 |
+
ball.position.add(ballVelocity);
|
| 155 |
+
|
| 156 |
+
// Check for collisions with pegs
|
| 157 |
+
for (const peg of pegs) {
|
| 158 |
+
const distance = ball.position.distanceTo(peg.position);
|
| 159 |
+
if (distance < pegCollisionDistance) {
|
| 160 |
+
// Simple collision response
|
| 161 |
+
const normal = ball.position.clone().sub(peg.position).normalize();
|
| 162 |
+
ballVelocity.reflect(normal).multiplyScalar(0.8);
|
| 163 |
+
|
| 164 |
+
// Move ball outside the peg
|
| 165 |
+
const overlap = pegCollisionDistance - distance;
|
| 166 |
+
ball.position.add(normal.multiplyScalar(overlap * 0.5));
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// Check if ball fell off the board
|
| 171 |
+
if (ball.position.y < -boardHeight / 2 - ballRadius) {
|
| 172 |
+
gameActive = false;
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
controls.update();
|
| 177 |
+
renderer.render(scene, camera);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
animate();
|
| 181 |
+
</script>
|
| 182 |
+
</body>
|
| 183 |
+
</html>
|