diff --git a/docs/assets/images/Capture.PNG b/docs/assets/images/Capture.PNG new file mode 100644 index 0000000..538afbb Binary files /dev/null and b/docs/assets/images/Capture.PNG differ diff --git a/docs/assets/images/blinkOverlay.png b/docs/assets/images/blinkOverlay.png new file mode 100644 index 0000000..4a0a3fa Binary files /dev/null and b/docs/assets/images/blinkOverlay.png differ diff --git a/docs/assets/images/eye.png b/docs/assets/images/eye.png new file mode 100644 index 0000000..611f982 Binary files /dev/null and b/docs/assets/images/eye.png differ diff --git a/docs/assets/images/eyeDry.png b/docs/assets/images/eyeDry.png new file mode 100644 index 0000000..5629894 Binary files /dev/null and b/docs/assets/images/eyeDry.png differ diff --git a/docs/assets/images/heartBack.png b/docs/assets/images/heartBack.png new file mode 100644 index 0000000..9dbd3c3 Binary files /dev/null and b/docs/assets/images/heartBack.png differ diff --git a/docs/assets/images/heartCover.png b/docs/assets/images/heartCover.png new file mode 100644 index 0000000..6f4ae9f Binary files /dev/null and b/docs/assets/images/heartCover.png differ diff --git a/docs/assets/images/tempIcon.png b/docs/assets/images/tempIcon.png new file mode 100644 index 0000000..c6b249c Binary files /dev/null and b/docs/assets/images/tempIcon.png differ diff --git a/docs/assets/js/UI/ui.js b/docs/assets/js/UI/ui.js index c15dcd9..8bb34a7 100644 --- a/docs/assets/js/UI/ui.js +++ b/docs/assets/js/UI/ui.js @@ -13,6 +13,9 @@ function drawPlayingUI() { //Respiration Monitor respiratoryUI(cw/8*5,ch/8*7-8, cw/16, ch/8); + + //Blink eye and overlay + blinkUI(); } //UI for pause screen @@ -75,7 +78,16 @@ function heartBeatUI(x, y, width, height){ } //Backdrop - rect(x+width/2,y+height/2,width,height,"black"); + var BackdropColor; + if(pressure > 42 && pressure < 60) { + BackdropColor = "#0c2605"; + } else if(pressure > 28 && pressure < 75) { + BackdropColor = "#2b2b06"; + } else { + BackdropColor = "#260505"; + } + rect(x+width/2,y+height/2,width,height,BackdropColor); + img(sprites.heartBack,cw-107,ch-46); //Pressure Meter rect(x+width-8,y+height/2,16,height,"red"); @@ -90,6 +102,9 @@ function heartBeatUI(x, y, width, height){ const qrsValueAtNextPosition = heartBeatHistory[index+1]; 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"); } + + // cover + img(sprites.heartCover,cw-107,ch-46); } //Determine next value to be added to the graph @@ -126,3 +141,21 @@ function pushNextBeatValue(){ heartBeatHistory.push(nextBeatValue); } + + +function blinkUI() { + // eye + img(sprites.eye,cw-350,ch-40,0,2,2); + var alpha = clamp(eyeDryness / constants.lifeFuncs.blink.dryTime,0,1); + curCtx.globalAlpha = alpha; + img(sprites.eyeDry,cw-350,ch-40,0,2,2); + + // dry overlay + if(eyeDryness > constants.lifeFuncs.blink.dryTime) { + alpha = (eyeDryness - constants.lifeFuncs.blink.dryTime) / 350; + curCtx.globalAlpha = alpha; + img(sprites.blinkOverlay,cw/2,ch/2); + } + + curCtx.globalAlpha = 1; +} \ No newline at end of file diff --git a/docs/assets/js/constants.js b/docs/assets/js/constants.js index 4f5d388..f2c99ce 100644 --- a/docs/assets/js/constants.js +++ b/docs/assets/js/constants.js @@ -41,6 +41,9 @@ var constants = { }, cardio:{ optimalPressure: 50 + }, + blink: { + dryTime: 600 } }, player:{ diff --git a/docs/assets/js/index.js b/docs/assets/js/index.js index 27ca176..87a7cfc 100644 --- a/docs/assets/js/index.js +++ b/docs/assets/js/index.js @@ -5,7 +5,12 @@ page_preloader.show(true); images = [ "assets/images/", "level.png", - "level_2.png" + "level_2.png", + "heartCover.png", + "heartBack.png", + "blinkOverlay.png", + "eye.png", + "eyeDry.png" ]; audio = [ @@ -72,10 +77,17 @@ function draw() { break; // playing case globalStates.playing: - camera.zoom = 1; - drawWorldBlocks(); - imgIgnoreCutoff(sprites.level_2,0,0,0,4,4); - player.draw(); + if(!justBlinked) { + + camera.zoom = 1; + drawWorldBlocks(); + imgIgnoreCutoff(sprites.level_2,0,0,0,4,4); + player.draw(); + + } else { + rect(-camera.x - difx + cw/2,-camera.y - dify + ch/2,cw,ch,"black"); + justBlinked = false; + } break; // paused case globalStates.paused: diff --git a/docs/assets/js/player/lifeFunctions.js b/docs/assets/js/player/lifeFunctions.js index 81f8a8f..bbc1f01 100644 --- a/docs/assets/js/player/lifeFunctions.js +++ b/docs/assets/js/player/lifeFunctions.js @@ -13,18 +13,19 @@ var breathMode = { let currentBreathMode = breathMode.exhale; - +let eyeDryness = 0; +let justBlinked = false; function updateLife() { - if(keyDown[k.z]) { + if(keyDown[k.x]) { if(breath === 0) currentBreathMode = breathMode.inhale; else if(breath === constants.lifeFuncs.breath.fullBreath) currentBreathMode = breathMode.exhale; } breathe(); - if(keyPress[k.x]) { + if(keyPress[k.c]) { heartbeat(); } @@ -32,6 +33,12 @@ function updateLife() { if(pressure<=0){ pressure = 0; } + + eyeDryness++; + + if(keyPress[k.z]) { + blink(); + } }; function breathe() { @@ -72,4 +79,9 @@ function heartbeat() { // Play the heartbeat sound soundAssets.heartbeat.play(); -}; \ No newline at end of file +}; + +function blink() { + eyeDryness = 0; + justBlinked = true; +} \ No newline at end of file diff --git a/docs/assets/js/player/player.js b/docs/assets/js/player/player.js index 9c541a9..2ce5929 100644 --- a/docs/assets/js/player/player.js +++ b/docs/assets/js/player/player.js @@ -4,10 +4,10 @@ class Player { this.y = y; this.w = constants.player.width; this.h = constants.player.height; - this.hipLeft = { x: this.x - constants.player.hip.offset_x, y: this.y + constants.player.hip.offset_y }; - this.hipRight = { x: this.x + constants.player.hip.offset_x, y: this.y + constants.player.hip.offset_y }; - this.leftLeg = new Leg(this.hipLeft.x, this.hipLeft.y, 50, -Math.PI / 4); - this.rightLeg = new Leg(this.hipRight.x, this.hipRight.y, 50, Math.PI / 2); + this.hipLeft = { x: this.x + constants.player.hip.offset_x, y: this.y + constants.player.hip.offset_y }; + this.hipRight = { x: this.x - constants.player.hip.offset_x, y: this.y + constants.player.hip.offset_y }; + this.leftLeg = new Leg(this.hipLeft.x, this.hipLeft.y, 50, Math.PI*2.5); + this.rightLeg = new Leg(this.hipRight.x, this.hipRight.y, 50, Math.PI*2.5); this.legSelected = "R"; this.shouldMoveLeg = false; this.collided = false; @@ -55,17 +55,8 @@ Player.prototype.update = function() { var targetPos = mousePosition(); var curLeg = this.getActiveLeg(); this.hover.active = false; - //left - if (distanceToLineSegment(this.leftLeg.x, this.leftLeg.y, this.leftLeg.x2, this.leftLeg.y2, targetPos.x, targetPos.y) < constants.player.select_range) { - this.hover.active = true; - this.hover.leg = "L"; - if(mousePress[0]) { - this.shouldMoveLeg = true; - this.legSelected = "L"; - this.hover.active = false; - } // right - } else if (distanceToLineSegment(this.rightLeg.x, this.rightLeg.y, this.rightLeg.x2, this.rightLeg.y2, targetPos.x, targetPos.y) < constants.player.select_range) { + if (distanceToLineSegment(this.rightLeg.x, this.rightLeg.y, this.rightLeg.x2, this.rightLeg.y2, targetPos.x, targetPos.y) < constants.player.select_range) { this.hover.active = true; this.hover.leg = "R"; if(mousePress[0]) { @@ -73,7 +64,16 @@ Player.prototype.update = function() { this.legSelected = "R"; this.hover.active = false; } - } + //left + } else if (distanceToLineSegment(this.leftLeg.x, this.leftLeg.y, this.leftLeg.x2, this.leftLeg.y2, targetPos.x, targetPos.y) < constants.player.select_range) { + this.hover.active = true; + this.hover.leg = "L"; + if(mousePress[0]) { + this.shouldMoveLeg = true; + this.legSelected = "L"; + this.hover.active = false; + } + } } centerCameraOn(this.x,this.y); @@ -98,7 +98,6 @@ Player.prototype.moveLeg = function(){ // console.log(curLeg.angle.toPrecision(5),pointTo(curLeg,target).toPrecision(5)); var angleDif = turn(curLeg.angle, pointTo(curLeg, target), constants.player.leg_speed) - curLeg.angle; curLeg.angle += angleDif; - // var angle = pointTo(curLeg,target); curLeg.x2 = curLeg.x + curLeg.len * Math.cos(curLeg.angle); curLeg.y2 = curLeg.y + curLeg.len * Math.sin(curLeg.angle); @@ -109,15 +108,26 @@ Player.prototype.moveLeg = function(){ curLeg.x2 = lastX; curLeg.y2 = lastY; curLeg.angle -= angleDif; + + // finer movement + angleDif = turn(curLeg.angle, pointTo(curLeg, target), constants.player.leg_speed/8) - curLeg.angle; + curLeg.angle += angleDif; + curLeg.x2 = curLeg.x + curLeg.len * Math.cos(curLeg.angle); + curLeg.y2 = curLeg.y + curLeg.len * Math.sin(curLeg.angle); + + + // Collision + if(collidingWithWorld({x:curLeg.x2,y:curLeg.y2,w:2,h:2})){ + this.collided = true; + curLeg.x2 = lastX; + curLeg.y2 = lastY; + curLeg.angle -= angleDif; + } return 0; - } - if(collidingWithWorld({x:this.x, y:this.y, w:this.w, h:this.h})){ - this.x = this.lastBodyX; - this.y = this.lastBodyY; - } + if (dist(curLeg, target) > curLeg.len) { @@ -169,7 +179,10 @@ Player.prototype.moveLeg = function(){ } - + if(collidingWithWorld({x:this.x, y:this.y, w:this.w, h:this.h})){ + this.x = this.lastBodyX; + this.y = this.lastBodyY; + } this.lastBodyX = this.x; @@ -248,3 +261,7 @@ function distanceToLineSegment(lx1, ly1, lx2, ly2, px, py) { var player = new Player(constants.player.defaultX, constants.player.defaultY); +// why does this stop the legs from glitching on the first step??? +player.rightLeg.angle = -pointTo({ x: player.rightLeg.x2, y: player.rightLeg.y2 }, player.hipRight); +player.leftLeg.angle = pointTo({ x: player.leftLeg.x2, y: player.leftLeg.y2 }, player.hipLeft); +player.moveLeg(); \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 940cbaa..6b7ceab 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,8 +1,8 @@
- -TODO REMOVE ME +z: blink +x: breath +c: beat heart +