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