xxxxxxxxxx
let oyunZamani; // Oyuncunun kontrol ettiği top
let obstacles = []; // Engelleri tutacak dizi
let speed = 2; // Engellerin hareket hızı
let stage = 0; // Oyun aşaması (1: Böcekler, 2: Fareler)
let salataImg; // salatalık resim
let igneImg; //igne resim
let ballImg; // Top için resim
let bugImg; // Böcek için resim
let ratImg; // Fare için resim
let portalImg; // Portal için resim
let bckgrdImg1, bckgrdImg2, gameOverImg;
let spd, xRicky, yRicky;
function preload() {
rickyImg = loadImage("Ricky.png"); // Böceğin resmi
bugImg = loadImage("bocek.png");
ratImg = loadImage("fare.png");
salataImg = loadImage("salatalik.png"); // salata resmi
igneImg = loadImage("igne.png");
bckgrdImg1 = loadImage("5.png");
bckgrdImg2 = loadImage("6.png");
portalImg = loadImage("portal.png");
gameOverImg = loadImage("gameover.png");
}
function setup() {
createCanvas(1350, 590);
spd = 0;
xRicky = 20;
yRicky = 150;
oyunZamani = true;
}
function draw() {
if (oyunZamani === true) {
background(bckgrdImg1);
if (spd < 320 && stage === 0) {
image(salataImg, 250, 320, 350, 300);
image(igneImg, 250, -50 + spd, 350, 250);
spd++;
if (spd === 320) stage = 1;
}else if (stage === 1) {
push();
fill(255);
textSize(25);
text("Level 1", 650, 25);
// Engelleri yönet
if (frameCount % 60 === 0) obstacles.push(new Bug());
// Portal ekleme şansı (nadir)
if (random(1) < 0.002) obstacles.push(new Portal());
for (let i = 0; i < obstacles.length - 1; i++) {
obstacles[i].move();
obstacles[i].show();
// Calculate the distance.
let d = dist(xRicky, yRicky, obstacles[i].x, obstacles[i].y);
if (obstacles[i].offscreen()) {
var idx = obstacles.indexOf(i);
delete obstacles[idx];
//console.log(obstacles.length);
}
if (d < 15 && obstacles[i].h === 50) {
oyunZamani = false;
break;
} else if (d < 25 && obstacles[i].h === 100) {
stage = 2;
obstacles = [];
}
}
imageMode(CENTER); // Resmin merkezden çizilmesini sağlar
image(rickyImg, xRicky, yRicky, 400, 320);
keyControl();
//console.log(mouseX, mouseY);
pop();
} else if (stage === 2) {
background(bckgrdImg2);
push();
fill(255);
textSize(25);
text("Level 2", 650, 25);
// Engelleri yönet
if (frameCount % 60 === 0) obstacles.push(new Rat());
for (let i = 0; i < obstacles.length - 1; i++) {
obstacles[i].move();
obstacles[i].show();
// Calculate the distance.
let d = dist(xRicky, yRicky, obstacles[i].x, obstacles[i].y);
if (d < 15 && obstacles[i].h === 50) {
oyunZamani = false;
break;
}
if (obstacles[i].offscreen()) {
var idx = obstacles.indexOf(i);
delete obstacles[idx];
//console.log(obstacles.length);
}
}
imageMode(CENTER); // Resmin merkezden çizilmesini sağlar
image(rickyImg, xRicky, yRicky, 400, 320);
keyControl();
pop();
}
} else {
background("green");
image(gameOverImg, 390, 120, 500, 380);
obstacles = [];
}
}//end of draw
function keyControl() {
if (keyIsPressed === true) {
if (keyCode === UP_ARROW) yRicky -= 1;
else if (keyCode === DOWN_ARROW) yRicky += 1;
else if (keyCode === RIGHT_ARROW) xRicky += 1;
}
}
// Böcek Sınıfı
class Bug {
constructor() {
this.x = width;
this.y = random([height / 4, height / 2, (3 * height) / 4]); // Yukarı, orta, aşağı konumlar
this.w = 70; // Böceğin genişliği
this.h = 50; // Böceğin yüksekliği
}
move() {
this.x -= speed;
}
show() {
imageMode(CENTER); // Resmin merkezden çizilmesini sağlar
image(bugImg, this.x, this.y, this.w, this.h);
}
offscreen() {
return this.x < 0;
}
} // end of Bug
// Fare Sınıfı
class Rat {
constructor() {
this.x = width;
this.y = random([height / 4, height / 2, (3 * height) / 4]); // Yukarı, orta, aşağı konumlar
this.w = 70; // Fare genişliği
this.h = 50; // Fare yüksekliği
}
move() {
this.x -= speed;
}
show() {
imageMode(CENTER); // Resmin merkezden çizilmesini sağlar
image(ratImg, this.x, this.y, this.w, this.h);
}
offscreen() {
return this.x < 0;
}
}
// Portal Sınıfı
class Portal {
constructor() {
this.x = width;
this.y = random([height / 3, height / 4, (2 * height) / 4]); // Yukarı, orta, aşağı konumlar
this.w = 120; // Böceğin genişliği
this.h = 100; // Böceğin yüksekliği
}
move() {
this.x -= speed - 1;
}
show() {
imageMode(CENTER); // Resmin merkezden çizilmesini sağlar
image(portalImg, this.x, this.y, this.w, this.h);
}
offscreen() {
return this.x < 0;
}
} //end of Portal