<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Pool Party – Three.js FPS Demo</title>
<style>
html,body{
margin:0;
padding:0;
overflow:hidden;
height:100%;
font-family:Arial,Helvetica,sans-serif;
color:#fff;
user-select:none;
}
canvas{display:block;}
/* -------- HUD ---------- */
#hud{
position:fixed;
top:10px;
left:10px;
padding:10px 14px;
background:rgba(0,0,0,0.35);
border-radius:6px;
font-size:14px;
line-height:1.4em;
pointer-events:none;
}
#hud span{font-weight:bold;}
/* -------- Pointer-lock overlay ---------- */
#overlay{
position:fixed;
inset:0;
background:rgba(0,0,0,0.85);
display:flex;
align-items:center;
justify-content:center;
flex-direction:column;
text-align:center;
color:#fff;
font-size:20px;
cursor:pointer;
z-index:5;
}
#overlay.hide{display:none;}
#overlay small{font-size:14px;color:#ccc;margin-top:8px;}
</style>
<!-- ES-module import map -->
<script type="importmap">
{
"imports":{
"three":"https://unpkg.com/three@0.159.0/build/three.module.js",
"three/addons/":"https://unpkg.com/three@0.159.0/examples/jsm/",
"PointerLockControls":"https://unpkg.com/three@0.159.0/examples/jsm/controls/PointerLockControls.js"
}
}
</script>
</head>
<body>
<div id="overlay">
Click to play
<small>(W A S D to move – Mouse to look – Space to jump – Hold LMB to… relieve yourself 😅)</small>
</div>
<div id="hud">
Pee Meter : <span id="peeVal">100%</span><br>
Bladder Health : <span id="bladder">Excellent</span><br>
Score : <span id="score">0</span>
</div>
<script type="module">
/* =============================================================
Imports & basic setup
============================================================= */
import * as THREE from 'three';
import { PointerLockControls } from 'PointerLockControls';
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x87ceeb); // sky-blue
scene.fog = new THREE.Fog(0x87ceeb, 10, 120);
const camera = new THREE.PerspectiveCamera(75, innerWidth/innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setSize(innerWidth,innerHeight);
document.body.appendChild(renderer.domElement);
/* =============================================================
Lights
============================================================= */
scene.add(new THREE.HemisphereLight(0xeeeeff, 0x444466, 0.6));
const dirLight = new THREE.DirectionalLight(0xffffff, 0.8);
dirLight.position.set(50, 100, 50);
scene.add(dirLight);
/* =============================================================
Pool & environment geometry
============================================================= */
const loader = new THREE.TextureLoader();
const tileTex = loader.load('https://cdn.jsdelivr.net/gh/mrdoob/three.js@dev/examples/textures/uv_grid_opengl.jpg');
tileTex.wrapS = tileTex.wrapT = THREE.RepeatWrapping;
tileTex.repeat.set(4,2);
// Walkable deck
(function(){
const deck = new THREE.Mesh(
new THREE.PlaneGeometry(80,80),
new THREE.MeshLambertMaterial({color:0x808080})
);
deck.rotation.x = -Math.PI/2;
scene.add(deck);
})();
// Pool dimensions
const POOL_LEN = 20; // x
const POOL_WID = 10; // z
const POOL_DEPTH = 5;
// Pool floor
const poolFloor = new THREE.Mesh(
new THREE.PlaneGeometry(POOL_LEN, POOL_WID,1,1),
new THREE.MeshPhongMaterial({map:tileTex,side:THREE.DoubleSide})
);
poolFloor.rotation.x = -Math.PI/2;
poolFloor.position.y = -POOL_DEPTH;
scene.add(poolFloor);
// Pool walls (4 boxes)
const wallMat = new THREE.MeshPhongMaterial({map:tileTex});
const wallThk = 0.2, hw = POOL_WID/2, hl = POOL_LEN/2;
const walls = new THREE.Group();
[
// long walls (along x, front/back)
[new THREE.BoxGeometry(POOL_LEN, POOL_DEPTH, wallThk), 0, -POOL_DEPTH/2, -hw],
[new THREE.BoxGeometry(POOL_LEN, POOL_DEPTH, wallThk), 0, -POOL_DEPTH/2, hw],
// short walls (along z, left/right)
[new THREE.BoxGeometry(wallThk, POOL_DEPTH, POOL_WID), -hl, -POOL_DEPTH/2, 0],
[new THREE.BoxGeometry(wallThk, POOL_DEPTH, POOL_WID), hl, -POOL_DEPTH/2, 0],
].forEach(([geo,x,y,z])=>{
const m = new THREE.Mesh(geo, wallMat);
m.position.set(x,y,z);
walls.add(m);
});
scene.add(walls);
// Water surface
const water = new THREE.Mesh(
new THREE.PlaneGeometry(POOL_LEN,POOL_WID),
new THREE.MeshPhongMaterial({color:0x3399ff,transparent:true,opacity:0.4})
);
water.rotation.x = -Math.PI/2;
water.position.y = 0;
scene.add(water);
/* =============================================================
Controls & movement
============================================================= */
const controls = new PointerLockControls(camera, document.body);
scene.add(controls.getObject());
const overlay = document.getElementById('overlay');
overlay.addEventListener('click', ()=>{ controls.lock(); });
controls.addEventListener('lock', ()=> overlay.classList.add('hide') );
controls.addEventListener('unlock',()=> overlay.classList.remove('hide') );
let moveF = false, moveB=false, moveL=false, moveR=false;
let canJump = false;
const velocity = new THREE.Vector3();
const direction = new THREE.Vector3();
const clock = new THREE.Clock();
const playerHeight = 1.6;
controls.getObject().position.set(0, playerHeight, 30); // start outside pool
document.addEventListener('keydown', (e)=>{
switch(e.code){
case 'KeyW': case 'ArrowUp': moveF=true; break;
case 'KeyS': case 'ArrowDown': moveB=true; break;
case 'KeyA': case 'ArrowLeft': moveL=true; break;
case 'KeyD': case 'ArrowRight': moveR=true; break;
case 'Space':
if(canJump && !isInWater()) {
velocity.y += 6;
canJump=false;
}
break;
}
});
document.addEventListener('keyup', (e)=>{
switch(e.code){
case 'KeyW': case 'ArrowUp': moveF=false; break;
case 'KeyS': case 'ArrowDown': moveB=false; break;
case 'KeyA': case 'ArrowLeft': moveL=false; break;
case 'KeyD': case 'ArrowRight': moveR=false; break;
}
});
/* =============================================================
Pineapple-juice particle system
============================================================= */
const particles = []; // {mesh,vel}
const partGeo = new THREE.SphereGeometry(0.05,8,8);
function createParticle(pos,dir,color){
const mesh = new THREE.Mesh(partGeo, new THREE.MeshBasicMaterial({color}));
mesh.position.copy(pos);
scene.add(mesh);
particles.push({mesh,vel:dir.multiplyScalar(8).add(new THREE.Vector3(0,2,0))});
}
/* =============================================================
UI / Game Metrics
============================================================= */
let peeMeter = 100;
let score = 0;
const peeSpan = document.getElementById('peeVal');
const bladSpan= document.getElementById('bladder');
const scoreSpan= document.getElementById('score');
function updateHUD(){
peeSpan.textContent = Math.max(0,peeMeter.toFixed(0)) + '%';
let health='Excellent';
if(peeMeter>80) health='Excellent';
else if(peeMeter>50) health='Good';
else if(peeMeter>20) health='Warning';
else health='Critical';
bladSpan.textContent = health;
scoreSpan.textContent = score.toFixed(0);
}
/* =============================================================
Input state for streaming
============================================================= */
let isStreaming = false;
window.addEventListener('mousedown', e=>{
if(e.button===0) isStreaming=true;
});
window.addEventListener('mouseup', e=>{
if(e.button===0) isStreaming=false;
});
/* =============================================================
Helpers
============================================================= */
function isInsidePool(x,z){
return Math.abs(x)<=POOL_LEN/2 && Math.abs(z)<=POOL_WID/2;
}
function isInWater(){
return camera.position.y < 0;
}
/* =============================================================
Main animation loop
============================================================= */
function animate(){
requestAnimationFrame(animate);
const dt = Math.min(0.05, clock.getDelta()); // clamp for stability
if(controls.isLocked){
/* ----- movement physics ----- */
direction.set(0,0,0);
if(moveF) direction.z -= 1;
if(moveB) direction.z += 1;
if(moveL) direction.x -= 1;
if(moveR) direction.x += 1;
direction.normalize();
const speed = isInWater()? 4 : 10;
if(direction.lengthSq()>0){
// convert local to world direction
const vec = new THREE.Vector3(direction.x,0,direction.z);
// rotate by camera yaw
vec.applyQuaternion(controls.getObject().quaternion);
controls.moveRight( vec.x * speed * dt);
controls.moveForward(vec.z * speed * dt);
}
/* ----- vertical physics ----- */
if(isInWater()){
// buoyancy
velocity.y += 4*dt; // upward push
velocity.y -= 2*dt; // small gravity
}else{
velocity.y -= 9.8 * dt; // gravity
}
controls.getObject().position.y += velocity.y * dt;
/* ----- collision with ground / pool floor ----- */
const pos = controls.getObject().position;
const inPool = isInsidePool(pos.x,pos.z);
const floorLevel = inPool ? -POOL_DEPTH : 0;
if(pos.y < floorLevel + playerHeight){
pos.y = floorLevel + playerHeight;
velocity.y = 0;
canJump = !inPool; // inside pool you float, no jump
}
}
/* ----- handle particle streaming ----- */
if(isStreaming && peeMeter>0){
// spawn several particles per second
if(Math.random() < 15*dt){
const origin = new THREE.Vector3().copy(camera.position);
origin.y -= 0.2; // emit slightly below eye
const dir = new THREE.Vector3(0,0,-1).applyQuaternion(camera.quaternion).normalize();
const color = (peeMeter<=20)?0xff0000:0xffff00;
createParticle(origin, dir, color);
}
peeMeter -= 15*dt;
score += 20*dt;
peeMeter = Math.max(0,peeMeter);
}
/* ----- update particles ----- */
for(let i=particles.length-1;i>=0;i--){
const p = particles[i];
p.vel.y -= 9.8*dt; // gravity on particle
p.mesh.position.addScaledVector(p.vel, dt);
// collision with water
if(p.mesh.position.y <= 0){
p.mesh.position.y = 0;
p.vel.set(0,0,0);
}
// remove if too old / out of bounds
if(p.mesh.position.length() > 200 || (p.vel.lengthSq()===0 && Math.random()<0.01)){
scene.remove(p.mesh);
particles.splice(i,1);
}
}
updateHUD();
renderer.render(scene,camera);
}
animate();
/* =============================================================
Handle window resize
============================================================= */
window.addEventListener('resize',()=>{
camera.aspect = innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
});
</script>
</body>
</html>