From 18a03a5aff79805fddb293520d073223ed3ddaa8 Mon Sep 17 00:00:00 2001 From: Silas Bartha Date: Sat, 18 Apr 2020 15:38:50 -0400 Subject: [PATCH] Added blood pressure system -bloood --- docs/assets/js/UI/ui.js | 9 ++++++++- docs/assets/js/constants.js | 9 ++++++--- docs/assets/js/player/lifeFunctions.js | 21 +++++++++++++++------ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/docs/assets/js/UI/ui.js b/docs/assets/js/UI/ui.js index 5e51149..f084c82 100644 --- a/docs/assets/js/UI/ui.js +++ b/docs/assets/js/UI/ui.js @@ -80,11 +80,18 @@ function heartBeatUI(x, y, width, height){ //Backdrop rect(x+width/2,y+height/2,width,height,"black"); + //Pressure Meter + rect(x+width-8,y+height/2,16,height,"red"); + rect(x+width-8,y+height/2,16,height/2,"yellow"); + rect(x+width-8,y+height/2,16,height/6,"green"); + let pressureHeight = Math.max(Math.min(y+height-(pressure/constants.lifeFuncs.cardio.optimalPressure*height/2),y+height),y); + line(x+width-16, pressureHeight,x+width,pressureHeight, 2,"black") + //Graph for (let index = 0; index < heartBeatHistory.length; index++) { const qrsValueAtPosition = heartBeatHistory[index]; const qrsValueAtNextPosition = heartBeatHistory[index+1]; - line(x+(index*width/heartBeatHistory.length), y+(2*height/3)+(qrsValueAtPosition*width/heartBeatHistory.length), x+((index+1)*width/heartBeatHistory.length), y+(2*height/3)+(qrsValueAtNextPosition*width/heartBeatHistory.length),Math.min(3,Math.max(3/beatTimeElapsed,1)), "red"); + line(x+(index*(width-16)/heartBeatHistory.length), y+(2*height/3)+(qrsValueAtPosition*(width-16)/heartBeatHistory.length), x+((index+1)*(width-16)/heartBeatHistory.length), y+(2*height/3)+(qrsValueAtNextPosition*(width-16)/heartBeatHistory.length),Math.min(3,Math.max(3/beatTimeElapsed,1)), "red"); } } diff --git a/docs/assets/js/constants.js b/docs/assets/js/constants.js index c4ef125..0adeac7 100644 --- a/docs/assets/js/constants.js +++ b/docs/assets/js/constants.js @@ -35,9 +35,12 @@ var constants = { } }, lifeFuncs:{ - breath:{ - fullBreath: 200 - } + breath:{ + fullBreath: 200 + }, + cardio:{ + optimalPressure: 50 + } }, legs:{ size:{ diff --git a/docs/assets/js/player/lifeFunctions.js b/docs/assets/js/player/lifeFunctions.js index 1df2f12..105ab0e 100644 --- a/docs/assets/js/player/lifeFunctions.js +++ b/docs/assets/js/player/lifeFunctions.js @@ -2,7 +2,7 @@ let breath = 180; let fullBreathTimer = 0; let noBreathTimer = 0; -let heartRate = 60; +let pressure = 50; let heartBeat = false; @@ -17,11 +17,11 @@ let currentBreathMode = breathMode.exhale; function updateLife() { - if(keyDown[k.UP]) { + if(keyDown[k.w]) { if(breath === 0) currentBreathMode = breathMode.inhale; } - if(keyDown[k.DOWN]) { + if(keyDown[k.s]) { if(breath === constants.lifeFuncs.breath.fullBreath) currentBreathMode = breathMode.exhale; } @@ -30,6 +30,11 @@ function updateLife() { if(keyPress[k.x]) { heartbeat(); } + + pressure-=0.25; + if(pressure<=0){ + pressure = 0; + } }; function breathe() { @@ -39,7 +44,7 @@ function breathe() { if(breath >= constants.lifeFuncs.breath.fullBreath) { breath = constants.lifeFuncs.breath.fullBreath; fullBreathTimer++; - if(fullBreathTimer >= 180) { + if(fullBreathTimer >= 600) { //cough and lose breath or something } } else { @@ -47,11 +52,11 @@ function breathe() { } break; case breathMode.exhale: - breath -= 1; + breath -= 2; if(breath <= 0) { breath = 0; noBreathTimer++; - if(noBreathTimer >= 180) { + if(noBreathTimer >= 300) { //cough and lose breath or something } } else { @@ -62,5 +67,9 @@ function breathe() { }; function heartbeat() { + pressure+=10; + if(pressure>=100){ + pressure = 100; + } heartBeat = true; }; \ No newline at end of file