<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mini Agar.io (Botlu)</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #111;
font-family: Arial, sans-serif;
}
canvas {
display: block;
}
#scoreBoard {
position: absolute;
top: 10px;
left: 10px;
color: white;
font-size: 20px;
font-weight: bold;
background: rgba(0, 0, 0, 0.5);
padding: 10px;
border-radius: 5px;
pointer-events: none;
}
#gameOver {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
text-align: center;
background: rgba(0, 0, 0, 0.8);
padding: 30px;
border-radius: 10px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
border-radius: 5px;
background-color: #28a745;
color: white;
font-weight: bold;
}
</style>
</head>
<body>
<div id="scoreBoard">Skor: <span id="score">10</span></div>
<div id="gameOver">
<h1>Kaybettin!</h1>
<p>Botlar seni yuttu.</p>
<button onclick="restartGame()">Yeniden Başla</button>
</div>
<canvas id="gameCanvas"></canvas>
<script>
const canvas = document.getElementById("gameCanvas");
const ctx = canvas.getContext("2d");
// Ekran boyutunu ayarla
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// Oyun Dünyası Boyutları (Ekrandan daha büyük bir harita)
const WORLD_WIDTH = 3000;
const WORLD_HEIGHT = 3000;
let player;
let foods = [];
let bots = [];
let isGameOver = false;
// Fare Pozisyonu
let mouse = { x: canvas.width / 2, y: canvas.height / 2 };
window.addEventListener('mousemove', (e) => {
mouse.x = e.clientX;
mouse.y = e.clientY;
});
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});
// Rastgele Renk Oluşturucu
function getRandomColor() {
const colors = ['#f1c40f', '#e67e22', '#e74c3c', '#3498db', '#9b59b6', '#1abc9c', '#e84393', '#badc58'];
return colors[Math.floor(Math.random() * colors.length)];
}
// Oyunu Başlat/Sıfırla
function init() {
isGameOver = false;
document.getElementById("gameOver").style.display = "none";
// Oyuncu Başlangıcı
player = {
x: WORLD_WIDTH / 2,
y: WORLD_HEIGHT / 2,
radius: 20,
color: '#2ecc71',
speed: 4
};
// Yemleri Oluştur
foods = [];
for (let i = 0; i < 400; i++) {
spawnFood();
}
// Botları Oluştur
bots = [];
for (let i = 0; i < 20; i++) {
spawnBot();
}
}
function spawnFood() {
foods.push({
x: Math.random() * WORLD_WIDTH,
y: Math.random() * WORLD_HEIGHT,
radius: 5,
color: getRandomColor()
});
}
function spawnBot() {
bots.push({
x: Math.random() * WORLD_WIDTH,
y: Math.random() * WORLD_HEIGHT,
radius: Math.random() * 25 + 10, // 10 ile 35 arası rastgele boyut
color: '#e74c3c',
// Rastgele hedef yönü
targetX: Math.random() * WORLD_WIDTH,
targetY: Math.random() * WORLD_HEIGHT,
speed: 3
});
}
// İki nokta arasındaki mesafe (Çarpışma testi için)
function getDistance(x1, y1, x2, y2) {
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}
// Güncelleme Mantığı
function update() {
if (isGameOver) return;
// --- OYUNCU HAREKETİ ---
// Kameranın merkezine göre fare açısını hesapla
let targetX = mouse.x - canvas.width / 2;
let targetY = mouse.y - canvas.height / 2;
let angle = Math.atan2(targetY, targetX);
// Oyuncu büyüdükçe hızı yavaşlar
player.speed = Math.max(1.5, 5 - (player.radius / 100));
// Sadece fare merkezden uzaktaysa hareket et
if (getDistance(mouse.x, mouse.y, canvas.width/2, canvas.height/2) > 10) {
player.x += Math.cos(angle) * player.speed;
player.y += Math.sin(angle) * player.speed;
}
// Sınır kontrolü
player.x = Math.max(player.radius, Math.min(WORLD_WIDTH - player.radius, player.x));
player.y = Math.max(player.radius, Math.min(WORLD_HEIGHT - player.radius, player.y));
// --- BOTLARIN HAREKETİ ---
bots.forEach(bot => {
// Bot hedefe yaklaştıysa yeni hedef seç
if (getDistance(bot.x, bot.y, bot.targetX, bot.targetY) < 20) {
bot.targetX = Math.random() * WORLD_WIDTH;
bot.targetY = Math.random() * WORLD_HEIGHT;
}
// Bota en yakın yemi veya küçük oyuncuyu kovalama yapay zekası eklenebilir,
// şimdilik basitlik adına rastgele hedefe gidiyorlar.
let botAngle = Math.atan2(bot.targetY - bot.y, bot.targetX - bot.x);
bot.speed = Math.max(1, 4.5 - (bot.radius / 100));
bot.x += Math.cos(botAngle) * bot.speed;
bot.y += Math.sin(botAngle) * bot.speed;
bot.x = Math.max(bot.radius, Math.min(WORLD_WIDTH - bot.radius, bot.x));
bot.y = Math.max(bot.radius, Math.min(WORLD_HEIGHT - bot.radius, bot.y));
});
// --- ÇARPIŞMALAR VE YEME MANTIĞI ---
// 1. Oyuncunun Yemleri Yemesi
for (let i = foods.length - 1; i >= 0; i--) {
if (getDistance(player.x, player.y, foods[i].x, foods[i].y) < player.radius) {
foods.splice(i, 1);
player.radius += 0.2; // Büyüme miktarı
spawnFood(); // Yeni yem ekle
}
}
// 2. Botların Yemleri Yemesi
bots.forEach(bot => {
for (let i = foods.length - 1; i >= 0; i--) {
if (getDistance(bot.x, bot.y, foods[i].x, foods[i].y) < bot.radius) {
foods.splice(i, 1);
bot.radius += 0.2;
spawnFood();
}
}
});
// 3. Oyuncu ve Botların Birbirini Yemesi
for (let i = bots.length - 1; i >= 0; i--) {
let bot = bots[i];
let dist = getDistance(player.x, player.y, bot.x, bot.y);
// Oyuncu botu yiyor (%10 daha büyük olmalı kuralı)
if (dist < player.radius && player.radius > bot.radius * 1.1) {
player.radius += bot.radius * 0.3; // Botun kütlesinin bir kısmını al
bots.splice(i, 1);
setTimeout(spawnBot, 3000); // 3 saniye sonra yeni bot doğsun
}
// Bot oyuncuyu yiyor
else if (dist < bot.radius && bot.radius > player.radius * 1.1) {
isGameOver = true;
document.getElementById("gameOver").style.display = "block";
}
}
// Skor tablosunu güncelle (Kütle = yarıçapın yuvarlanmış hali)
document.getElementById("score").innerText = Math.round(player.radius);
}
// Çizim Mantığı
function draw() {
// Ekranı temizle
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Kamera takibi için ekranı oyuncunun merkezine kaydırıyoruz
ctx.save();
ctx.translate(canvas.width / 2 - player.x, canvas.height / 2 - player.y);
// Arka plan kılavuz çizgileri (Grid sistemi)
ctx.strokeStyle = '#222';
ctx.lineWidth = 1;
const gridSize = 50;
for (let x = 0; x < WORLD_WIDTH; x += gridSize) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, WORLD_HEIGHT);
ctx.stroke();
}
for (let y = 0; y < WORLD_HEIGHT; y += gridSize) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(WORLD_WIDTH, y);
ctx.stroke();
}
// Dünya Sınırlarını Çiz
ctx.strokeStyle = '#ff0000';
ctx.lineWidth = 5;
ctx.strokeRect(0, 0, WORLD_WIDTH, WORLD_HEIGHT);
// Yemleri Çiz
foods.forEach(food => {
ctx.beginPath();
ctx.arc(food.x, food.y, food.radius, 0, Math.PI * 2);
ctx.fillStyle = food.color;
ctx.fill();
ctx.closePath();
});
// Botları Çiz
bots.forEach(bot => {
ctx.beginPath();
ctx.arc(bot.x, bot.y, bot.radius, 0, Math.PI * 2);
ctx.fillStyle = bot.color;
ctx.fill();
ctx.closePath();
// Bot boyutu yazısı
ctx.fillStyle = 'white';
ctx.font = '12px Arial';
ctx.textAlign = 'center';
ctx.fillText(Math.round(bot.radius), bot.x, bot.y + 4);
});
// Oyuncuyu Çiz (Eğer ölmediyse)
if (!isGameOver) {
ctx.beginPath();
ctx.arc(player.x, player.y, player.radius, 0, Math.PI * 2);
ctx.fillStyle = player.color;
ctx.fill();
ctx.closePath();
// Oyuncu boyutu yazısı
ctx.fillStyle = 'white';
ctx.font = '14px Arial';
ctx.textAlign = 'center';
ctx.fillText(Math.round(player.radius), player.x, player.y + 5);
}
ctx.restore();
}
// Oyun Döngüsü
function gameLoop() {
update();
draw();
requestAnimationFrame(gameLoop);
}
function restartGame() {
init();
}
// Oyunu başlat
init();
gameLoop();
</script>
</body>
</html>
Selamlar buyrun agar io yapay zeka ile yapıldı geliştirmek size kalmış iyi forumlar