🎮ArcadeLab

Zombie City FPS

by BoldPenguin14
92 lines4.4 KB
▶ Play
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Zombie City FPS</title>
<style>
*{touch-action:none}body{margin:0;overflow:hidden;background:#222;color:white;font:18px Arial}
canvas{width:100vw;height:100vh;display:block}
#hud{position:absolute;top:10px;left:10px}
#joy{position:absolute;bottom:20px;left:20px;width:110px;height:110px;border-radius:50%;background:#ffffff44}
#stick{margin:35px;width:40px;height:40px;border-radius:50%;background:white}
#fire{position:absolute;bottom:45px;right:30px;padding:25px;border:0;border-radius:50%;background:#c22;color:white}
#menu{position:absolute;inset:0;background:#000c;display:grid;place-content:center;text-align:center}
</style>
</head>
<body>
<canvas id="c"></canvas><div id="hud"></div>
<div id="joy"><div id="stick"></div></div>
<button id="fire">🔥</button>
<div id="menu"><h1>🧟 ZOMBIE CITY</h1><button onclick="start()">START</button></div>
<script>
let c=document.querySelector('#c'),g=c.getContext('2d'),W,H;
function resize(){W=c.width=innerWidth;H=c.height=innerHeight}onresize=resize;resize();
let p,z=[],b=[],keys={},joy={x:0,y:0},health=100,kills=0,playing=false;
function spawn(){let a=Math.random()*6.28,d=18+Math.random()*30;z.push({x:p.x+Math.sin(a)*d,y:p.y+Math.cos(a)*d,h:100})}
function start(){p={x:0,y:0,a:0};z=[];health=100;kills=0;playing=true;menu.style.display='none';for(let i=0;i<10;i++)spawn()}
let buildings=[];
for(let i=0;i<65;i++){let a=Math.random()*6.28,d=12+Math.random()*100;buildings.push({x:Math.sin(a)*d,y:Math.cos(a)*d,w:4+Math.random()*7,h:6+Math.random()*15,col:['#454545','#625447','#34434b'][i%3]})}
onkeydown=e=>{keys[e.key.toLowerCase()]=1};
onkeyup=e=>keys[e.key.toLowerCase()]=0;

let look=null;
c.onpointerdown=e=>look={x:e.clientX,y:e.clientY};
c.onpointermove=e=>{if(look){p.a+=(e.clientX-look.x)*.005;look={x:e.clientX,y:e.clientY}}};
c.onpointerup=c.onpointercancel=()=>look=null;

let j=document.querySelector('#joy'),st=document.querySelector('#stick');
j.onpointerdown=j.onpointermove=e=>{
if(!e.buttons&&e.pointerType!=='touch')return;
let r=j.getBoundingClientRect(),x=e.clientX-r.left-55,y=e.clientY-r.top-55,d=Math.hypot(x,y)||1;
joy.x=x/d*Math.min(1,d/35);joy.y=y/d*Math.min(1,d/35);
st.style.transform=`translate(${joy.x*35}px,${joy.y*35}px)`;
};
j.onpointerup=j.onpointercancel=()=>{joy={x:0,y:0};st.style.transform=''};
fire.onpointerdown=e=>{e.preventDefault();shoot()};
function shoot(){
if(!playing)return;
let best=null,dist=35;
z.forEach(v=>{let dx=v.x-p.x,dy=v.y-p.y,d=Math.hypot(dx,dy),a=Math.atan2(dx,dy)-p.a;a=Math.atan2(Math.sin(a),Math.cos(a));if(Math.abs(a)<.13&&d<dist){best=v;dist=d}});
if(best){best.h-=50;if(best.h<=0){z=z.filter(v=>v!==best);kills++;spawn()}}
}
function draw(){
g.fillStyle='#52604d';g.fillRect(0,0,W,H/2);
g.fillStyle='#292820';g.fillRect(0,H/2,W,H/2);
let objects=[
...buildings.map(v=>({...v,type:0})),
...z.map(v=>({...v,type:1}))
];
objects.map(v=>({...v,d:Math.hypot(v.x-p.x,v.y-p.y),a:Math.atan2(v.x-p.x,v.y-p.y)-p.a}))
.filter(v=>Math.abs(Math.atan2(Math.sin(v.a),Math.cos(v.a)))<1.25)
.sort((a,b)=>b.d-a.d).forEach(v=>{
let a=Math.atan2(Math.sin(v.a),Math.cos(v.a)),s=450/v.d,x=W/2+Math.tan(a)*W*.7,y=H/2;
if(v.type===0){
g.fillStyle=v.col;g.fillRect(x-v.w*s/2,y-v.h*s,v.w*s,v.h*s);
g.fillStyle='#171e21';
for(let i=0;i<3;i++)for(let k=0;k<2;k++)g.fillRect(x-v.w*s/2+i*v.w*s/3,y-v.h*s*(.8-k*.25),v.w*s/8,v.h*s/10);
}else{
g.fillStyle='#527c3c';g.beginPath();g.arc(x,y-s*.3,s*.15,0,7);g.fill();
g.fillRect(x-s*.15,y-s*.3,s*.3,s*.5);
g.fillStyle='red';g.fillRect(x-s*.12,y-s*.4,s*.24*v.h/100,4);
}
});
g.fillStyle='#555';g.fillRect(W/2-30,H-100,60,100);
g.fillStyle='white';g.font='25px Arial';g.fillText('+',W/2-7,H/2+8);
hud.innerHTML=`❤️ ${Math.floor(health)} | 🧟 ${kills}`;
}
function update(){
if(playing){
let x=joy.x+(keys.d?1:0)-(keys.a?1:0),y=-joy.y+(keys.w?1:0)-(keys.s?1:0),d=Math.hypot(x,y)||1;
p.x+=Math.sin(p.a)*y/d*.15+Math.cos(p.a)*x/d*.15;
p.y+=Math.cos(p.a)*y/d*.15-Math.sin(p.a)*x/d*.15;
z.forEach(v=>{let dx=p.x-v.x,dy=p.y-v.y,d=Math.hypot(dx,dy)||1;if(d>1.2){v.x+=dx/d*.025;v.y+=dy/d*.025}else health-=.1});
if(z.length<10&&Math.random()<.008)spawn();
draw();
if(health<=0){playing=false;menu.style.display='grid';menu.innerHTML=`<h1>GAME OVER</h1><p>Kills: ${kills}</p><button onclick="start()">RESTART</button>`}
}
requestAnimationFrame(update);
}
update();
</script>
</body>
</html>

Game Source: Zombie City FPS

Creator: BoldPenguin14

Libraries: none

Complexity: moderate (92 lines, 4.4 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: zombie-city-fps-boldpenguin14" to link back to the original. Then publish at arcadelab.ai/publish.