From 838b660f8c41b740f280a32a2644b2c838ac0354 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Sun, 7 Jan 2024 14:13:45 +0100 Subject: [PATCH 01/12] Print out sql on php page in order of scores --- server/getData.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 server/getData.php diff --git a/server/getData.php b/server/getData.php new file mode 100644 index 0000000..4aa998e --- /dev/null +++ b/server/getData.php @@ -0,0 +1,22 @@ +connect_error) { die("Connection failed: " . $conn->connect_error); } +echo "Connected successfully"; + + + $sql = "SELECT * FROM Scores ORDER BY Score DESC LIMIT 10"; + $result = $conn->query($sql); + +if ($result->num_rows > 0) { + // output data of each row + while($row = $result->fetch_assoc()) { + echo "Name: " . $row["Naam"]. " -Score:" . $row["Score"]. "-Datum:" . $row["Datum"]. "
"; + } + // $myJson = json_encode($result); + // echo $myJson; +} \ No newline at end of file From e9f1d8b286ef8a136b9adc124561365034a6fd3a Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Sun, 7 Jan 2024 14:13:54 +0100 Subject: [PATCH 02/12] Added sources --- docs/documentatie/sql.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/documentatie/sql.md b/docs/documentatie/sql.md index 334862b..2d3a6b2 100644 --- a/docs/documentatie/sql.md +++ b/docs/documentatie/sql.md @@ -56,4 +56,8 @@ echo "Text"; En je kan meerdere dingen in een echo zetten doormiddel van een punt ```php echo "Text" . $variabele . "Text"; -``` \ No newline at end of file +``` +--- +### Bronnen: +* https://www.w3schools.com/php/php_mysql_select.asp Voor data opvragen uit database +* https://www.w3schools.com/js/js_json_php.asp Voor data omzetten in json in php \ No newline at end of file From b803280f833bb14c434bfec97f48a8837a08b7ef Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Sun, 7 Jan 2024 14:22:58 +0100 Subject: [PATCH 03/12] Post requested data into a json --- server/getData.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/server/getData.php b/server/getData.php index 4aa998e..8e65e1f 100644 --- a/server/getData.php +++ b/server/getData.php @@ -1,22 +1,26 @@ -connect_error) { die("Connection failed: " . $conn->connect_error); } -echo "Connected successfully"; - - - $sql = "SELECT * FROM Scores ORDER BY Score DESC LIMIT 10"; - $result = $conn->query($sql); +if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); +} +//echo "Connected successfully"; +$sql = "SELECT * FROM Scores ORDER BY Score DESC LIMIT 10"; +$result = $conn->query($sql); if ($result->num_rows > 0) { - // output data of each row - while($row = $result->fetch_assoc()) { - echo "Name: " . $row["Naam"]. " -Score:" . $row["Score"]. "-Datum:" . $row["Datum"]. "
"; + // output data of each row and put them into a json array + while ($row = $result->fetch_assoc()) { + //echo "Name: " . $row["Naam"]. " -Score:" . $row["Score"]. "-Datum:" . $row["Datum"]. "
"; + $data[] = $row; + $json = json_encode($data); } - // $myJson = json_encode($result); - // echo $myJson; -} \ No newline at end of file +} else { + echo "0 results"; +} +echo $json; + From e97a8e2bf7c3725801e2ceb4fe2d753d1ab23f44 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Sun, 7 Jan 2024 14:28:49 +0100 Subject: [PATCH 04/12] code conventions --- web/game.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/web/game.js b/web/game.js index b9f3aaa..4dd03b5 100644 --- a/web/game.js +++ b/web/game.js @@ -218,7 +218,7 @@ async function keyPressed() { function submit() { if (entered == true) { - Senddata(nameHS, int(time)); + sendData(nameHS, int(time)); console.log(nameHS + ": " + int(time)); nameHS = ''; submitted = true; @@ -675,7 +675,7 @@ function game() { } -function Senddata(naam, score) { +function sendData(naam, score) { const request = ( url, params = {}) => { url += '?' + ( new URLSearchParams( params ) ).toString(); fetch( url ); @@ -684,4 +684,8 @@ function Senddata(naam, score) { get('https://oege.ie.hva.nl/~hossan/postData.php', { name: naam, score: score } ); +} + +function getData(){ + } \ No newline at end of file From 1a707650bd21931b035d6aa646ab9331d09b316b Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Sun, 7 Jan 2024 15:06:49 +0100 Subject: [PATCH 05/12] func toegevoegd data ontvangen van webserver en omzetten in array --- web/game.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/game.js b/web/game.js index 4dd03b5..3aa7f02 100644 --- a/web/game.js +++ b/web/game.js @@ -687,5 +687,9 @@ 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') + .then(response => response.json()) + .then(data=>{ console.log(data); }) +} -} \ No newline at end of file From b012d098d8ebedd4b079c6cfdd82f66320f39e1b Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Sun, 7 Jan 2024 15:06:55 +0100 Subject: [PATCH 06/12] added sources --- docs/documentatie/sql.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/documentatie/sql.md b/docs/documentatie/sql.md index 2d3a6b2..344f700 100644 --- a/docs/documentatie/sql.md +++ b/docs/documentatie/sql.md @@ -60,4 +60,6 @@ echo "Text" . $variabele . "Text"; --- ### Bronnen: * https://www.w3schools.com/php/php_mysql_select.asp Voor data opvragen uit database -* https://www.w3schools.com/js/js_json_php.asp Voor data omzetten in json in php \ No newline at end of file +* https://www.w3schools.com/js/js_json_php.asp Voor data omzetten in json in php +* https://www.w3schools.com/php/php_json.asp Voor data omzetten in json in php +* https://stackoverflow.com/questions/43903767/read-the-body-of-a-fetch-promise Opgehaalde data in een json array zetten in javascript \ No newline at end of file From caa5a3d34ff654f84035c9c7f2fd7b4894012e49 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Sun, 7 Jan 2024 16:34:08 +0100 Subject: [PATCH 07/12] Added source --- docs/documentatie/sql.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/documentatie/sql.md b/docs/documentatie/sql.md index 344f700..c1da295 100644 --- a/docs/documentatie/sql.md +++ b/docs/documentatie/sql.md @@ -62,4 +62,5 @@ echo "Text" . $variabele . "Text"; * https://www.w3schools.com/php/php_mysql_select.asp Voor data opvragen uit database * https://www.w3schools.com/js/js_json_php.asp Voor data omzetten in json in php * https://www.w3schools.com/php/php_json.asp Voor data omzetten in json in php -* https://stackoverflow.com/questions/43903767/read-the-body-of-a-fetch-promise Opgehaalde data in een json array zetten in javascript \ No newline at end of file +* https://stackoverflow.com/questions/43903767/read-the-body-of-a-fetch-promise Opgehaalde data in een json array zetten in javascript +* https://css-tricks.com/using-fetch/ voor documenteren \ No newline at end of file From 02f731f2ba9e41a0a7ee52e1b21ee3ca6768cdac Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 8 Jan 2024 13:35:39 +0100 Subject: [PATCH 08/12] fixed submitted score --- web/game.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/game.js b/web/game.js index 3aa7f02..bacc22b 100644 --- a/web/game.js +++ b/web/game.js @@ -178,6 +178,7 @@ async function keyPressed() { nameHS += letters[currentIndex[1]]; nameHS += letters[currentIndex[2]]; entered = true; + submit(); keyReleasedFlag = false; } } @@ -197,7 +198,6 @@ async function keyPressed() { keyReleasedFlag = false; } if (keyCode == ENTER) { - submit(); keyReleasedFlag = false; } } @@ -221,7 +221,7 @@ function submit() { sendData(nameHS, int(time)); console.log(nameHS + ": " + int(time)); nameHS = ''; - submitted = true; + submitted = true;0 } } From e2b0ee682522b7301143e7155edfd8cc544f6282 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 8 Jan 2024 13:36:35 +0100 Subject: [PATCH 09/12] skip creation. fully functional keyboard script for esp32 --- .../keyboard esp32s3/controllerkeyboard.ino | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 arduino/keyboard esp32s3/controllerkeyboard.ino diff --git a/arduino/keyboard esp32s3/controllerkeyboard.ino b/arduino/keyboard esp32s3/controllerkeyboard.ino new file mode 100644 index 0000000..2dd68d7 --- /dev/null +++ b/arduino/keyboard esp32s3/controllerkeyboard.ino @@ -0,0 +1,84 @@ +#include "USB.h" +#include "USBHIDKeyboard.h" +USBHIDKeyboard Keyboard; + +const int buttonPinUp = 9; // the number of the pushbutton pin +const int buttonPinRight = 10; // the number of the pushbutton pin +const int buttonPinDown = 11; // the number of the pushbutton pin +const int buttonPinLeft = 12; // the number of the pushbutton pin +const int buttonPinDodge = 14; +const int buttonPinPause = 13; + +int buttonStateUp = 0; +int buttonStateRight = 0; +int buttonStateDown = 0; +int buttonStateLeft = 0; +int buttonStateDodge = 0; +int buttonStatePause = 0; + +bool boolUp = false; +bool boolRight = false; +bool boolDown = false; +bool boolLeft = false; +bool boolDodge = false; +bool boolPause = false; + +void setup() { + // put your setup code here, to run once: + pinMode(buttonPinUp, INPUT); + pinMode(buttonPinRight, INPUT); + pinMode(buttonPinDown, INPUT); + pinMode(buttonPinLeft, INPUT); + pinMode(buttonPinDodge, INPUT); + pinMode(buttonPinPause, INPUT); + Keyboard.begin(); + USB.begin(); + Serial.begin(9600); +} + +void loop() { + // put your main code here, to run repeatedly: + buttonStateUp = digitalRead(buttonPinUp); + buttonStateRight = digitalRead(buttonPinRight); + buttonStateDown = digitalRead(buttonPinDown); + buttonStateLeft = digitalRead(buttonPinLeft); + buttonStateDodge = digitalRead(buttonPinDodge); + buttonStatePause = digitalRead(buttonPinPause); + + if (buttonStateUp == HIGH) { + Keyboard.press(KEY_UP_ARROW); + } + else{ + Keyboard.release(KEY_UP_ARROW); + } + if (buttonStateRight == HIGH) { + Keyboard.press(KEY_RIGHT_ARROW); + } + else{ + Keyboard.release(KEY_RIGHT_ARROW); + } + if (buttonStateDown == HIGH) { + Keyboard.press(KEY_DOWN_ARROW); + } + else{ + Keyboard.release(KEY_DOWN_ARROW); + } + if (buttonStateLeft == HIGH) { + Keyboard.press(KEY_LEFT_ARROW); + } + else{ + Keyboard.release(KEY_LEFT_ARROW); + } + if (buttonStateDodge == HIGH) { + Keyboard.press(KEY_RETURN); + } + else{ + Keyboard.release(KEY_RETURN); + } + if (buttonStatePause == HIGH) { + Keyboard.press('p'); + } + else{ + Keyboard.release('p'); + } +} From c80e698619ac79f8368b2018a5079fd930e65d3e Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 8 Jan 2024 13:37:05 +0100 Subject: [PATCH 10/12] disabled unused scripts --- web/index.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/web/index.html b/web/index.html index 438fd4d..59ae5bd 100644 --- a/web/index.html +++ b/web/index.html @@ -8,9 +8,7 @@ - - From fbd65b6355f0acd20ffc5207cf6384b60d3f697e Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 8 Jan 2024 13:38:20 +0100 Subject: [PATCH 11/12] Fix typo in game.js --- web/game.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/game.js b/web/game.js index bacc22b..9f2bef4 100644 --- a/web/game.js +++ b/web/game.js @@ -221,7 +221,7 @@ function submit() { sendData(nameHS, int(time)); console.log(nameHS + ": " + int(time)); nameHS = ''; - submitted = true;0 + submitted = true; } } From b944d047ff8633b8a0e97c33a3d436263d06cf12 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 8 Jan 2024 14:32:44 +0100 Subject: [PATCH 12/12] Added player highscores --- web/game.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/web/game.js b/web/game.js index 9f2bef4..4782f9f 100644 --- a/web/game.js +++ b/web/game.js @@ -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; + }); } -