Contrôle du joueur il faut que sa fonctionne sous android.
Crée un plateforme 3D à la quelle c'est composé de plusieurs cube gris attaché les une par les autres. Pour les distinguer a l'extrémité du cube gris il est gris foncé.
un système qui permet de charger des chunck lorsque le joueur se déplace
le joueur incarnera un rectangle vert mes il sera plus petit horizontal par rapport au cube gris
il faut que tu crée un bouton qui permet de mettre à la 1er personne et à la 3eme personne.
un système de hitbox de collision pour éviter que le joueur traverse le cube gris
le ciel est bleu pour l'arrière plan
pour la génération de plateforme il faut qu'il y a des montagnes et des creux (il faut également qu'il y a des cube gris dans le creux)
Utiliser le bibliothèque three
Écrire en une seul fichier de code.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Voici un exemple complet (HTML+JS+CSS) d’un « Minecraft-like » minimal en un seul fichier, utilisant Three.js, adapté Android (touch), avec chunks, collisions, toggle 1ᵉʳ/3ᵉ personne, ciel bleu, montagnes et creux, blocs gris / bords foncés :
html
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
<title>Minecraft-like Three.js</title>
<style>
html, body { margin:0; padding:0; overflow:hidden; touch-action:none; }
canvas { display:block; }
#ui {
position:absolute; top:10px; right:10px; z-index:10;
}
#btnView {
width:50px; height:50px;
background:rgba(0,0,0,0.5); color:white;
border:none; border-radius:5px;
font-size:12px;
}
/* joystick */
#joy {
position:absolute; bottom:20px; left:20px;
width:120px; height:120px;
background:rgba(0,0,0,0.3);
border:2px solid #888; border-radius:50%;
touch-action:none;
z-index:10;
}
#stick {
position:absolute;
width:50px; height:50px;
background:rgba(200,200,200,0.8);
border-radius:50%;
left:35px; top:35px;
touch-action:none;
}
</style>
</head>
<body>
<div id="ui">
<button id="btnView">3ᵉ→1ᵉ</button>
</div>
<div id="joy"><div id="stick"></div></div>
<script src="https://cdn.jsdelivr.net/npm/three@0.155/build/three.min.js"></script>
<script>
// ---- CONFIGURATION ----
const CHUNK_SIZE = 16;
const RENDER_DIST = 2; // en chunks
const BLOCK = 1;
const GRAVITY = -30;
const SPEED = 6;
const JUMP = 12;
// ---- THREE.JS SETUP ----
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x87CEEB); // bleu ciel
const camera = new THREE.PerspectiveCamera(75, innerWidth/innerHeight, 0.1, 200);
const renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
// lumière
scene.add(new THREE.AmbientLight(0xffffff,0.5));
const sun = new THREE.DirectionalLight(0xffffff,0.8);
sun.position.set(30,50,30); sun.castShadow=true;
scene.add(sun);
// ---- JOUEUR ----
const player = {
height:1.8, // m
box: new THREE.Box3(),
velocity:new THREE.Vector3(),
mesh: null,
onGround:false
};
const geo = new THREE.BoxGeometry(0.6,player.height,0.6);
const mat = new THREE.MeshLambertMaterial({color:0x00ff00});
player.mesh = new THREE.Mesh(geo,mat);
player.mesh.castShadow = true;
player.mesh.position.set(0,5,0);
scene.add(player.mesh);
// ---- CHUNKS ET MONDE ----
const world = new Map(); // key="x,y,z" → Mesh
const loaded = new Set(); // "cx,cz"
// matériaux blocs (faces supérieures + inférieures plus foncées)
function blockMats(){
return [
new THREE.MeshLambertMaterial({color:0xAAAAAA}), // droite
new THREE.MeshLambertMaterial({color:0xAAAAAA}), // gauche
new THREE.MeshLambertMaterial({color:0x666666}), // haut
new THREE.MeshLambertMaterial({color:0x666666}), // bas
new THREE.MeshLambertMaterial({color:0xAAAAAA}), // avant
new THREE.MeshLambertMaterial({color:0xAAAAAA}) // arrière
];
}
// bruit procédural simplifié
function hauteur(x,z){
const h1 = Math.sin(x*0.1)*4;
const h2 = Math.cos(z*0.1)*4;
const h3 = Math.sin((x+z)*0.05)*8;
return Math.floor(h1+h2+h3);
}
// créer un chunk
function loadChunk(cx,cz){
const key = `${cx},${cz}`;
if(loaded.has(key)) return;
loaded.add(key);
for(let i=0;i<CHUNK_SIZE;i++){
for(let k=0;k<CHUNK_SIZE;k++){
const gx = cx*CHUNK_SIZE + i;
const gz = cz*CHUNK_SIZE + k;
const h = hauteur(gx,gz);
for(let y=0;y<=h;y++){
const bkey = `${gx},${y},${gz}`;
if(world.has(bkey)) continue;
const m = new THREE.Mesh(new THREE.BoxGeometry(BLOCK,BLOCK,BLOCK), blockMats());
m.position.set(gx,y,gz);
m.receiveShadow=true; m.castShadow=true;
scene.add(m);
world.set(bkey,m);
}
}
}
}
// charger chunks autour du joueur
function updateChunks(){
const px = player.mesh.position.x;
const pz = player.mesh.position.z;
const ccx = Math.floor(px/CHUNK_SIZE);
const ccz = Math.floor(pz/CHUNK_SIZE);
for(let dx=-RENDER_DIST;dx<=RENDER_DIST;dx++){
for(let dz=-RENDER_DIST;dz<=RENDER_DIST;dz++){
loadChunk(ccx+dx, ccz+dz);
}
}
}
// ---- COLLISIONS ----
function collide(pos){
// recalcule la Box3 du joueur
const halfW = 0.3, halfD=0.3;
const min = new THREE.Vector3(pos.x-halfW, pos.y-0.001, pos.z-halfD);
const max = new THREE.Vector3(pos.x+halfW, pos.y+player.height, pos.z+halfD);
player.box.set(min,max);
// vérifier tous les blocs proches
const x0 = Math.floor(min.x), x1=Math.ceil(max.x);
const y0 = Math.floor(min.y), y1=Math.ceil(max.y);
const z0 = Math.floor(min.z), z1=Math.ceil(max.z);
for(let x=x0;x<=x1;x++){
for(let y=y0;y<=y1;y++){
for(let z=z0;z<=z1;z++){
const k = `${x},${y},${z}`;
if(world.has(k)){
const bb = new THREE.Box3().setFromObject(world.get(k));
if(player.box.intersectsBox(bb)) return true;
}
}
}
}
return false;
}
// ---- CONTROLES ANDROID ----
let mv = new THREE.Vector2(0,0); // joystick
const joy = document.getElementById('joy');
const stick = document.getElementById('stick');
let jAct=false, jCx=0, jCy=0;
joy.addEventListener('touchstart', e=>{
e.preventDefault();
jAct=true;
const r=joy.getBoundingClientRect();
jCx = r.left+r.width/2;
jCy = r.top + r.height/2;
});
joy.addEventListener('touchmove', e=>{
if(!jAct) return;
e.preventDefault();
const t=e.touches[0];
let dx = t.clientX-jCx, dy=t.clientY-jCy;
const d = Math.hypot(dx,dy);
const max=40;
if(d>max){
dx=dx/d*max; dy=dy/d*max;
}
stick.style.transform = `translate(${dx}px,${dy}px)`;
mv.set(dx/max, -dy/max);
});
joy.addEventListener('touchend', e=>{
jAct=false;
stick.style.transform=`translate(0,0)`;
mv.set(0,0);
});
// rotation caméra via droite
let rotActive=false, lastX=0, lastY=0;
renderer.domElement.addEventListener('touchstart',e=>{
if(e.touches.length===1 && !jAct){
rotActive=true;
lastX=e.touches[0].clientX;
lastY=e.touches[0].clientY;
}
});
renderer.domElement.addEventListener('touchmove',e=>{
if(!rotActive) return;
e.preventDefault();
const dx=e.touches[0].clientX-lastX;
const dy=e.touches[0].clientY-lastY;
camera.rotation.y -= dx*0.003;
camera.rotation.x -= dy*0.003;
camera.rotation.x = Math.max(-Math.PI/2, Math.min(Math.PI/2, camera.rotation.x));
lastX=e.touches[0].clientX; lastY=e.touches[0].clientY;
});
renderer.domElement.addEventListener('touchend',e=>{
rotActive=false;
});
// saut
document.body.addEventListener('dblclick',e=>{
if(player.onGround){
player.velocity.y = JUMP;
player.onGround=false;
}
});
// toggle 1ᵉ/3ᵉ personne
let firstPerson=false;
document.getElementById('btnView').onclick=()=>{
firstPerson=!firstPerson;
document.getElementById('btnView').innerText = firstPerson?'1ᵉ→3ᵉ':'3ᵉ→1ᵉ';
};
// ---- ANIMATION ----
let last=performance.now();
function animate(now){
const dt=(now-last)/1000; last=now;
// MOUVEMENT
const dir = new THREE.Vector3(mv.x,0,mv.y).applyEuler(camera.rotation);
dir.multiplyScalar(SPEED*dt);
const p0 = player.mesh.position.clone();
const p1 = p0.clone().add(dir);
// collision horiz.
if(!collide(new THREE.Vector3(p1.x,p0.y,p1.z))){
player.mesh.position.x=p1.x; player.mesh.position.z=p1.z;
}
// gravité
player.velocity.y += GRAVITY*dt;
let p2 = player.mesh.position.clone();
p2.y += player.velocity.y*dt;
if(collide(p2)){
// si on descend
if(player.velocity.y<0) player.onGround=true;
player.velocity.y=0;
} else {
player.mesh.position.y=p2.y;
player.onGround=false;
}
// chunks
updateChunks();
// camera
if(firstPerson){
camera.position.copy(player.mesh.position);
camera.position.y += player.height*0.8;
camera.lookAt(player.mesh.position.x + Math.sin(camera.rotation.y),
player.mesh.position.y + player.height*0.8 + Math.sin(camera.rotation.x),
player.mesh.position.z + -Math.cos(camera.rotation.y));
player.mesh.visible=false;
} else {
const offset = new THREE.Vector3( -5, 4, -5 ).applyEuler(camera.rotation);
camera.position.copy(player.mesh.position).add(offset);
camera.lookAt(player.mesh.position);
player.mesh.visible=true;
}
renderer.render(scene,camera);
requestAnimationFrame(animate);
}
animate(performance.now());
// handle resize
window.addEventListener('resize',()=>{
camera.aspect = innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
});
</script>
</body>
</html>
Principales fonctionnalités couvertes :
Contrôles tactiles Android
• Joystick (bas-gauche) pour avancer/reculer/gauche/droite
• Glisser sur la moitié droite pour orienter la caméra
• Double-tap pour sauter