شوتر موبایل
by WildWave36577 lines19.9 KB🛠️ Three.js (3D graphics)
<!--ARCADELAB title: بازی شوتر موبایل description: شوتر اول شخص موبایل با تفنگ و چاقو libraries: three emoji: 🔫 color: red -->
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>شوتر موبایل</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #000; font-family: sans-serif; touch-action: none; }
canvas { display: block; }
/* کراسهیر */
#crosshair {
position: fixed; top: 50%; left: 50%;
width: 26px; height: 26px;
transform: translate(-50%,-50%);
pointer-events: none; z-index: 10;
}
#crosshair::before, #crosshair::after {
content: ''; position: absolute; background: #0f0;
box-shadow: 0 0 4px #0f0;
}
#crosshair::before { width: 2px; height: 26px; left: 12px; }
#crosshair::after { width: 26px; height: 2px; top: 12px; }
/* جویاستیک */
#joyBase {
position: fixed; bottom: 30px; left: 30px;
width: 130px; height: 130px;
border-radius: 50%;
background: rgba(255,255,255,0.12);
border: 2px solid rgba(255,255,255,0.35);
z-index: 20; touch-action: none;
}
#joyKnob {
position: absolute; top: 50%; left: 50%;
width: 55px; height: 55px;
margin: -27.5px 0 0 -27.5px;
border-radius: 50%;
background: rgba(255,255,255,0.55);
border: 2px solid rgba(255,255,255,0.8);
transition: none;
}
/* دکمه شلیک */
#fireBtn {
position: fixed; bottom: 35px; right: 30px;
width: 95px; height: 95px;
border-radius: 50%;
background: rgba(220,30,30,0.75);
border: 3px solid rgba(255,120,120,0.9);
color: white; font-size: 32px; font-weight: bold;
display: flex; align-items: center; justify-content: center;
z-index: 20; touch-action: none;
box-shadow: 0 0 15px rgba(255,0,0,0.5);
}
#fireBtn:active { background: rgba(255,60,60,0.95); transform: scale(0.95); }
/* دکمه تعویض سلاح */
#switchBtn {
position: fixed; bottom: 145px; right: 45px;
width: 70px; height: 70px;
border-radius: 50%;
background: rgba(50,80,150,0.75);
border: 2px solid rgba(120,160,255,0.9);
color: white; font-size: 28px;
display: flex; align-items: center; justify-content: center;
z-index: 20; touch-action: none;
}
#switchBtn:active { background: rgba(80,120,220,0.95); }
/* امتیاز */
#score {
position: fixed; top: 12px; right: 12px;
color: #0f0; background: rgba(0,0,0,0.6);
padding: 8px 16px; border-radius: 8px;
font-size: 16px; font-weight: bold; z-index: 10;
}
/* هیتمارکر */
#hitmarker {
position: fixed; top: 50%; left: 50%;
transform: translate(-50%,-50%);
color: #ff3030; font-size: 44px; font-weight: bold;
pointer-events: none; z-index: 11; display: none;
text-shadow: 0 0 8px #f00;
}
/* پیام شروع */
#tip {
position: fixed; top: 50%; left: 50%;
transform: translate(-50%,-50%);
color: white; background: rgba(0,0,0,0.8);
padding: 22px 28px; border-radius: 12px;
font-size: 16px; z-index: 30; text-align: center;
line-height: 1.8; max-width: 85%;
}
#tip b { color: #0f0; }
</style>
</head>
<body>
<div id="crosshair"></div>
<div id="score">Kills: 0</div>
<div id="hitmarker">✕</div>
<div id="joyBase"><div id="joyKnob"></div></div>
<div id="fireBtn">🔥</div>
<div id="switchBtn">🔫</div>
<div id="tip">
<b>جویاستیک چپ:</b> حرکت<br>
<b>کشیدن انگشت راست:</b> چرخش دوربین<br>
<b>دکمه قرمز:</b> شلیک<br>
<b>دکمه آبی:</b> تعویض سلاح<br><br>
برای شروع، این پیام را لمس کن
</div>
<script>
// ============ صحنه ============
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x87CEEB);
scene.fog = new THREE.Fog(0x87CEEB, 15, 55);
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.rotation.order = 'YXZ';
scene.add(camera);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: 'high-performance' });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
document.body.appendChild(renderer.domElement);
// ============ نورها ============
scene.add(new THREE.AmbientLight(0xffffff, 0.55));
const dirLight = new THREE.DirectionalLight(0xffffff, 0.9);
dirLight.position.set(8, 15, 6);
dirLight.castShadow = true;
dirLight.shadow.mapSize.width = 512;
dirLight.shadow.mapSize.height = 512;
dirLight.shadow.camera.left = -35;
dirLight.shadow.camera.right = 35;
dirLight.shadow.camera.top = 35;
dirLight.shadow.camera.bottom = -35;
scene.add(dirLight);
const viewLight = new THREE.PointLight(0xffffff, 1.3, 4);
viewLight.position.set(0.3, 0.2, 0.5);
camera.add(viewLight);
// ============ زمین ============
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(120, 120),
new THREE.MeshStandardMaterial({ color: 0x3a5f3a, roughness: 0.9 })
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
// ============ موانع ============
const obstacles = [];
const obsMat = new THREE.MeshStandardMaterial({ color: 0x8B4513 });
for (let i = 0; i < 18; i++) {
const box = new THREE.Mesh(new THREE.BoxGeometry(1.5, 2, 1.5), obsMat);
let x, z;
do {
x = (Math.random() - 0.5) * 50;
z = (Math.random() - 0.5) * 50;
} while (Math.abs(x) < 4 && Math.abs(z) < 4);
box.position.set(x, 1, z);
box.castShadow = true;
box.receiveShadow = true;
scene.add(box);
obstacles.push(box);
}
// ============ تفنگ در دست ============
const gunGroup = new THREE.Group();
const gunMat = new THREE.MeshStandardMaterial({ color: 0x333333, depthTest: false, transparent: true });
const gunMatDark = new THREE.MeshStandardMaterial({ color: 0x1a1a1a, depthTest: false, transparent: true });
const gbody = new THREE.Mesh(new THREE.BoxGeometry(0.16, 0.16, 0.55), gunMat);
gbody.position.set(0.32, -0.28, -0.55); gunGroup.add(gbody);
const gbarrel = new THREE.Mesh(new THREE.BoxGeometry(0.09, 0.09, 0.35), gunMatDark);
gbarrel.position.set(0.32, -0.26, -0.92); gunGroup.add(gbarrel);
const ggrip = new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.28, 0.14), gunMatDark);
ggrip.position.set(0.32, -0.5, -0.42); gunGroup.add(ggrip);
const gsight = new THREE.Mesh(new THREE.BoxGeometry(0.04, 0.06, 0.04), gunMatDark);
gsight.position.set(0.32, -0.17, -0.75); gunGroup.add(gsight);
gunGroup.traverse(o => { if (o.isMesh) { o.renderOrder = 999; o.castShadow = false; } });
camera.add(gunGroup);
// ============ چاقو در دست ============
const knifeGroup = new THREE.Group();
const bladeMat = new THREE.MeshStandardMaterial({ color: 0xd0d0d0, metalness: 0.7, roughness: 0.3, depthTest: false, transparent: true });
const handleMat = new THREE.MeshStandardMaterial({ color: 0x3a1e08, depthTest: false, transparent: true });
const kblade = new THREE.Mesh(new THREE.BoxGeometry(0.07, 0.55, 0.03), bladeMat);
kblade.position.set(0.35, -0.25, -0.6); knifeGroup.add(kblade);
const ktip = new THREE.Mesh(new THREE.ConeGeometry(0.035, 0.15, 4), bladeMat);
ktip.position.set(0.35, 0.1, -0.6); ktip.rotation.z = Math.PI; knifeGroup.add(ktip);
const khandle = new THREE.Mesh(new THREE.BoxGeometry(0.09, 0.22, 0.06), handleMat);
khandle.position.set(0.35, -0.6, -0.6); knifeGroup.add(khandle);
const kguard = new THREE.Mesh(new THREE.BoxGeometry(0.15, 0.04, 0.06), handleMat);
kguard.position.set(0.35, -0.47, -0.6); knifeGroup.add(kguard);
knifeGroup.traverse(o => { if (o.isMesh) { o.renderOrder = 999; o.castShadow = false; } });
knifeGroup.visible = false;
camera.add(knifeGroup);
// ============ بازیکن ============
const player = { height: 1.6, speed: 6.5, yaw: 0, pitch: 0 };
camera.position.y = player.height;
// ============ دشمنها ============
const enemies = [];
let score = 0;
const scoreEl = document.getElementById('score');
function spawnEnemy() {
const group = new THREE.Group();
group.userData.isEnemy = true;
const bodyMat = new THREE.MeshStandardMaterial({ color: 0xcc2222 });
const bodyMesh = new THREE.Mesh(new THREE.BoxGeometry(0.7, 1.3, 0.4), bodyMat);
bodyMesh.position.y = 0.85; bodyMesh.castShadow = true;
group.add(bodyMesh);
group.userData.bodyMat = bodyMat;
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.28, 10, 10),
new THREE.MeshStandardMaterial({ color: 0xffcc99 })
);
head.position.y = 1.75; head.castShadow = true;
group.add(head);
const armMat = new THREE.MeshStandardMaterial({ color: 0xaa1111 });
const armL = new THREE.Mesh(new THREE.BoxGeometry(0.16, 0.85, 0.16), armMat);
armL.position.set(-0.45, 1.0, 0); armL.castShadow = true; group.add(armL);
const armR = new THREE.Mesh(new THREE.BoxGeometry(0.16, 0.85, 0.16), armMat);
armR.position.set(0.45, 1.0, 0); armR.castShadow = true; group.add(armR);
const legMat = new THREE.MeshStandardMaterial({ color: 0x223a6b });
const legL = new THREE.Mesh(new THREE.BoxGeometry(0.22, 0.75, 0.22), legMat);
legL.position.set(-0.18, 0.375, 0); legL.castShadow = true; group.add(legL);
const legR = new THREE.Mesh(new THREE.BoxGeometry(0.22, 0.75, 0.22), legMat);
legR.position.set(0.18, 0.375, 0); legR.castShadow = true; group.add(legR);
let x, z;
do {
x = (Math.random() - 0.5) * 45;
z = (Math.random() - 0.5) * 45;
} while (Math.sqrt(x*x + z*z) < 8);
group.position.set(x, 0, z);
group.userData.health = 100;
group.userData.speed = 1.5 + Math.random() * 1.8;
group.userData.dir = new THREE.Vector3(Math.random()-0.5, 0, Math.random()-0.5).normalize();
group.userData.dirTimer = 1 + Math.random() * 2;
group.userData.flashTimer = 0;
scene.add(group);
enemies.push(group);
}
for (let i = 0; i < 8; i++) spawnEnemy();
// ============ کنترل لمسی ============
const tipEl = document.getElementById('tip');
tipEl.addEventListener('touchstart', e => { e.preventDefault(); tipEl.style.display = 'none'; });
tipEl.addEventListener('click', () => { tipEl.style.display = 'none'; });
// --- جویاستیک ---
const joyBase = document.getElementById('joyBase');
const joyKnob = document.getElementById('joyKnob');
let joyTouchId = null;
let joyVector = { x: 0, y: 0 };
const JOY_RADIUS = 55;
function updateJoy(clientX, clientY) {
const rect = joyBase.getBoundingClientRect();
const cx = rect.left + rect.width / 2;
const cy = rect.top + rect.height / 2;
let dx = clientX - cx;
let dy = clientY - cy;
const dist = Math.sqrt(dx*dx + dy*dy);
if (dist > JOY_RADIUS) {
dx = dx / dist * JOY_RADIUS;
dy = dy / dist * JOY_RADIUS;
}
joyKnob.style.transform = `translate(${dx}px, ${dy}px)`;
joyVector.x = dx / JOY_RADIUS;
joyVector.y = dy / JOY_RADIUS;
}
joyBase.addEventListener('touchstart', e => {
e.preventDefault();
if (joyTouchId !== null) return;
const t = e.changedTouches[0];
joyTouchId = t.identifier;
updateJoy(t.clientX, t.clientY);
}, { passive: false });
document.addEventListener('touchmove', e => {
for (let i = 0; i < e.changedTouches.length; i++) {
const t = e.changedTouches[i];
if (t.identifier === joyTouchId) {
updateJoy(t.clientX, t.clientY);
e.preventDefault();
return;
}
if (t.identifier === lookTouchId) {
const dx = t.clientX - lookLastX;
const dy = t.clientY - lookLastY;
player.yaw -= dx * 0.005;
player.pitch -= dy * 0.005;
player.pitch = Math.max(-Math.PI/2 + 0.1, Math.min(Math.PI/2 - 0.1, player.pitch));
lookLastX = t.clientX;
lookLastY = t.clientY;
e.preventDefault();
return;
}
}
}, { passive: false });
document.addEventListener('touchend', e => {
for (let i = 0; i < e.changedTouches.length; i++) {
const t = e.changedTouches[i];
if (t.identifier === joyTouchId) {
joyTouchId = null;
joyVector.x = 0; joyVector.y = 0;
joyKnob.style.transform = 'translate(0,0)';
}
if (t.identifier === lookTouchId) {
lookTouchId = null;
}
}
}, { passive: false });
document.addEventListener('touchcancel', e => {
for (let i = 0; i < e.changedTouches.length; i++) {
const t = e.changedTouches[i];
if (t.identifier === joyTouchId) {
joyTouchId = null;
joyVector.x = 0; joyVector.y = 0;
joyKnob.style.transform = 'translate(0,0)';
}
if (t.identifier === lookTouchId) {
lookTouchId = null;
}
}
}, { passive: false });
// --- چرخش دوربین (نیمه راست صفحه) ---
let lookTouchId = null;
let lookLastX = 0, lookLastY = 0;
renderer.domElement.addEventListener('touchstart', e => {
e.preventDefault();
if (lookTouchId !== null) return;
for (let i = 0; i < e.changedTouches.length; i++) {
const t = e.changedTouches[i];
if (t.clientX > window.innerWidth * 0.35) {
lookTouchId = t.identifier;
lookLastX = t.clientX;
lookLastY = t.clientY;
break;
}
}
}, { passive: false });
// --- دکمه شلیک ---
const fireBtn = document.getElementById('fireBtn');
let firing = false;
let fireCooldown = 0;
fireBtn.addEventListener('touchstart', e => {
e.preventDefault();
e.stopPropagation();
firing = true;
fireWeapon();
}, { passive: false });
fireBtn.addEventListener('touchend', e => {
e.preventDefault();
e.stopPropagation();
firing = false;
}, { passive: false });
fireBtn.addEventListener('touchcancel', e => {
firing = false;
}, { passive: false });
// --- دکمه تعویض سلاح ---
const switchBtn = document.getElementById('switchBtn');
switchBtn.addEventListener('touchstart', e => {
e.preventDefault();
e.stopPropagation();
switchWeapon(currentWeapon === 'gun' ? 'knife' : 'gun');
}, { passive: false });
// جلوگیری از منوی راستکلیک
window.addEventListener('contextmenu', e => e.preventDefault());
// ============ سلاح ============
let currentWeapon = 'gun';
function switchWeapon(type) {
currentWeapon = type;
gunGroup.visible = (type === 'gun');
knifeGroup.visible = (type === 'knife');
switchBtn.textContent = type === 'gun' ? '🔪' : '🔫';
}
// ============ شلیک ============
const hitmarkerEl = document.getElementById('hitmarker');
function showHitmarker() {
hitmarkerEl.style.display = 'block';
clearTimeout(hitmarkerEl._t);
hitmarkerEl._t = setTimeout(() => hitmarkerEl.style.display = 'none', 130);
}
function findEnemyRoot(obj) {
let o = obj;
while (o) {
if (o.userData && o.userData.isEnemy) return o;
o = o.parent;
}
return null;
}
let recoil = 0;
function fireWeapon() {
if (currentWeapon === 'gun') {
recoil = 1;
const ray = new THREE.Raycaster();
ray.setFromCamera(new THREE.Vector2(0, 0), camera);
ray.far = 100;
const hits = ray.intersectObjects(enemies.concat(obstacles), true);
if (hits.length > 0) {
const hitObj = hits[0].object;
const enemyRoot = findEnemyRoot(hitObj);
if (enemyRoot) {
damageEnemy(enemyRoot, 34);
} else if (hitObj.material && hitObj.material.color) {
const oldColor = hitObj.material.color.getHex();
hitObj.material.color.setHex(0xffff00);
setTimeout(() => hitObj.material.color.setHex(oldColor), 100);
}
}
} else {
recoil = 0.6;
const ray = new THREE.Raycaster();
ray.setFromCamera(new THREE.Vector2(0, 0), camera);
ray.far = 2.8;
const hits = ray.intersectObjects(enemies, true);
if (hits.length > 0) {
const enemyRoot = findEnemyRoot(hits[0].object);
if (enemyRoot) damageEnemy(enemyRoot, 60);
}
}
}
function damageEnemy(enemy, dmg) {
enemy.userData.health -= dmg;
enemy.userData.bodyMat.color.setHex(0xffffff);
enemy.userData.flashTimer = 0.15;
showHitmarker();
if (enemy.userData.health <= 0) {
scene.remove(enemy);
const idx = enemies.indexOf(enemy);
if (idx !== -1) enemies.splice(idx, 1);
score++;
scoreEl.textContent = 'Kills: ' + score;
setTimeout(spawnEnemy, 800);
}
}
// ============ حلقه بازی ============
const clock = new THREE.Clock();
let bobTime = 0, walkBobY = 0, walkBobX = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.1);
if (firing && fireCooldown <= 0 && currentWeapon === 'gun') {
fireWeapon();
fireCooldown = 0.18;
}
if (fireCooldown > 0) fireCooldown -= delta;
camera.rotation.y = player.yaw;
camera.rotation.x = player.pitch;
// حرکت با جویاستیک
const forward = new THREE.Vector3(-Math.sin(player.yaw), 0, -Math.cos(player.yaw));
const right = new THREE.Vector3(Math.cos(player.yaw), 0, -Math.sin(player.yaw));
const spd = player.speed * delta;
const moveVec = new THREE.Vector3();
if (Math.abs(joyVector.x) > 0.15 || Math.abs(joyVector.y) > 0.15) {
moveVec.addScaledVector(forward, -joyVector.y);
moveVec.addScaledVector(right, joyVector.x);
if (moveVec.lengthSq() > 0) moveVec.normalize().multiplyScalar(spd);
}
const moving = moveVec.lengthSq() > 0.0001;
camera.position.x += moveVec.x;
camera.position.z += moveVec.z;
camera.position.x = Math.max(-55, Math.min(55, camera.position.x));
camera.position.z = Math.max(-55, Math.min(55, camera.position.z));
camera.position.y = player.height;
// لرزش راه رفتن
if (moving) {
bobTime += delta * 11;
walkBobY = Math.sin(bobTime * 2) * 0.012;
walkBobX = Math.sin(bobTime) * 0.008;
} else {
bobTime = 0;
walkBobY = 0;
walkBobX = 0;
}
if (recoil > 0) recoil = Math.max(0, recoil - delta * 6);
const recoilZ = recoil * 0.12;
const recoilRot = recoil * 0.3;
gunGroup.position.set(walkBobX, walkBobY, recoilZ);
gunGroup.rotation.x = recoilRot;
knifeGroup.position.set(walkBobX, walkBobY, recoilZ * 0.5);
knifeGroup.rotation.x = recoilRot * 0.5;
// دشمنها
for (let i = 0; i < enemies.length; i++) {
const e = enemies[i];
const d = e.userData;
d.dirTimer -= delta;
if (d.dirTimer <= 0) {
if (Math.random() < 0.65) {
d.dir.set(
camera.position.x - e.position.x, 0,
camera.position.z - e.position.z
).normalize();
} else {
d.dir.set(Math.random()-0.5, 0, Math.random()-0.5).normalize();
}
d.dirTimer = 1.5 + Math.random() * 2.5;
}
e.position.x += d.dir.x * d.speed * delta;
e.position.z += d.dir.z * d.speed * delta;
if (Math.abs(e.position.x) > 28) { e.position.x = Math.sign(e.position.x) * 28; d.dir.x *= -1; }
if (Math.abs(e.position.z) > 28) { e.position.z = Math.sign(e.position.z) * 28; d.dir.z *= -1; }
e.rotation.y = Math.atan2(d.dir.x, d.dir.z);
if (d.flashTimer > 0) {
d.flashTimer -= delta;
if (d.flashTimer <= 0) d.bodyMat.color.setHex(0xcc2222);
}
}
renderer.render(scene, camera);
}
animate();
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.Game Source: شوتر موبایل
Creator: WildWave36
Libraries: three
Complexity: complex (577 lines, 19.9 KB)
The full source code is displayed above on this page.
Remix Instructions
To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: game-wildwave36-mx0st3wp" to link back to the original. Then publish at arcadelab.ai/publish.