<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Tembak Corona - Bos Raksasa</title>
<style>
*{margin:0;padding:0;box-sizing:border-box;font-family:Arial,sans-serif;touch-action:none}
body{background:#0a0a2e;overflow:hidden;display:flex;justify-content:center}
#gameWrap{width:100%;max-width:420px;height:100vh;position:relative;background:linear-gradient(#0a0a2e,#1a0033);overflow:hidden}
#header{position:absolute;top:0;left:0;right:0;z-index:10;display:flex;justify-content:space-between;padding:10px;color:#fff;font-weight:bold;background:rgba(0,0,0,0.6);font-size:14px}
#bosBarWrap{position:absolute;top:42px;left:10px;right:10px;z-index:11;display:none;background:rgba(0,0,0,0.7);padding:8px;border-radius:10px;color:#fff}
#bosBarWrap b{color:#ff1744;font-size:13px}
#bosBarBg{width:100%;height:14px;background:#333;border-radius:10px;margin-top:5px;overflow:hidden}
#bosBar{width:100%;height:100%;background:linear-gradient(90deg,#ff1744,#ff9800);transition:width 0.2s}
canvas{width:100%;height:100%;display:block}
#startScreen{position:absolute;inset:0;background:rgba(0,0,0,0.88);color:#fff;display:flex;flex-direction:column;justify-content:center;align-items:center;text-align:center;padding:20px;z-index:20}
#startScreen h1{font-size:30px;color:#00ff88}
#startScreen h2{font-size:18px;color:#ffeb3b;margin-bottom:12px}
#startScreen p{font-size:14px;line-height:1.6;color:#ddd;margin-bottom:15px}
.btnMain{background:#00e676;color:#000;border:none;padding:15px 30px;border-radius:50px;font-size:20px;font-weight:bold;cursor:pointer}
#btnTembak{position:absolute;bottom:20px;right:20px;width:80px;height:80px;border-radius:50%;background:#ff1744;color:#fff;font-size:28px;border:4px solid #fff;z-index:15;display:none}
#peringatan{position:absolute;top:35%;left:0;right:0;text-align:center;font-size:28px;font-weight:bold;color:#ff1744;z-index:16;display:none;text-shadow:2px 2px 0 #fff;animation:kedip 0.5s infinite}
@keyframes kedip{50%{opacity:0.3}}
#gameOver{position:absolute;inset:0;background:rgba(0,0,0,0.92);color:#fff;display:none;flex-direction:column;justify-content:center;align-items:center;text-align:center;padding:20px;z-index:20}
#gameOver h1{font-size:30px;color:#ff1744}
</style>
</head>
<body>
<div id="gameWrap">
<div id="header">
<div>SKOR: <span id="skor">0</span></div>
<div>LV: <span id="level">1</span></div>
<div><span id="nyawa">❤️❤️❤️</span></div>
</div>
<div id="bosBarWrap">
<b>👹 BOS VIRUS RAKSASA - <span id="bosNama">MEGA CORONA</span></b>
<div id="bosBarBg"><div id="bosBar"></div></div>
</div>
<div id="peringatan">⚠️ BOS DATANG! ⚠️</div>
<canvas id="gameCanvas"></canvas>
<div id="startScreen">
<div style="font-size:70px">🦠👹💥</div>
<h1>TEMBAK CORONA</h1>
<h2>COVID WAR - BOS MODE</h2>
<p>🦠 Tembak virus kecil<br>
👹 <b style="color:#ff5252">WASPADA! Tiap Level 5 muncul BOS RAKSASA!</b><br>
❤️ Bos punya darah 30x tembakan<br>
🎯 Bos bisa nembak balik ke kamu!<br>
🏆 Kalahkan Bos dapat +500 Poin!</p>
<button class="btnMain" onclick="mulaiGame()">▶️ MULAI PERANG</button>
</div>
<button id="btnTembak">💥</button>
<div id="gameOver">
<div style="font-size:60px">😷</div>
<h1>GAME OVER</h1>
<h2 id="skorAkhir">Skor: 0</h2>
<p id="pesanAkhir"></p><br>
<button class="btnMain" onclick="mulaiGame()">🔄 MAIN LAGI</button>
</div>
</div>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
let W, H;
function resize(){
W = document.getElementById('gameWrap').clientWidth;
H = document.getElementById('gameWrap').clientHeight;
canvas.width = W; canvas.height = H;
}
window.addEventListener('resize', resize); resize();
let gameJalan=false, skor=0, nyawa=3, level=1;
let pemain={x:0,y:0,w:60,h:60};
let peluru=[], musuh=[], musuhPeluru=[], bintang=[], bos=null;
let musuhTimer=0, bosSudahMunculDiLevel=0;
let namaBosList = ["MEGA CORONA","OMICRON KING","DELTA DESTROYER","COVID ULTRA","VIRUS APOCALYPSE"];
function resetGame(){
skor=0; nyawa=3; level=1; bos=null; bosSudahMunculDiLevel=0;
pemain.x=W/2-30; pemain.y=H-130;
peluru=[]; musuh=[]; musuhPeluru=[]; bintang=[];
for(let i=0;i<60;i++) bintang.push({x:Math.random()*W, y:Math.random()*H, s:Math.random()*2+0.5});
document.getElementById('bosBarWrap').style.display='none';
updateHUD();
}
function mulaiGame(){
document.getElementById('startScreen').style.display='none';
document.getElementById('gameOver').style.display='none';
document.getElementById('btnTembak').style.display='block';
resetGame(); gameJalan=true;
requestAnimationFrame(loop);
}
function updateHUD(){
document.getElementById('skor').innerText=skor;
document.getElementById('level').innerText=level;
document.getElementById('nyawa').innerText="❤️".repeat(nyawa);
if(bos){
document.getElementById('bosBarWrap').style.display='block';
document.getElementById('bosBar').style.width = (bos.hp / bos.maxHp * 100) + "%";
document.getElementById('bosNama').innerText = bos.nama;
} else {
document.getElementById('bosBarWrap').style.display='none';
}
}
function bunyi(freq){
try{
let a=new (window.AudioContext||window.webkitAudioContext)();
let o=a.createOscillator(); o.type='square'; o.frequency.value=freq;
let g=a.createGain(); g.gain.value=0.08;
o.connect(g); g.connect(a.destination); o.start(); o.stop(a.currentTime+0.08);
}catch(e){}
}
function tembak(){
if(!gameJalan) return;
peluru.push({x:pemain.x+25, y:pemain.y, w:8, h:18});
bunyi(800);
}
function buatMusuh(){
let uk=35+Math.random()*25;
let jenis=["🦠","🦠","🦠","👾","☣️"][Math.floor(Math.random()*5)];
musuh.push({x:Math.random()*(W-uk), y:-uk, w:uk, h:uk, speed:1.5+level*0.35+Math.random(), emoji:jenis, putar:Math.random()*360});
}
function munculkanBos(){
let nama = namaBosList[Math.floor(Math.random()*namaBosList.length)];
bos = {x:W/2-70, y:50, w:140, h:140, hp:30+level*5, maxHp:30+level*5, arah:1, tembakTimer:0, emoji:"👹"};
bosSudahMunculDiLevel = level;
document.getElementById('peringatan').style.display='block';
setTimeout(()=> document.getElementById('peringatan').style.display='none', 2000);
updateHUD();
}
function loop(){
if(!gameJalan) return;
ctx.clearRect(0,0,W,H);
ctx.fillStyle="#fff";
bintang.forEach(b=>{ ctx.fillRect(b.x,b.y,b.s,b.s); b.y+=1; if(b.y>H) b.y=0; });
// Cek Bos Muncul - Tiap kelipatan 5
if(level % 5 === 0 && bosSudahMunculDiLevel !== level && !bos){
munculkanBos();
}
// Kalau ada Bos, virus kecil berhenti dulu biar fokus lawan Bos
if(!bos){
musuhTimer++;
if(musuhTimer > Math.max(25, 60-level*4)){ buatMusuh(); musuhTimer=0; }
}
// Gambar Pemain
ctx.font="50px Arial"; ctx.textAlign="center";
ctx.fillText("🚀", pemain.x+30, pemain.y+45);
// Peluru Pemain
peluru.forEach((p,i)=>{
p.y-=10; ctx.fillStyle="#00ff88"; ctx.fillRect(p.x,p.y,p.w,p.h);
ctx.fillStyle="#ffff00"; ctx.beginPath(); ctx.arc(p.x+4,p.y,5,0,Math.PI*2); ctx.fill();
if(p.y<0) peluru.splice(i,1);
});
// Musuh Kecil
musuh.forEach((m,mi)=>{
m.y+=m.speed; m.putar+=2;
ctx.save(); ctx.translate(m.x+m.w/2, m.y+m.h/2); ctx.rotate(m.putar*Math.PI/180);
ctx.font=m.w+"px Arial"; ctx.fillText(m.emoji,0,m.w/3); ctx.restore();
peluru.forEach((p,pi)=>{
if(p.x>m.x && p.x<m.x+m.w && p.y>m.y && p.y<m.y+m.h){
musuh.splice(mi,1); peluru.splice(pi,1); skor+=10;
if(skor%100===0) level++; updateHUD();
}
});
if(m.y+m.h>pemain.y && m.y<pemain.y+pemain.h && m.x+m.w>pemain.x && m.x<pemain.x+pemain.w){
musuh.splice(mi,1); nyawa--; updateHUD(); if(nyawa<=0) gameOver();
}
if(m.y>H) musuh.splice(mi,1);
});
// === BOS RAKSASA ===
if(bos){
bos.x += 1.2 * bos.arah;
if(bos.x <= 0 || bos.x >= W-bos.w) bos.arah *= -1;
bos.y = 50 + Math.sin(Date.now()/500)*10;
// Gambar Bos
ctx.font = bos.w + "px Arial";
ctx.fillText("👹", bos.x + bos.w/2, bos.y + bos.w/2 + 20);
ctx.font = "30px Arial";
ctx.fillText("🦠", bos.x + 20, bos.y + 30);
ctx.fillText("🦠", bos.x + bos.w - 20, bos.y + 30);
// Bos Nembak Balik
bos.tembakTimer++;
if(bos.tembakTimer > 50){
musuhPeluru.push({x:bos.x+bos.w/2, y:bos.y+bos.h, w:12, h:12});
bos.tembakTimer=0;
}
// Cek Peluru Kena Bos
peluru.forEach((p,pi)=>{
if(p.x>bos.x && p.x<bos.x+bos.w && p.y>bos.y && p.y<bos.y+bos.h){
peluru.splice(pi,1); bos.hp--; bunyi(200); updateHUD();
if(bos.hp<=0){
skor+=500; level++;
document.getElementById('hasilBos') ;
alert("🎉 BOS KALAH! +500 Poin! Kamu Hebat!");
bos=null; updateHUD();
}
}
});
// Cek Bos Nabrak Pemain
if(bos.y+bos.h>pemain.y && bos.y<pemain.y+pemain.h && bos.x+bos.w>pemain.x && bos.x<pemain.x+pemain.w){
nyawa--; updateHUD(); bos.y=50;
if(nyawa<=0) gameOver();
}
}
// Peluru Bos
musuhPeluru.forEach((mp, i)=>{
mp.y+=5;
ctx.fillStyle="#ff1744"; ctx.beginPath(); ctx.arc(mp.x, mp.y, 8, 0, Math.PI*2); ctx.fill();
ctx.font="16px Arial"; ctx.fillText("🦠", mp.x, mp.y+5);
if(mp.x>pemain.x && mp.x<pemain.x+pemain.w && mp.y>pemain.y && mp.y<pemain.y+pemain.h){
musuhPeluru.splice(i,1); nyawa--; updateHUD();
if(nyawa<=0) gameOver();
}
if(mp.y>H) musuhPeluru.splice(i,1);
});
requestAnimationFrame(loop);
}
function gameOver(){
gameJalan=false;
document.getElementById('btnTembak').style.display='none';
document.getElementById('skorAkhir').innerText="Skor Akhir: "+skor+" | Level: "+level;
document.getElementById('pesanAkhir').innerText = skor>500 ? "Kamu Pahlawan Covid Sejati! 🏆" : "Virus masih kuat, ayo lawan lagi! 💪";
document.getElementById('gameOver').style.display='flex';
}
// Kontrol
let geser=false;
canvas.addEventListener('touchstart', e=>{ geser=true; pindah(e.touches[0].clientX, e.touches[0].clientY); });
canvas.addEventListener('touchmove', e=>{ e.preventDefault(); if(geser) pindah(e.touches[0].clientX, e.touches[0].clientY); });
canvas.addEventListener('touchend', ()=> geser=false);
canvas.addEventListener('mousedown', e=>{ geser=true; pindah(e.clientX,e.clientY); });
canvas.addEventListener('mousemove', e=>{ if(geser) pindah(e.clientX,e.clientY); });
canvas.addEventListener('mouseup', ()=> geser=false);
function pindah(cx,cy){
let r=canvas.getBoundingClientRect();
pemain.x=cx-r.left-30; pemain.y=cy-r.top-30;
if(pemain.x<0) pemain.x=0; if(pemain.x>W-60) pemain.x=W-60;
if(pemain.y<0) pemain.y=0; if(pemain.y>H-60) pemain.y=H-60;
}
let auto;
document.getElementById('btnTembak').addEventListener('touchstart', e=>{ e.preventDefault(); tembak(); auto=setInterval(tembak,180); });
document.getElementById('btnTembak').addEventListener('touchend', ()=> clearInterval(auto));
document.getElementById('btnTembak').addEventListener('mousedown', ()=>{ tembak(); auto=setInterval(tembak,180); });
document.getElementById('btnTembak').addEventListener('mouseup', ()=> clearInterval(auto));
</script>
</body>
</html>
Tidak ada komentar:
Posting Komentar