Meta Description" name="description" />
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mobile Battle Royale</title>
<style>
body { margin:0; overflow:hidden; }
#ui {
position: absolute;
bottom: 20px;
width: 100%;
display: flex;
justify-content: space-between;
padding: 20px;
}
.btn {
width: 60px;
height: 60px;
background: rgba(255,255,255,0.4);
border-radius: 50%;
text-align: center;
line-height: 60px;
font-weight: bold;
font-size: 18px;
user-select: none;
}
#shoot {
position:absolute;
right:20px;
bottom:120px;
}
#health {
position:absolute;
top:10px;
left:10px;
color:white;
font-size:18px;
}
</style>
</head>
<body>
<div id="health">Health: 200</div>
<div id="ui">
<div>
<div class="btn" id="up">β</div>
<div style="display:flex; gap:10px;">
<div class="btn" id="left">β</div>
<div class="btn" id="down">β</div>
<div class="btn" id="right">β</div>
</div>
</div>
<div>
<div class="btn" id="gloo">G</div>
</div>
</div>
<div class="btn" id="shoot">π«</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
let scene = new THREE.Scene();
scene.background = new THREE.Color(0x87CEEB);
let camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
let renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
let light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(10,20,10);
scene.add(light);
let ground = new THREE.Mesh(
new THREE.PlaneGeometry(200,200),
new THREE.MeshLambertMaterial({color:0x228B22})
);
ground.rotation.x = -Math.PI/2;
scene.add(ground);
let player = new THREE.Mesh(
new THREE.BoxGeometry(1,2,1),
new THREE.MeshLambertMaterial({color:0x0000ff})
);
player.position.set(0,1,0);
scene.add(player);
let enemy = new THREE.Mesh(
new THREE.BoxGeometry(1,2,1),
new THREE.MeshLambertMaterial({color:0xff0000})
);
enemy.position.set(10,1,0);
scene.add(enemy);
let bullets=[];
let glooWalls=[];
let health=200;
let enemyHealth=200;
camera.position.set(0,8,12);
camera.lookAt(0,0,0);
// Movement
function move(x,z){
player.position.x += x;
player.position.z += z;
}
document.getElementById("up").ontouchstart=()=>move(0,-0.5);
document.getElementById("down").ontouchstart=()=>move(0,0.5);
document.getElementById("left").ontouchstart=()=>move(-0.5,0);
document.getElementById("right").ontouchstart=()=>move(0.5,0);
// Shoot
document.getElementById("shoot").ontouchstart=()=>{
let bullet = new THREE.Mesh(
new THREE.SphereGeometry(0.2),
new THREE.MeshBasicMaterial({color:0xffff00})
);
bullet.position.copy(player.position);
scene.add(bullet);
bullets.push(bullet);
};
// Gloo Wall
document.getElementById("gloo").ontouchstart=()=>{
let gloo = new THREE.Mesh(
new THREE.BoxGeometry(3,3,0.5),
new THREE.MeshLambertMaterial({color:0x00ffff,transparent:true,opacity:0.6})
);
gloo.position.set(player.position.x,1.5,player.position.z-2);
scene.add(gloo);
glooWalls.push(gloo);
setTimeout(()=>{
scene.remove(gloo);
},8000);
};
function animate(){
requestAnimationFrame(animate);
bullets.forEach((b,index)=>{
b.position.x+=0.5;
if(b.position.distanceTo(enemy.position)<1){
enemyHealth-=20;
scene.remove(b);
bullets.splice(index,1);
if(enemyHealth<=0){
alert("π YOU WIN!");
}
}
});
renderer.render(scene,camera);
}
animate();
</script>
</body>
</html>2
2
123KB
593KB
609.0ms
116.0ms
609.0ms