Skip to content

Commit

Permalink
Created a new screen where the player can adjust the blinking sensiti…
Browse files Browse the repository at this point in the history
…vity.
  • Loading branch information
CorneliusPavlic committed Apr 29, 2024
1 parent ca16eaa commit af79eb2
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 16 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<script src="p5play/planck.min.js"></script>
<script src="p5play/p5play.js"></script>
<script src="src/js/mainPlayer.js"></script>
<script src="src/js/videoCheck.js"></script>
<script src="src/js/menu.js"></script>
<script src="src/js/playing.js"></script>
<script src="src/js/Camera.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const video = document.getElementById('video')
let nowBlinking = false;
let vThreshold = 1.3;

Promise.all([
faceapi.nets.tinyFaceDetector.loadFromUri('./facemodels'),
Expand Down Expand Up @@ -117,7 +118,6 @@ video.addEventListener('play', () => {
return sum + element;
}, 0);
meanIrisC = meanIrisC / irisC.length;
let vThreshold = 1.3;

let currentIrisC = irisC[irisC.length-1];
if(irisC.length==100){
Expand Down
4 changes: 4 additions & 0 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function setup() {

mainMenuBackground.resize(1920,1080);
mainMenu = new MainMenu();
BlinkViewer = new BlinkViewer();

//Makes a pause menu screen
pauseMenu = new PauseMenu();
Expand All @@ -160,6 +161,9 @@ function draw() {
if (GAMESTATE == "MENU") {
menuFunctionality();
}
else if (GAMESTATE === "BLINKVIEW"){
videoCheckFunctionality();
}
else if (GAMESTATE === 'PLAYING') {
clear();
playingFunctionality();
Expand Down
110 changes: 109 additions & 1 deletion src/js/Screens.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,114 @@ class MainMenu {
this.title.hide();
this.menu.visible = false;
}
/**
* Called when exit is clicked
* Takes you to the main menu
*/
exitGame(CURRENTGAMESTATE) {
this.hideMenu();
CURRENTGAMESTATE = "MENU";
}


/**
* Resumes the game when resume is clicked OR escape is pressed a second time
*/
startBlinkView(CURRENTGAMESTATE) {
this.hideMenu();
CURRENTGAMESTATE = 'BLINKVIEW';

return CURRENTGAMESTATE;
}
}



class BlinkViewer {
/**
* Default constructor, makes a background, resume and exit buttons
*/
constructor() {
this.OKButton = createButton('OK');
this.sensitivitySlider = createSlider(100, 200, 130);
this.title = createButton('BLINK');

//Backdrop to the menu
this.menu = new Sprite(1920/2,1080/2,1920,1080);
this.menu.layer = MAIN_MENU_LAYER;
this.menu.opacity = 1;
this.menu.color = 'black';
this.menu.collider = 'none';

this.title.class("H1");
this.title.attribute('name', 'title');
this.title.position(600,50);
this.title.hide();

//Setting up the start button
this.sensitivitySlider.class("MainMenuButtons");
this.sensitivitySlider.attribute("name", "start");
this.sensitivitySlider.position(window.outerWidth/2, 1000)
this.sensitivitySlider.hide(); //Hides the button until pause menu is triggered

// Setup exit Button
this.OKButton.class("MainMenuButtons");
this.OKButton.attribute("name", "exit");
this.OKButton.position(window.outerWidth/2 + 300,1000)
this.OKButton.hide(); //Hides the button until pause menu is triggered

}

/**
* Shows the menu and buttons
*
* @param {*} CURRENTGAMESTATE
*/
showMenu() {
var element = document.querySelectorAll('[id=irrelevantCanvas]');
var video = document.getElementById("video");
element.forEach(element => {
element.style.height = "70vh";
element.style.width = "70vw";
element.style.top = "15vh";
element.style.left = "15vw";
element.style.backgroundColor = "transparent";
});
video.style.height = "70vh";
video.style.width = "70vw";
video.style.top = "15vh";
video.style.left = "15vw";

this.menu.visible = true;
this.OKButton.show();
this.sensitivitySlider.show();
this.title.show();
}

/**
* Hides the menu
*
*/
hideMenu() {
var element = document.querySelectorAll('[id=irrelevantCanvas]');
var video = document.getElementById("video");
element.forEach(element => {
element.style.height = "1px";
element.style.width = "1px";
element.style.top = "1px";
element.style.left = "1px";
element.style.backgroundColor = "black";
});
video.style.height = "1px";
video.style.width = "1px";
video.style.top = "1px";
video.style.left = "1px";

this.OKButton.hide();
this.sensitivitySlider.hide();
this.title.hide();
this.menu.visible = false;
}


/**
Expand All @@ -332,7 +440,7 @@ class MainMenu {
*/
exitGame(CURRENTGAMESTATE) {
this.hideMenu();
CURRENTGAMESTATE = "MENU";
CURRENTGAMESTATE = "BLINKVIEW";
}


Expand Down
16 changes: 2 additions & 14 deletions src/js/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,8 @@ function menuFunctionality(){
mainMenu.showMenu();

mainMenu.startButton.mousePressed(() => {
player.visible = true;
healthBar.visible = true;
moveCamera("right",SPAWNX);
moveCamera("down",SPAWNY);
var coords=gameMap.getRoomWorldCoords(SPAWNX,SPAWNY);
player.x=coords.x+600;
player.y=coords.y+600;
player.room["x"]=SPAWNX;
player.room["y"]=SPAWNY;
fadeScreen.x = player.x;
fadeScreen.y = player.y;
gameMap.loadRoom(SPAWNX,SPAWNY);
mainMenuSound.pause();
GAMESTATE = mainMenu.startGame(GAMESTATE);
GAMESTATE = mainMenu.startBlinkView(GAMESTATE);
});

mainMenu.exitButton.mousePressed(() => {
Expand All @@ -34,6 +22,6 @@ function menuFunctionality(){

if(kb.pressed('l')){

GAMESTATE = mainMenu.startGame(GAMESTATE);
GAMESTATE = mainMenu.startBlinkView(GAMESTATE);
}
}
24 changes: 24 additions & 0 deletions src/js/videoCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function videoCheckFunctionality(){
BlinkViewer.showMenu();
vThreshold = BlinkViewer.sensitivitySlider.value() / 100;

BlinkViewer.OKButton.mousePressed(() => {
player.visible = true;
healthBar.visible = true;
moveCamera("right",SPAWNX);
moveCamera("down",SPAWNY);
var coords=gameMap.getRoomWorldCoords(SPAWNX,SPAWNY);
player.x=coords.x+600;
player.y=coords.y+600;
player.room["x"]=SPAWNX;
player.room["y"]=SPAWNY;
fadeScreen.x = player.x;
fadeScreen.y = player.y;
gameMap.loadRoom(SPAWNX,SPAWNY);
GAMESTATE = BlinkViewer.startGame(GAMESTATE);
});

if(kb.pressed('l')){
GAMESTATE = BlinkViewer.startGame(GAMESTATE);
}
}

0 comments on commit af79eb2

Please sign in to comment.