Untitled
Anonymous
plain_text
02/21/2026 3:28 PM
9.9 KB
8
Indexable
<!DOCTYPE html>
<html>
<head>
<title>Game Câu Cá của Ní</title>
<style>
body { margin: 0; overflow: hidden; background: skyblue; touch-action: none; }
#hook { width: 10px; height: 50px; background: black; position: absolute; left: 50%; top: 0; }
#fish { width: 50px; height: 30px; background: orange; position: absolute; bottom: 100px; border-radius: 50%; }
</style>
</head>
<body onclick="dropHook()">
<div id="hook"></div>
<div id="fish"></div>
<script>
let hook = document.getElementById('hook');
let fish = document.getElementById('fish');
let hookY = 0;
let dropping = false;
let fishX = 0;
// Cá bơi qua bơi lại
setInterval(() => {
fishX += 2;
if (fishX > window.innerWidth) fishX = -50;
fish.style.left = fishX + 'px';
}, 20;
function dropHook() {
if (!dropping) dropping = true;
}
// Vòng lặp game
setInterval(() => {
if (dropping) {
hookY += 5;
if (hookY > window.innerHeight - 150) dropping = false;
} else if (hookY > 0) {
hookY -= 5;
}
hook.style.height = hookY + 50 + 'px';
// Kiểm tra va chạm (Câu trúng cá)
let hRect = hook.getBoundingClientRect();
let fRect = fish.getBoundingClientRect();
if (!(hRect.right < fRect.left || hRect.left > fRect.right || hRect.bottom < fRect.top || hRect.top > fRect.bottom)) {
alert("Dính cá rồi ní ơi!");
hookY = 0;
dropping = false;
}
}, 20);
</script>
</body>
</html>
}
}
}
})
}
})Editor is loading...
Leave a Comment