Added blood pressure system

-bloood
This commit is contained in:
Silas Bartha 2020-04-18 15:38:50 -04:00
parent 2d6863dd1a
commit 18a03a5aff
3 changed files with 29 additions and 10 deletions

View File

@ -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");
}
}

View File

@ -35,9 +35,12 @@ var constants = {
}
},
lifeFuncs:{
breath:{
fullBreath: 200
}
breath:{
fullBreath: 200
},
cardio:{
optimalPressure: 50
}
},
legs:{
size:{

View File

@ -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;
};