xxxxxxxxxx
let oyunZamani; // Oyun kontrol
let spd, score, xCub; //oyun hızı
let agacImg; // salatalık resim
let grinchImg; //igne resim
let karTanesiImg; // Top için resim
let lambaImg; // Böcek için resim
let noelBabaImg; // Fare için resim
let patikImg; // Portal için resim
let backgroundImg, cubImg, gameOverImg;
let items = [];
function setup() {
createCanvas(1350, 600);
spd = 1;
score = 0;
xCub = 500;
oyunZamani = true;
}
function preload() {
agacImg = loadImage("tree.png");
grinchImg = loadImage("grinch.png");
noelBabaImg = loadImage("head.png");
patikImg = loadImage("socks.png");
backgroundImg = loadImage("back.png");
cubImg = loadImage("bag.png");
gameOverImg = loadImage("gameOver.jpeg");
}
function draw() {
if (oyunZamani === true) {
push();
background(backgroundImg);
fill("blue");
textSize(25);
text("Score:", 1200, 40);
text(score, 1310, 40);
if (frameCount % 250 === 0) items.push(new Agac());
if (frameCount % 600 === 0) items.push(new Grinch());
if (frameCount % 350 === 0) items.push(new Head());
if (frameCount % 450 === 0) items.push(new Socks());
for (let i = 0; i < items.length - 1; i++) {
items[i].move();
items[i].show();
// Calculate the distance.
let d = dist(xCub, 575, items[i].x, items[i].y);
if (d < 15 && items[i].h !== 50) {
score++;
} else if (d < 15 && items[i].h === 50) {
oyunZamani = false;
break;
}
if (items[i].offscreen()) {
var idx = items.indexOf(i);
delete items[idx];
}
}
imageMode(CENTER); // Resmin merkezden çizilmesini sağlar
image(cubImg, xCub, 575, 110, 100);
keyControl();
pop();
} else {
background("orange");
image(gameOverImg, 390, 120, 500, 380);
items = [];
}
}
function keyControl() {
if (keyIsPressed === true) {
if (keyCode === LEFT_ARROW) xCub -= 3;
else if (keyCode === RIGHT_ARROW) xCub += 3;
}
}
class Agac {
constructor() {
this.x = Math.floor(Math.random() * 1200);
this.y = 0;
this.w = 45;
this.h = 45;
}
move() {
this.y += spd;
}
show() {
imageMode(CENTER);
image(agacImg, this.x, this.y, this.w, this.h);
}
offscreen() {
return this.y > 600;
}
}
class Grinch {
constructor() {
this.x = Math.floor(Math.random() * 1200);
this.y = 0; // Yukarı, orta, aşağı konumlar
this.w = 45; // genişliği
this.h = 50; // yüksekliği
}
move() {
this.y += spd;
}
show() {
imageMode(CENTER); // Resmin merkezden çizilmesini sağlar
image(grinchImg, this.x, this.y, this.w, this.h);
}
offscreen() {
return this.y > 600;
}
}
class Head {
constructor() {
this.x = Math.floor(Math.random() * 1200);
this.y = 0; // Yukarı, orta, aşağı konumlar
this.w = 45; // genişliği
this.h = 45; // yüksekliği
}
move() {
this.y += spd;
}
show() {
imageMode(CENTER); // Resmin merkezden çizilmesini sağlar
image(noelBabaImg, this.x, this.y, this.w, this.h);
}
offscreen() {
return this.y > 600;
}
}
class Socks {
constructor() {
this.x = Math.floor(Math.random() * 1200);
this.y = 0; // Yukarı, orta, aşağı konumlar
this.w = 45; // genişliği
this.h = 45; // yüksekliği
}
move() {
this.y += spd;
}
show() {
imageMode(CENTER); // Resmin merkezden çizilmesini sağlar
image(patikImg, this.x, this.y, this.w, this.h);
}
offscreen() {
return this.y > 600;
}
}