Added player highscores

This commit is contained in:
Sam
2024-01-08 14:32:44 +01:00
parent fbd65b6355
commit b944d047ff

View File

@@ -2,7 +2,7 @@
// Game variables
const width = 1260;
const height = 620;
let requesteddata = [];
// Menu variables
let letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
let currentIndex = [0, 0, 0];
@@ -31,7 +31,6 @@ let shotPosY;
let initialPlayerPosX = playerPosX;
let initialPlayerPosY = playerPosY;
let bullets = [];
let direction;
let framerate = 120;
@@ -71,7 +70,7 @@ let phases = [false, false, false, false, false];
// the function setup() is called once when the page is loaded
function setup() {
// create a canvas element and append it to the body
getData()
createCanvas(width, height);
frameRate(framerate);
angleMode(DEGREES);
@@ -558,13 +557,25 @@ function homescreen() {
fill(0, 255, 0, 0)
rect(100, 150, 300, 400)
pop()
//highscores rectangle
push()
textSize(50)
fill(255, 255, 255)
text("Highscores", 250, 200)
pop()
push()
fill(255, 255, 255)
textSize(25)
textAlign(CENTER)
// if (requesteddata.length > 0) {
// text("1. " + requesteddata[0].Naam + ": " + requesteddata[0].Score, 250, 250)
// }
for (let i = 0; i < requesteddata.length; i++) {
text(i + 1 + ". " + requesteddata[i].Naam + ": " + requesteddata[i].Score, 250, 250 + (i * 30))
}
pop()
push()
stroke(255, 255, 255)
strokeWeight(5)
@@ -687,9 +698,10 @@ function sendData(naam, score) {
}
function getData(){
//haalt data op van de database en plaatst die in een array en print het uit in de console
fetch ('https://oege.ie.hva.nl/~hossan/getData.php')
// Fetch data from the database, put it in an array, and log it to the console
return fetch ('https://oege.ie.hva.nl/~hossan/getData.php') // Add return here
.then(response => response.json())
.then(data=>{ console.log(data); })
.then(data => {
requesteddata = data;
});
}