xxxxxxxxxx
var sceneId = 0; // 0: intro scene, 1: selection scene, 2: pet scene
var buttonIntrovert;
var buttonExtravert;
var buttonIndoor;
var buttonOutdoor;
var buttonDay;
var buttonNight;
var buttonSummer;
var buttonWinter;
var nameField;
var button;
var buttonNotfy;
var catImages = [];
var catId = 0;
var col1X;
var col2X;
var yStart;
// Veritabanı (database) tanımı
var database = [
{imageSrc: "cat.jpg",
name: "Milo",
breed: "Siamese",
location: "Atasehir Shelter",
age: "14 months",
// Path to image
},
{
imageSrc: "cat4.jpg",
name: "Bella",
breed: "Persian",
location: "Moda Shelter",
age: "8 months",
},
{
imageSrc: "cat6.jpg",
name: "Manti",
breed: "Calico",
location: "Tuzla Shelter",
age: "9 months",
}
// Daha fazla kedi ekleyebilirsiniz
];
function preload() {
img = loadImage('introvert.png');
img1 = loadImage('extrovert.png');
img2 = loadImage('indoor.png');
img3 = loadImage('outdoor.png');
img4 = loadImage('day.png');
img5 = loadImage('night.png');
img6 = loadImage('summer.png');
img7 = loadImage('winter.png');
da = loadImage('da.jpg');
rejectIcon = loadImage('selectionpage.png');
homeIcon = loadImage('matchsuccessful.png');
refreshIcon = loadImage('newcat.png');
// Veritabanındaki kedilerin resimlerini yükle
for (var i = 0; i < database.length; i++) {
catImages[i] = loadImage(database[i].imageSrc);
}
}
function setup() {
createCanvas(350, 600);
background(200);
col1X = 30;
col2X = 255;
yStart = 90;
// Scene 1 elementlerini gizle
function hideScene1() {
buttonIntrovert.hide();
buttonExtravert.hide();
buttonIndoor.hide();
buttonOutdoor.hide();
buttonDay.hide();
buttonNight.hide();
buttonSummer.hide();
buttonWinter.hide();
nameField.hide();
button.hide();
}
// Scene 1 butonları
buttonIntrovert = createButton('introvert');
buttonIntrovert.position(col1X, yStart);
buttonExtravert = createButton('extrovert');
buttonExtravert.position(col2X, yStart);
buttonIndoor = createButton('indoor');
buttonIndoor.position(col1X, yStart + 70);
buttonOutdoor = createButton('outdoor');
buttonOutdoor.position(col2X, yStart + 70);
buttonDay = createButton('day');
buttonDay.position(col1X, yStart + 140);
buttonNight = createButton('night');
buttonNight.position(col2X, yStart + 140);
buttonWinter = createButton('winter');
buttonWinter.position(col1X, yStart + 210);
buttonSummer = createButton('summer');
buttonSummer.position(col2X, yStart + 210);
nameField = createInput('');
nameField.attribute('placeholder', 'your name');
nameField.position(col1X, 400);
nameField.size(100);
button = createButton('Find a match');
button.style("background", "red");
button.position(col2X - 30, 450);
button.mousePressed(matchButtonPressed);
hideScene1();
// Scene 2
buttonNotfy = createButton("New Match");
buttonNotfy.size(200, 70);
buttonNotfy.position(width / 2 - buttonNotfy.width / 2, height / 2 - buttonNotfy.height / 2);
buttonNotfy.mousePressed(buttonNotfyPressed);
function showScene1() {
buttonIntrovert.show();
buttonExtravert.show();
buttonIndoor.show();
buttonOutdoor.show();
buttonDay.show();
buttonNight.show();
buttonSummer.show();
buttonWinter.show();
nameField.show();
button.show();
}
function buttonNotfyPressed() {
sceneId = 1;
buttonNotfy.hide();
showScene1();
}
function matchButtonPressed() {
sceneId = 2;
hideScene1();
}
}
function draw() {
background(220);
// Scene 1 elementlerini çiz
if (sceneId == 0) {
image(da, 0, 0);
}
if (mouseIsPressed && mouseX > 150 && mouseX < 250 && mouseY > 490 && mouseY < 530) {
let matchedCat = findMatchingCat(); // Eşleşen kediyi bul
if (matchedCat !== -1) {
currentCat = matchedCat; // Eşleşen kediyi ayarla
sceneId = 2; // Kedi eşleşmesi sahnesine geç
buttons.forEach((button) => button.hide());
} else {
alert("No matching cat found!"); // Eşleşme bulunamazsa uyarı
}
}
// Scene 2 elementlerini çiz
else if (sceneId == 1) {
buttonIntrovert.show();
buttonExtravert.show();
buttonIndoor.show();
buttonOutdoor.show();
buttonDay.show();
buttonNight.show();
buttonSummer.show();
buttonWinter.show();
nameField.show();
button.show();
image(img, col1X + 60, yStart);
image(img1, col2X - 30, yStart);
image(img2, col1X + 60, yStart + 70);
image(img3, col2X - 30, yStart + 70);
image(img4, col1X + 60, yStart + 140);
image(img5, col2X - 30, yStart + 140);
image(img6, col2X - 30, yStart + 210);
image(img7, col1X + 60, yStart + 210);
let name = nameField.value()
if (name) {
textSize(14)
text("welcome " + name + ",", 145, 410)
text("ready to meet your companion?", 145, 420)
}
fill(50);
textSize(20);
text("Select Your Preferences", 60, 50);
}
// Scene 3 elementlerini çiz
else if (sceneId == 2) {
drawActionButtons();
strokeWeight(8);
rect(31, 79, 290, 290);
textSize(30);
textStyle(BOLD);
image(catImages[catId], 33, 80);
text(database[catId].name, 36, 400);
textSize(15);
textStyle(NORMAL);
text(database[catId].location, 200, 400);
text(database[catId].breed, 36, 430);
text(database[catId].age, 36, 450);
}
}
let buttonClicked = false; // Tıklama durumu kontrolü
function drawActionButtons() {
// X (Reddet) Butonu
if (rejectIcon) {
image(rejectIcon, 70, 520, 40, 40); // X ikonunu çiz
if (isMouseInside(70, 150, 520, 560) && !buttonClicked) { // Tıklama kontrolü
buttonClicked = true; // Tıklama yapılmış
sceneId = 1;
}
}
// Kalp Butonu
if (homeIcon) {
image(homeIcon, 150, 520, 40, 40); // Kalp ikonunu çiz
if (isMouseInside(150, 225, 520, 560) && !buttonClicked) { // Tıklama kontrolü
buttonClicked = true; // Tıklama yapılmış
window.alert('Congrats, you found your new match <3'); // mesaj göster
}
}
// Yenile Butonu
if (refreshIcon) {
image(refreshIcon, 230, 520, 40, 40); // Yenile ikonunu çiz
if (isMouseInside(230, 300, 520, 560) && !buttonClicked) { // Tıklama kontrolü
buttonClicked = true; // Tıklama yapılmış
currentCat = floor(random(database.length)); // Rastgele bir kedi seç
catId = currentCat; // currentCat güncelleniyor
}
}
}
// Mouse'ın butonun içinde olup olmadığını kontrol eden fonksiyon
function isMouseInside(x1, x2, y1, y2) {
return mouseX > x1 && mouseX < x2 && mouseY > y1 && mouseY < y2;
}
// Yeniden buton tıklamalarını etkinleştirmek için
function mouseReleased() {
buttonClicked = false; // Fare bırakıldığında tıklama durumu sıfırlanır
}