xxxxxxxxxx
let gameStarted = false;
let score = 0; // Puan
let rainNotes = [];
let F5;
let C6;
let C4;
let F4;
let A4;
let E4;
let D4;
let B4;
let G4;
let A5;
let E5;
let C5;
let D5;
let B5;
let G5;
let notes = ["C4", "D4", "E4", "F4", "G4", "A4", "B4", "C5", "D5", "E5", "F5", "G5", "A5", "B5", "C6"]; // Nota isimleri
let notePositions = { // Notaların doğru yerleri (y ekseni)
"C4": 200, // oldu
"D4": 195, // oldu
"E4": 190, // oldu
"F4": 185, // oldu
"G4": 180, // oldu
"A4": 175, // oldu
"B4": 170, // oldu
"C5": 165, // oldu
"D5": 160, // oldu
"E5": 155, // oldu
"F5": 150, // oldu
"G5": 145, // oldu
"A5": 140, // oldu
"B5": 135, // oldu
"C6": 130, // oldu
};
let currentNote = ""; // Şu anki nota
let options = []; // Seçenekler
// Timer
let tickTime = 2; // unvisible for 2 seconds
let initTime = 0;
let correctNoteSelected = false;
let feedback = { show: false, correct: false, x: 0, y: 0 };
function preload() {
F5 = loadSound("fa 20.mp3");
C6 = loadSound("C6.mp3");
C4 = loadSound("C4.mp3");
F4 = loadSound("F4.mp3");
A4 = loadSound("A4.mp3");
E4 = loadSound("E4.mp3");
D4 = loadSound("D4.mp3");
B4 = loadSound("B4.mp3");
G4 = loadSound("G4.mp3");
A5 = loadSound("A5.mp3");
E5 = loadSound("E5.mp3");
C5 = loadSound("C5.mp3");
D5 = loadSound("D5.mp3");
B5 = loadSound("B5.mp3");
G5 = loadSound("G5.mp3");
dist_mus = loadFont("dist_mus.ttf");
liberation = loadFont("LiberationSans-Bold.ttf");
}
function setup() {
createCanvas(600, 400);
// Yağmur notalarını oluştur
for (let i = 0; i < 50; i++) { // 50 tane küçük nota
rainNotes.push({
x: random(width), // Rastgele x pozisyonu
y: random(-200, height), // Ekranın üst kısmından rastgele başlangıç
speed: random(1, 3) // Rastgele hız, çok hızlı hareket etmesin
});
}
}
function draw() {
background(255, 182, 193); // Beyaz arka plan
// Yağmur notalarını çiz
drawRainNotes();
if (!gameStarted) {
showStartScreen(); // Başlangıç ekranını
} else {
playGame(); // Oyun ekranını
}
}
function drawRainNotes() {
// Küçük notaların hareket etmesi için her bir nota
for (let i = 0; i < rainNotes.length; i++) {
let rainNote = rainNotes[i];
// Nota sembolünü çiz
textSize(24);
fill(0, 0, 0, 150); // Yavaş hareket eden ve şeffaf notalar
text('\u266A', rainNote.x, rainNote.y);
// Yukarıdan aşağıya hareket etmelerini sağla
rainNote.y += rainNote.speed;
// Eğer notalar ekranın altına geldiyse, tekrar yukarıya yerleştir
if (rainNote.y > height) {
rainNote.y = 0;
rainNote.x = random(width); // Notayı rastgele yeni bir x pozisyonunda yerleştir
}
}
}
function showStartScreen() {
textAlign(CENTER, CENTER);
textSize(50);
textFont(dist_mus);
fill(50);
text("NoteQuest", width / 2, height / 3);
// Buton hover kontrolü
let isHovering = mouseX > width / 2 - 75 && mouseX < width / 2 + 75 &&
mouseY > height / 2 - 25 && mouseY < height / 2 + 25;
// Canlı renkler (Hover ve Normal)
if (isHovering) {
fill(20, 30, 60); // Canlı turuncu (hover rengi)
} else {
fill(135, 206, 250); // Daha açık bir turuncu tonu
}
stroke(0);
strokeWeight(2);
rectMode(CENTER);
rect(width / 2, height / 2, 150, 50, 10); // Yuvarlatılmış köşeler
fill(255); // Yazı rengi (beyaz)
noStroke();
textSize(20);
textFont(liberation);
text("Play", width / 2, height / 2);
}
// Mouse tıklaması işlemleri
function mousePressed() {
// "Oyna" butonuna tıklanırsa
if (!gameStarted && mouseX > width / 2 - 50 && mouseX < width / 2 + 50 && mouseY > height / 2 - 25 && mouseY < height / 2 + 25) {
gameStarted = true;
generateNewNote(); // Yeni bir nota oluştur
}
// Oyun sırasında seçeneklere tıklanırsa
if (gameStarted) {
for (let i = 0; i < options.length; i++) {
if (mouseX > options[i].x && mouseX < options[i].x + 80 && mouseY > options[i].y && mouseY < options[i].y + 30) {
checkAnswer(options[i].label);
}
}
}
}
// Oyun ekranını çiz
function playGame() {
// Puan göstergesi
textSize(25);
fill(0);
text(`Score: ${score}`, 60, 40);
// Porteyi çiz
drawPorte(220, 150);
// Şu anki notayı çiz
drawNoteOnPorte(250, notePositions[currentNote]);
// Seçenekleri yazdır
drawOptions();
if (feedback.show) {
textSize(50);
textFont(cone);
textAlign(CENTER, CENTER);
fill(feedback.correct ? "green" : "red"); // Doğruysa yeşil, yanlışsa kırmızı
text(feedback.correct ? "✓" : "✗", feedback.x, feedback.y);
}
if (correctNoteSelected == true) {
if (millis() - initTime > tickTime * 1000) {
generateNewNote(); // Yeni bir nota oluştur
initTime = millis();
correctNoteSelected = false;
feedback.show = false;
}
}
}
// Yeni bir nota seç ve seçenekleri oluştur
function generateNewNote() {
// Yeni bir rastgele nota seç
currentNote = random(notes);
// Seçenekler oluştur
options = [];
for (let i = 0; i < 5; i++) { // 5 farklı seçenek
let randomNote = random(notes);
options.push({
label: randomNote,
x: 100 + i * 90,
y: 300
});
}
// Doğru cevabı seçeneklerden birine yerleştir
let correctIndex = floor(random(5));
options[correctIndex].label = currentNote;
}
// Cevap kontrolü
function checkAnswer(selectedNote) {
print(selectedNote)
if (selectedNote == "F5") {
if (F5.isPlaying() == false) {
F5.play();
}
}
if (selectedNote == "C6") {
if (C6.isPlaying() == false) {
C6.play();
}
}
if (selectedNote == "C4") {
if (C4.isPlaying() == false) {
C4.play();
}
}
if (selectedNote == "F4") {
if (F4.isPlaying() == false) {
F4.play();
}
}
if (selectedNote == "A4") {
if (A4.isPlaying() == false) {
A4.play();
}
}
if (selectedNote == "E4") {
if (E4.isPlaying() == false) {
E4.play();
}
}
if (selectedNote == "D4") {
if (D4.isPlaying() == false) {
D4.play();
}
}
if (selectedNote == "B4") {
if (B4.isPlaying() == false) {
B4.play();
}
}
if (selectedNote == "G4") {
if (G4.isPlaying() == false) {
G4.play();
}
}
if (selectedNote == "A5") {
if (A5.isPlaying() == false) {
A5.play();
}
}
if (selectedNote == "E5") {
if (E5.isPlaying() == false) {
E5.play();
}
}
if (selectedNote == "C5") {
if (C5.isPlaying() == false) {
C5.play();
}
}
if (selectedNote == "D5") {
if (D5.isPlaying() == false) {
D5.play();
}
}
if (selectedNote == "B5") {
if (B5.isPlaying() == false) {
B5.play();
}
}
if (selectedNote == "G5") {
if (G5.isPlaying() == false) {
G5.play();
}
}
if (selectedNote === currentNote) {
score += 1; // Doğruysa puan artır
initTime = millis(); // returns the how long milliseconds passed since we hit run button.
correctNoteSelected = true;
feedback = { show: true, correct: true, x: mouseX, y: mouseY };
} else {
feedback = { show: true, correct: false, x: mouseX, y: mouseY };
}
}
// Porteyi çiz
function drawPorte(x, y) {
stroke(0);
strokeWeight(1);
// 5 yatay çizgi
for (let i = 0; i < 5; i++) {
line(x, y + i * 10, x + 150, y + i * 10); // Çizgiler kısa
}
// Sol anahtarını çiz
drawClef(x + 10, y - 15);
}
// Sol anahtarını çiz
function drawClef(x, y) {
push();
textSize(80);
textFont(cone);
textAlign(CENTER, CENTER);
text('\uD834\uDD1E', x, y + 35); // Sol anahtarının Unicode karakteri
pop();
}
// Notayı çiz
function drawNoteOnPorte(x, y) {
if (currentNote == "C4") {
fill(0);
stroke(2);
line(x + 40, y, x + 60, y);
noStroke();
ellipse(x + 50, y, 10, 10); // Nota yuvarlağı
}
if (currentNote == "A5") {
fill(0);
stroke(2);
line(x + 40, y, x + 60, y);
noStroke();
ellipse(x + 50, y, 10, 10);
}
if (currentNote == "B5") {
fill(0);
stroke(2);
line(x + 40, y + 5, x + 60, y + 5);
noStroke();
ellipse(x + 50, y, 10, 10);
}
if (currentNote == "C6") {
fill(0);
stroke(2);
line(x + 40, y, x + 60, y);
line(x + 40, y + 7, x + 60, y + 7);
noStroke();
ellipse(x + 50, y, 10, 10);
} else {
fill(0);
noStroke();
ellipse(x + 50, y, 10, 10); // Nota yuvarlağı
}
}
function drawOptions() {
textSize(18);
textAlign(CENTER, CENTER);
for (let i = 0; i < options.length; i++) {
let isHovering = mouseX > options[i].x && mouseX < options[i].x + 80 &&
mouseY > options[i].y && mouseY < options[i].y + 30;
// Hover Rengi
if (isHovering) {
fill(200, 250, 200);
} else {
fill(220);
}
stroke(0);
strokeWeight(1);
rect(options[i].x, options[i].y, 30, 30, 5); // Buton gibi dikdörtgen
fill(0);
noStroke();
text(options[i].label, options[i].x , options[i].y); // Butonun içindeki yazı
}
}